1
use conjure_cp_essence_parser::diagnostics::diagnostics_api::get_diagnostics;
2
use conjure_cp_essence_parser::diagnostics::error_detection::collect_errors::check_diagnostic;
3
use conjure_cp_essence_parser::util::get_tree;
4

            
5
#[test]
6
1
fn missing_identifier() {
7
1
    let source = "find: bool";
8
1
    let (cst, _) = get_tree(&source).unwrap();
9

            
10
1
    let diagnostics = get_diagnostics(&source, &cst);
11
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
12

            
13
1
    let diag = &diagnostics[0];
14

            
15
1
    check_diagnostic(diag, 0, 4, 0, 4, "Missing Variable List");
16
1
}
17

            
18
#[test]
19
1
fn missing_colon() {
20
1
    let source = "find x bool";
21
1
    let (cst, _) = get_tree(&source).unwrap();
22

            
23
1
    let diagnostics = get_diagnostics(&source, &cst);
24

            
25
    // Should be exactly one diagnostic
26
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
27
1
    let diag = &diagnostics[0];
28

            
29
1
    check_diagnostic(diag, 0, 6, 0, 6, "Missing :");
30
1
}
31

            
32
#[test]
33
1
fn missing_domain() {
34
    // not indented because have to avoid leading spaces for accurate character counr
35
1
    let source = "\
36
1
find x: bool
37
1
find y:
38
1
    ";
39
1
    let (cst, _) = get_tree(&source).unwrap();
40

            
41
1
    let diagnostics = get_diagnostics(&source, &cst);
42

            
43
    // Should be exactly one diagnostic
44
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
45
1
    let diag = &diagnostics[0];
46

            
47
1
    check_diagnostic(diag, 1, 7, 1, 7, "Missing Domain");
48
1
}
49

            
50
#[test]
51
1
fn missing_contraint() {
52
    // not indented because have to avoid leading spaces for accurate character counr
53
1
    let source = "\
54
1
find x: bool
55
1
such that
56
1
    ";
57
1
    let (cst, _) = get_tree(&source).unwrap();
58

            
59
1
    let diagnostics = get_diagnostics(&source, &cst);
60

            
61
    // Should be exactly one diagnostic
62
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
63
1
    let diag = &diagnostics[0];
64

            
65
1
    check_diagnostic(diag, 1, 9, 1, 9, "Missing Expression");
66
1
}
67

            
68
// TO-DO adapt when returning vector of errors
69
#[test]
70
1
fn multiple_missing_tokens() {
71
    // not indented because have to avoid leading spaces for accurate character counr
72
1
    let source = "\
73
1
find x: int(1..3
74
1
letting x be
75
1
    ";
76
1
    let (cst, _) = get_tree(&source).unwrap();
77

            
78
1
    let diagnostics = get_diagnostics(&source, &cst);
79

            
80
    // Should be exactly one diagnostic
81
1
    assert_eq!(diagnostics.len(), 2, "Expected two diagnostics");
82

            
83
1
    let diag1 = &diagnostics[0];
84
1
    let diag2 = &diagnostics[1];
85

            
86
1
    check_diagnostic(diag1, 0, 16, 0, 16, "Missing )");
87
1
    check_diagnostic(diag2, 1, 12, 1, 12, "Missing Expression or Domain");
88
1
}
89

            
90
#[test]
91
1
fn missing_rparen_in_int_domain_at_eof() {
92
1
    let source = "find x: int(1..3";
93
1
    let (cst, _) = get_tree(&source).unwrap();
94

            
95
1
    let diagnostics = get_diagnostics(&source, &cst);
96
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
97

            
98
1
    let diag = &diagnostics[0];
99
1
    check_diagnostic(diag, 0, 16, 0, 16, "Missing )");
100
1
}