1
use conjure_cp_essence_parser::diagnostics::error_detection::semantic_errors::detect_semantic_errors;
2
use conjure_cp_essence_parser::diagnostics::error_detection::syntactic_errors::check_diagnostic;
3

            
4
#[test]
5
fn detects_undefined_variable() {
6
    let source = "find x: int(1..10)\nsuch that x = y";
7
    // y is undefined
8
    let diagnostics = detect_semantic_errors(source);
9

            
10
    assert_eq!(
11
        diagnostics.len(),
12
        1,
13
        "Expected exactly one diagnostic for undefined variable"
14
    );
15

            
16
    let diag = &diagnostics[0];
17

            
18
    check_diagnostic(
19
        diag,
20
        1,
21
        14,
22
        1,
23
        15,
24
        "Semantic Error: Undefined variable: 'y'",
25
    );
26
}
27

            
28
#[test]
29
fn no_errors_for_valid_code() {
30
    let source = "find x, y: int(1..10)\nsuch that x + y = 10";
31
    let diagnostics = detect_semantic_errors(source);
32

            
33
    // should have no diagnostics
34
    assert_eq!(
35
        diagnostics.len(),
36
        0,
37
        "Expected no diagnostics for valid code, got: {:?}",
38
        diagnostics
39
    );
40
}
41

            
42
#[test]
43
fn range_points_to_error_location() {
44
    let source = "find x: int(1..10)\nsuch that x = undefined_var";
45
    let diagnostics = detect_semantic_errors(source);
46

            
47
    assert_eq!(
48
        diagnostics.len(),
49
        1,
50
        "Expected exactly one diagnostic for undefined variable"
51
    );
52

            
53
    let diag = &diagnostics[0];
54

            
55
    check_diagnostic(
56
        diag,
57
        1,
58
        14,
59
        1,
60
        27,
61
        "Semantic Error: Undefined variable: 'undefined_var'",
62
    );
63
}