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

            
4
#[test]
5
1
fn missing_identifier() {
6
1
    let source = "find: bool";
7
1
    let diagnostics = get_diagnostics(source);
8
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
9

            
10
1
    let diag = &diagnostics[0];
11

            
12
1
    check_diagnostic(diag, 0, 4, 0, 4, "Missing Variable List");
13
1
}
14

            
15
#[test]
16
1
fn missing_colon() {
17
1
    let source = "find x bool";
18
1
    let diagnostics = get_diagnostics(source);
19

            
20
    // Should be exactly one diagnostic
21
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
22
1
    let diag = &diagnostics[0];
23

            
24
1
    check_diagnostic(diag, 0, 6, 0, 6, "Missing :");
25
1
}
26

            
27
#[test]
28
1
fn missing_domain() {
29
    // not indented because have to avoid leading spaces for accurate character counr
30
1
    let source = "\
31
1
find x: bool
32
1
find y:
33
1
    ";
34

            
35
1
    let diagnostics = get_diagnostics(source);
36

            
37
    // Should be exactly one diagnostic
38
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
39
1
    let diag = &diagnostics[0];
40

            
41
1
    check_diagnostic(diag, 1, 7, 1, 7, "Missing Domain");
42
1
}
43

            
44
#[test]
45
1
fn missing_contraint() {
46
    // not indented because have to avoid leading spaces for accurate character counr
47
1
    let source = "\
48
1
find x: bool
49
1
such that
50
1
    ";
51
1
    let diagnostics = get_diagnostics(source);
52

            
53
    // Should be exactly one diagnostic
54
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
55
1
    let diag = &diagnostics[0];
56

            
57
1
    check_diagnostic(diag, 1, 9, 1, 9, "Missing Expression");
58
1
}
59

            
60
// TO-DO adapt when returning vector of errors
61
#[test]
62
1
fn multiple_missing_tokens() {
63
    // not indented because have to avoid leading spaces for accurate character counr
64
1
    let source = "\
65
1
find x: int(1..3
66
1
letting x be
67
1
    ";
68
1
    let diagnostics = get_diagnostics(source);
69

            
70
    // Should be exactly one diagnostic
71
1
    assert_eq!(diagnostics.len(), 2, "Expected two diagnostics");
72

            
73
1
    let diag1 = &diagnostics[0];
74
1
    let diag2 = &diagnostics[1];
75

            
76
1
    check_diagnostic(diag1, 0, 16, 0, 16, "Missing )");
77
1
    check_diagnostic(diag2, 1, 12, 1, 12, "Missing Expression or Domain");
78
1
}