Lines
28.24 %
Functions
16.67 %
use conjure_cp_essence_parser::diagnostics::diagnostics_api::get_diagnostics;
use conjure_cp_essence_parser::diagnostics::error_detection::collect_errors::check_diagnostic;
#[test]
fn detects_undefined_variable() {
let source = "find x: int(1..10)\nsuch that x = y";
// y is undefined
let diagnostics = get_diagnostics(source);
assert_eq!(
diagnostics.len(),
1,
"Expected exactly one diagnostic for undefined variable"
);
let diag = &diagnostics[0];
check_diagnostic(diag, 1, 14, 1, 15, "The identifier 'y' is not defined");
}
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";
check_diagnostic(
diag,
14,
27,
"The identifier 'undefined_var' is not defined",
// not enforced in conjure
#[ignore]
fn domain_start_greater_than_end() {
let source = "find x: int(10..1)";
12,
17,
"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,
15,
"Incorrect type 'bool' for variable 'y', expected 'int'",
fn dividing_over_zero() {
let source = "find x: int(5..10)\nsuch that x/0 = 3";
check_diagnostic(diag, 1, 10, 1, 13, "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, "Index out of bounds");
fn duplicate_declaration_of_variable() {
let source = "find x: int(1..10)\nfind x: int(2..3)";
5,
6,
"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'",