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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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