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

            
9
1
    assert_eq!(
10
1
        diags.len(),
11
        1,
12
        "Expected a valid top-level statement, but got 'a,a,b: int(1..3)'"
13
    );
14
1
    let diag = &diags[0];
15

            
16
1
    check_diagnostic(
17
1
        diag,
18
        0,
19
        0,
20
        0,
21
        17,
22
1
        "Expected a valid top-level statement, but got 'a,a,b: int(1..3)'",
23
    );
24
1
}
25

            
26
#[test]
27
1
fn malformed_find_2() {
28
1
    let source = "find >=lex,b,c: int(1..3)";
29
    // using >=lex operator instead of identifier
30
1
    let diagnostics = get_diagnostics(source);
31
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
32

            
33
1
    let diag = &diagnostics[0];
34
1
    check_diagnostic(
35
1
        diag,
36
        0,
37
        0,
38
        0,
39
        25,
40
1
        "Expected a find declaration statement, but got 'find >=lex,b,c: int(1..3)'",
41
    );
42
1
}
43

            
44
#[test]
45
1
fn malformed_find_3() {
46
1
    let source = "find +,a,b: int(1..3)";
47
1
    let diags = get_diagnostics(source);
48
1
    assert_eq!(diags.len(), 1, "Expected exactly one diagnostic");
49
1
    let diag = &diags[0];
50
1
    check_diagnostic(
51
1
        diag,
52
        0,
53
        0,
54
        0,
55
        21,
56
1
        "Expected a find declaration statement, but got 'find +,a,b: int(1..3)'",
57
    );
58
1
}
59

            
60
#[test]
61
1
fn unexpected_colon_used_as_identifier() {
62
1
    let source = "find :,b,c: int(1..3)";
63
1
    let diagnostics = get_diagnostics(source);
64

            
65
    // Should be exactly one diagnostic
66
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
67
1
    let diag = &diagnostics[0];
68

            
69
1
    check_diagnostic(
70
1
        diag,
71
        0,
72
        0,
73
        0,
74
        21,
75
1
        "Expected a find declaration statement, but got 'find :,b,c: int(1..3)'",
76
    );
77
1
}
78

            
79
#[test]
80
1
fn missing_colon_domain_in_find_statement_1st_line() {
81
1
    let source = "find 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

            
89
1
    check_diagnostic(
90
1
        diag,
91
        0,
92
        0,
93
        0,
94
        6,
95
1
        "Expected a find declaration statement, but got 'find x'",
96
    );
97
1
}
98

            
99
#[test]
100
1
fn missing_colon_domain_in_find_statement_2nd_line() {
101
1
    let source = "find x: int(1..3)\nfind x";
102
1
    let diagnostics = get_diagnostics(source);
103

            
104
    // Should be exactly one diagnostic
105
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
106

            
107
1
    let diag = &diagnostics[0];
108
1
    check_diagnostic(
109
1
        diag,
110
        1,
111
        0,
112
        1,
113
        6,
114
1
        "Expected a find declaration statement, but got 'find x'",
115
    );
116
1
}
117

            
118
#[test]
119
1
fn unexpected_print_2nd_line() {
120
1
    let source = "find a,b,c: int(1..3)\nprint a";
121
1
    let diagnostics = get_diagnostics(source);
122

            
123
    // Should be exactly one diagnostic
124
1
    assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
125

            
126
1
    let diag = &diagnostics[0];
127
1
    check_diagnostic(
128
1
        diag,
129
        1,
130
        0,
131
        1,
132
        7,
133
1
        "Expected a valid top-level statement, but got 'print a'",
134
    );
135
1
}