Lines
29.21 %
Functions
33.33 %
use conjure_cp_essence_parser::diagnostics::error_detection::semantic_errors::detect_semantic_errors;
use conjure_cp_essence_parser::diagnostics::error_detection::syntactic_errors::check_diagnostic;
#[test]
fn detects_undefined_variable() {
let source = "find x: int(1..10)\nsuch that x = y";
// y is undefined
let diagnostics = detect_semantic_errors(source);
assert_eq!(
diagnostics.len(),
1,
"Expected exactly one diagnostic for undefined variable"
);
let diag = &diagnostics[0];
check_diagnostic(
diag,
14,
15,
"Semantic Error: Undefined variable: 'y'",
}
fn no_errors_for_valid_code() {
let source = "find x, y: int(1..10)\nsuch that x + y = 10";
// should have no diagnostics
0,
"Expected no diagnostics for valid code, got: {:?}",
diagnostics
fn range_points_to_error_location() {
let source = "find x: int(1..10)\nsuch that x = undefined_var";
27,
"Semantic Error: Undefined variable: 'undefined_var'",
// not enforced in conjure
#[ignore]
fn domain_start_greater_than_end() {
let source = "find x: int(10..1)";
12,
17,
"Semantic Error: Start value greater than end value in 'domain'",
fn incorrect_type_for_equation() {
let source = "
letting y be false\n
find x: int(5..10)\n
such that 5 + y = 6";
2,
"Semantic Error: Incorrect type 'bool' for variable 'y', expected 'int'",
fn dividing_over_zero() {
let source = "find x: int(5..10)\nsuch that x/0 = 3";
10,
13,
"Semantic Error: Unsafe division attempted",
fn invalid_index() {
let source = "letting s be (0,1,1,0)
\nletting t be (0,0,0,1)
\nfind a : bool such that a = (s[5] = t[1])";
check_diagnostic(diag, 2, 31, 2, 32, "Semantic Error: Index out of bounds");
fn duplicate_declaration_of_variable() {
let source = "find x: int(1..10)\nfind x: int(2..3)";
5,
6,
"Semantic Error: Redeclaration of variable 'x' which was previously defined",
fn extra_comma_in_variable_list() {
let source = "find x,: int(1..10)";
7,
"Semantic Error: Extra ',' at the end of 'variable_list'",