1
use conjure_cp_essence_parser::diagnostics::error_detection::syntactic_errors::{
2
    check_diagnostic, detect_syntactic_errors,
3
};
4

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

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

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

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

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

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

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

            
36
1
    let diagnostics = detect_syntactic_errors(source);
37

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

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

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

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

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

            
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 = detect_syntactic_errors(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
}