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
1
fn invalid_top_level_statement_expression() {
6
1
    let source = " a,a,b: int(1..3)";
7
1
    let diags = get_diagnostics(source);
8
1
    assert_eq!(diags.len(), 1, "Expected exactly one diagnostic");
9
1
    let diag = &diags[0];
10
1
    check_diagnostic(diag, 0, 0, 0, 17, "Malformed line 1: ' a,a,b: int(1..3)'");
11
1
}
12

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

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

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

            
47
#[test]
48
1
fn unexpected_colon_used_as_identifier() {
49
1
    let source = "find :,b,c: int(1..3)";
50
1
    let diagnostics = get_diagnostics(source);
51

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

            
56
1
    check_diagnostic(
57
1
        diag,
58
        0,
59
        0,
60
        0,
61
        21,
62
1
        "Malformed line 1: 'find :,b,c: int(1..3)'",
63
    );
64
1
}
65

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

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

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

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

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

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

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

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

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

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