1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#[macro_export]
macro_rules! include_test_str {
($x:expr) => {
include_str!(concat!("../../dhall-lang/tests/", $x, ".dhall"))
};
}
#[macro_export]
macro_rules! include_test_strs_ab {
($x:expr) => {
(
include_test_str!(concat!($x, "A")),
include_test_str!(concat!($x, "B")),
)
};
}
#[macro_export]
macro_rules! parse_str {
($str:expr) => {{
let pest_expr = parser::parse_expr_pest(&$str)
.map_err(|e| println!("{}", e))
.unwrap();
// // Check with old parser
// match parser::parse_expr_lalrpop(&$str) {
// Ok(larlpop_expr) => assert_eq!(pest_expr, larlpop_expr),
// Err(_) => {},
// };
// panic!("{:?}", pest_expr);
pest_expr
}};
}
#[macro_export]
macro_rules! assert_eq_ {
($left:expr, $right:expr) => ({
match (&$left, &$right) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
panic!(r#"assertion failed: `(left == right)`
left: `{}`,
right: `{}`"#, left_val, right_val)
}
}
}
});
($left:expr, $right:expr,) => ({
assert_eq!($left, $right)
});
($left:expr, $right:expr, $($arg:tt)+) => ({
match (&($left), &($right)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
panic!(r#"assertion failed: `(left == right)`
left: `{:?}`,
right: `{:?}`: {}"#, left_val, right_val,
format_args!($($arg)+))
}
}
}
});
}
#[macro_export]
macro_rules! run_spec_test {
(normalization, $path:expr) => {
let (expr_str, expected_str) = include_test_strs_ab!($path);
let expr = parse_str!(expr_str);
let expected = parse_str!(expected_str);
assert_eq_!(
normalize::<_, X, _>(&expr),
normalize::<_, X, _>(&expected)
);
};
(parser, $path:expr) => {
let expr_str = include_test_str!(concat!($path, "A"));
parse_str!(expr_str);
};
(parser_failure, $path:expr) => {
let expr_str = include_test_str!($path);
parser::parse_expr_pest(&expr_str).unwrap_err();
};
}
#[macro_export]
macro_rules! make_spec_test {
($type:ident, $name:ident, $path:expr) => {
#[test]
#[allow(non_snake_case)]
#[allow(unused_variables)]
#[allow(unused_imports)]
fn $name() {
use dhall::*;
use dhall_core::*;
use dhall_normalize::*;
use std::thread;
thread::Builder::new()
.stack_size(16 * 1024 * 1024)
.spawn(move || {
run_spec_test!($type, $path);
})
.unwrap()
.join()
.unwrap();
}
};
}
|