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

            
5
#[test]
6
1
fn invalid_top_level_statement_expression() {
7
1
    let source = " a,a,b: int(1..3)";
8
1
    let diags = detect_syntactic_errors(source);
9
1
    assert_eq!(diags.len(), 1, "Expected exactly one diagnostic");
10
1
    let diag = &diags[0];
11
1
    check_diagnostic(diag, 0, 0, 0, 17, "Malformed line 1: ' a,a,b: int(1..3)'");
12
1
}
13

            
14
#[test]
15
1
fn malformed_find_2() {
16
1
    let source = "find >=lex,b,c: int(1..3)";
17
    // using >=lex operator instead of identifier
18
1
    let diagnostics = detect_syntactic_errors(source);
19
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
20

            
21
1
    let diag = &diagnostics[0];
22
1
    check_diagnostic(
23
1
        diag,
24
        0,
25
        0,
26
        0,
27
        25,
28
1
        "Malformed line 1: 'find >=lex,b,c: int(1..3)'",
29
    );
30
1
}
31

            
32
#[test]
33
1
fn malformed_find_3() {
34
1
    let source = "find +,a,b: int(1..3)";
35
1
    let diags = detect_syntactic_errors(source);
36
1
    assert_eq!(diags.len(), 1, "Expected exactly one diagnostic");
37
1
    let diag = &diags[0];
38
1
    check_diagnostic(
39
1
        diag,
40
        0,
41
        0,
42
        0,
43
        21,
44
1
        "Malformed line 1: 'find +,a,b: int(1..3)'",
45
    );
46
1
}
47

            
48
#[test]
49
1
fn unexpected_colon_used_as_identifier() {
50
1
    let source = "find :,b,c: int(1..3)";
51
1
    let diagnostics = detect_syntactic_errors(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(
58
1
        diag,
59
        0,
60
        0,
61
        0,
62
        21,
63
1
        "Malformed line 1: 'find :,b,c: int(1..3)'",
64
    );
65
1
}
66

            
67
#[test]
68
1
fn missing_colon_domain_in_find_statement_1st_line() {
69
1
    let source = "find x";
70
1
    let diagnostics = detect_syntactic_errors(source);
71

            
72
    // Should be exactly one diagnostic
73
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
74

            
75
1
    let diag = &diagnostics[0];
76

            
77
1
    check_diagnostic(diag, 0, 0, 0, 6, "Malformed line 1: 'find x'");
78
1
}
79

            
80
#[test]
81
1
fn missing_colon_domain_in_find_statement_2nd_line() {
82
1
    let source = "find x: int(1..3)\nfind x";
83
1
    let diagnostics = detect_syntactic_errors(source);
84

            
85
    // Should be exactly one diagnostic
86
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
87

            
88
1
    let diag = &diagnostics[0];
89
1
    check_diagnostic(diag, 1, 0, 1, 6, "Malformed line 2: 'find x'");
90
1
}
91

            
92
#[test]
93
1
fn unexpected_print_2nd_line() {
94
1
    let source = "find a,b,c: int(1..3)\nprint a";
95
1
    let diagnostics = detect_syntactic_errors(source);
96

            
97
    // Should be exactly one diagnostic
98
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
99

            
100
1
    let diag = &diagnostics[0];
101
1
    check_diagnostic(diag, 1, 0, 1, 7, "Malformed line 2: 'print a'");
102
1
}