1
use justjson::parser::{ParseConfig, Parser};
2
#[cfg(feature = "alloc")]
3
use justjson::{doc::Document, Value};
4

            
5
macro_rules! json_org_test {
6
    ($name:ident) => {
7
        #[test]
8
36
        fn $name() {
9
36
            let src = include_bytes!(concat!("./jsonorg/", stringify!($name), ".json"));
10
36
            let src_str = std::str::from_utf8(src).unwrap();
11
36
            let config = ParseConfig::strict().with_recursion_limit(19);
12
36

            
13
36
            if stringify!($name).starts_with("pass") {
14
3
                Parser::validate_json_bytes_with_config(src, config)
15
3
                    .expect("failed to parse success case");
16
3
                Parser::validate_json_with_config(src_str, config)
17
3
                    .expect("failed to parse success case");
18
3
                #[cfg(feature = "alloc")]
19
3
                {
20
3
                    Value::from_json_bytes_with_config(src, config)
21
3
                        .expect("failed to parse success case");
22
3
                    Value::from_json_with_config(src_str, config)
23
3
                        .expect("failed to parse success case");
24
3

            
25
3
                    Document::from_json_bytes_with_config(src, config)
26
3
                        .expect("failed to parse success case");
27
3
                    Document::from_json_with_config(src_str, config)
28
3
                        .expect("failed to parse success case");
29
3
                }
30
            } else {
31
33
                Parser::validate_json_bytes_with_config(src, config)
32
33
                    .expect_err("success on failure case");
33
33
                Parser::validate_json_with_config(src_str, config)
34
33
                    .expect_err("success on failure case");
35
33
                #[cfg(feature = "alloc")]
36
33
                {
37
33
                    Value::from_json_bytes_with_config(src, config)
38
33
                        .expect_err("success on failure case");
39
33
                    Value::from_json_with_config(src_str, config)
40
33
                        .expect_err("success on failure case");
41
33

            
42
33
                    Document::from_json_bytes_with_config(src, config)
43
33
                        .expect_err("success on failure case");
44
33
                    Document::from_json_with_config(src_str, config)
45
33
                        .expect_err("success on failure case");
46
33
                }
47
            }
48
36
        }
49
    };
50
}
51

            
52
1
json_org_test!(pass1);
53
1
json_org_test!(pass2);
54
1
json_org_test!(pass3);
55

            
56
1
json_org_test!(fail1);
57
1
json_org_test!(fail2);
58
1
json_org_test!(fail3);
59
1
json_org_test!(fail4);
60
1
json_org_test!(fail5);
61
1
json_org_test!(fail6);
62
1
json_org_test!(fail7);
63
1
json_org_test!(fail8);
64
1
json_org_test!(fail9);
65
1
json_org_test!(fail10);
66
1
json_org_test!(fail11);
67
1
json_org_test!(fail12);
68
1
json_org_test!(fail13);
69
1
json_org_test!(fail14);
70
1
json_org_test!(fail15);
71
1
json_org_test!(fail16);
72
1
json_org_test!(fail17);
73
1
json_org_test!(fail18);
74
1
json_org_test!(fail19);
75
1
json_org_test!(fail20);
76
1
json_org_test!(fail21);
77
1
json_org_test!(fail22);
78
1
json_org_test!(fail23);
79
1
json_org_test!(fail24);
80
1
json_org_test!(fail25);
81
1
json_org_test!(fail26);
82
1
json_org_test!(fail27);
83
1
json_org_test!(fail28);
84
1
json_org_test!(fail29);
85
1
json_org_test!(fail30);
86
1
json_org_test!(fail31);
87
1
json_org_test!(fail32);
88
1
json_org_test!(fail33);