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
2
fn missing_identifier() {
6
2
    let source = "find: bool";
7
2
    let diagnostics = get_diagnostics(source);
8
2
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
9

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

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

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

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

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

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

            
35
2
    let diagnostics = get_diagnostics(source);
36

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

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

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

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

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

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

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

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

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