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

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

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

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

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

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

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

            
35
3
    let diagnostics = get_diagnostics(source);
36

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

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

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

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

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

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

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

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

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