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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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