aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChimrod <>2024-01-19 11:55:15 +0100
committerChimrod <>2024-01-19 11:55:15 +0100
commit86fd78a5ab65015a9c18ad601856f1b16ed90fa9 (patch)
treeef47902c248fe385fffbcf6162001aa81748b895 /test
parentc8fb3bdbf3d35c0fd4496d3150961e1fcb202f05 (diff)
Wait to get a valid syntax before considering a new location
Diffstat (limited to 'test')
-rw-r--r--test/make_checkTest.ml2
-rw-r--r--test/syntax_error.ml29
2 files changed, 26 insertions, 5 deletions
diff --git a/test/make_checkTest.ml b/test/make_checkTest.ml
index 308d309..2066c22 100644
--- a/test/make_checkTest.ml
+++ b/test/make_checkTest.ml
@@ -1,5 +1,3 @@
-let _position = (Lexing.dummy_pos, Lexing.dummy_pos)
-
(** Build a parser for a specific check module *)
module M (Check : Qsp_syntax.S.Analyzer) = struct
module S = Qsp_syntax.S
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;
] )