From 86fd78a5ab65015a9c18ad601856f1b16ed90fa9 Mon Sep 17 00:00:00 2001 From: Chimrod <> Date: Fri, 19 Jan 2024 11:55:15 +0100 Subject: Wait to get a valid syntax before considering a new location --- test/syntax_error.ml | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'test/syntax_error.ml') diff --git a/test/syntax_error.ml b/test/syntax_error.ml index e8d29a2..04b91ad 100644 --- a/test/syntax_error.ml +++ b/test/syntax_error.ml @@ -17,14 +17,16 @@ let get_report : | Ok _ -> failwith "No error" | Error { level; loc; message } -> { level; loc; message } -let _test_instruction : string -> S.pos report -> unit = - fun literal expected -> +let _test_instruction : + ?k:(S.pos report -> unit) -> string -> S.pos report -> unit = + fun ?k literal expected -> let _location = Printf.sprintf {|# Location %s ------- |} literal in let actual = get_report @@ Syntax.parse _location and msg = literal in - Alcotest.(check' report ~msg ~expected ~actual) + let () = Alcotest.(check' report ~msg ~expected ~actual) in + match k with None -> () | Some f -> f actual let else_column () = _test_instruction @@ -186,6 +188,26 @@ let missing_comparable () = _test_instruction "1 <= or 0" result; _test_instruction "1 = or 0" result +(** This code looks like a new location, but is actualy invalid. + The application should report the old location. + *) +let location_change () = + let result = + { + level = Error; + loc = _position; + message = "Missing boolean after operator"; + } + in + _test_instruction "1 and >= # invalid" result ~k:(fun actual -> + let actual = (fst actual.loc).Lexing.pos_fname in + + Alcotest.( + check' ~msg:"The location name is not valid" string ~actual + ~expected:"Location")) + +(* The location name *) + let test = ( "Syntax Errors", [ @@ -202,4 +224,5 @@ let test = Alcotest.test_case "Unclosed block" `Quick unclosed_block; Alcotest.test_case "Unclosed block" `Quick comment_as_operator; Alcotest.test_case "Missing comparable" `Quick missing_comparable; + Alcotest.test_case "Location change" `Quick location_change; ] ) -- cgit v1.2.3