aboutsummaryrefslogtreecommitdiff
path: root/test/syntax_error.ml
diff options
context:
space:
mode:
Diffstat (limited to 'test/syntax_error.ml')
-rw-r--r--test/syntax_error.ml29
1 files changed, 26 insertions, 3 deletions
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;
] )