Lines
100 %
Functions
use conjure_cp_essence_parser::diagnostics::error_detection::syntactic_errors::{
check_diagnostic, detect_syntactic_errors,
};
#[test]
fn unexpected_closing_paren() {
let source = "find x: int(1..3))";
let diagnostics = detect_syntactic_errors(source);
assert_eq!(diagnostics.len(), 1, "Expected exactly one diagnostic");
let diag = &diagnostics[0];
check_diagnostic(diag, 0, 17, 0, 18, "Unexpected )");
}
fn unexpected_identifier_in_range() {
let source = "find x: int(1..3x)";
check_diagnostic(diag, 0, 16, 0, 17, "Unexpected x inside an Integer Domain");
fn unexpected_semicolon() {
let source = "\
find x: int(1..3)
such that x = 6;
";
check_diagnostic(diag, 1, 15, 1, 16, "Unexpected ;");
fn unexpected_extra_comma_in_find() {
let source = "find x,, y: int(1..3)";
check_diagnostic(diag, 0, 6, 0, 7, "Unexpected , inside a Variable List");
fn unexpected_token_in_implication() {
such that x -> %9
check_diagnostic(diag, 1, 15, 1, 16, "Unexpected % inside an Implication");
fn unexpected_token_in_matrix_domain() {
let source = "find x: matrix indexed by [int, &] of int";
check_diagnostic(diag, 0, 32, 0, 33, "Unexpected & inside a Matrix Domain");
fn unexpected_token_in_set_literal() {
let source = "find x: set of int\nsuch that x = {1, 2, @}";
check_diagnostic(diag, 1, 21, 1, 22, "Unexpected @ inside a Set");
// Multiple unexpected tokens
// One at the end of a find statement, one inside a set
fn multiple_unexpected_tokens() {
find x: set of int;
such that x = {1, 2, @}";
assert_eq!(diagnostics.len(), 2, "Expected exactly two diagnostics");
// First unexpected token: ';' at the end of domain
let diag1 = &diagnostics[0];
check_diagnostic(diag1, 0, 18, 0, 19, "Unexpected ;");
// Second unexpected token: '@' in set literal
let diag2 = &diagnostics[1];
check_diagnostic(diag2, 1, 21, 1, 22, "Unexpected @ inside a Set");
fn unexpected_x_in_all_diff() {
find a : bool
such that a = allDiff([1,2,4,1]x)";
check_diagnostic(
diag,
1,
31,
32,
"Unexpected x inside a List Combining Expression Bool",
);
fn unexpected_int_at_the_end() {
such that a = allDiff([1,2,4,1])8";
check_diagnostic(diag, 1, 32, 1, 33, "Unexpected 8");
fn unexpected_operand_at_end() {
find x, a, b: int(1..3)+
let diags = detect_syntactic_errors(source);
assert_eq!(diags.len(), 1, "Expected exactly one diagnostic");
let diag = &diags[0];
check_diagnostic(diag, 0, 23, 0, 24, "Unexpected +");
fn unexpected_operand_middle_no_comma() {
find x-, b: int(1..3)
check_diagnostic(diag, 0, 6, 0, 7, "Unexpected - inside a Variable List");
fn unexpected_operand_middle_comma() {
find x,-, b: int(1..3)
check_diagnostic(diag, 0, 6, 0, 8, "Unexpected ,- inside a Variable List");
fn unexpected_token_in_identifier() {
let source = "find v@lue: int(1..3)";
check_diagnostic(diag, 0, 6, 0, 10, "Unexpected @lue inside a Find Statement");
// Temporary before better logic is developed
fn missing_right_operand_in_and_expr() {
find x: int
such that x /\\
check_diagnostic(diag, 1, 12, 1, 14, "Unexpected /\\");
fn unexpected_token_in_comparison() {
such that 5 =
check_diagnostic(diag, 1, 12, 1, 13, "Unexpected =");
fn unexpected_token_in_domain() {
// not indented because have to avoid leading spaces for accurate character count
let source = "find a: int(1.3)";
// Should be exactly one diagnostic
check_diagnostic(diag, 0, 13, 0, 15, "Unexpected .3 inside an Integer Domain");