summaryrefslogtreecommitdiff
path: root/dhall/tests/macros.rs
blob: 956fa1f23a3ed1632ad323b98825e9b1fca0167c (plain)
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
#[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! 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 std::thread;
            use dhall::*;

            thread::Builder::new().stack_size(16 * 1024 * 1024).spawn(move || {
                run_spec_test!($type, $path);
            }).unwrap().join().unwrap();
        }
    };
}