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

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

            
11
    let diag = &diagnostics[0];
12

            
13
    check_diagnostic(diag, 0, 4, 0, 4, "Missing 'variable_list'");
14
}
15

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

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

            
25
    check_diagnostic(diag, 0, 6, 0, 6, "Missing 'COLON'");
26
}
27

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

            
36
    let diagnostics = detect_syntactic_errors(source);
37

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

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

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

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

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

            
61
#[test]
62
fn multiple_missing_tokens() {
63
    // not indented because have to avoid leading spaces for accurate character counr
64
    let source = "\
65
find x: int(1..3
66
letting x be
67
    ";
68
    let diagnostics = detect_syntactic_errors(source);
69

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

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

            
76
    check_diagnostic(diag1, 0, 16, 0, 16, "Missing ')'");
77
    check_diagnostic(diag2, 1, 12, 1, 12, "Missing 'expression or domain'");
78
}
79

            
80
#[test]
81
fn missing_domain_in_tuple_domain() {
82
    let source = "find x: tuple()";
83
    let diagnostics = detect_syntactic_errors(source);
84
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
85
    let diag = &diagnostics[0];
86
    check_diagnostic(diag, 0, 14, 0, 14, "Missing 'domain'");
87
}
88

            
89
#[test]
90
fn missing_operator_in_comparison() {
91
    // Missing operator in comparison expression
92
    let source = "\
93
find x: int
94
such that 5 =
95
    ";
96
    let diagnostics = detect_syntactic_errors(source);
97
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
98
    let diag = &diagnostics[0];
99
    check_diagnostic(
100
        diag,
101
        1,
102
        13,
103
        1,
104
        13,
105
        "Missing right operand in 'comparison' expression",
106
    );
107
}
108

            
109
#[test]
110
fn missing_right_operand_in_and_expr() {
111
    let source = "\
112
find x: int
113
such that x /\\
114
";
115
    let diagnostics = detect_syntactic_errors(source);
116
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
117
    let diag = &diagnostics[0];
118
    check_diagnostic(
119
        diag,
120
        1,
121
        14,
122
        1,
123
        14,
124
        "Missing right operand in 'and' expression",
125
    );
126
}