aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChimrod <>2024-06-04 22:47:07 +0200
committerChimrod <>2024-06-04 22:47:07 +0200
commitcb3b715053e5050201ca6074cf202033f07f50ec (patch)
tree18bc9b7356144249f3108619565a50895f08457b /test
parentb7cc3a4f423ed6ed98cbf87a408fe80335e4ab9b (diff)
Enforced the type_of checker
Diffstat (limited to 'test')
-rw-r--r--test/type_of.ml46
1 files changed, 32 insertions, 14 deletions
diff --git a/test/type_of.ml b/test/type_of.ml
index bca7ea0..a387bf6 100644
--- a/test/type_of.ml
+++ b/test/type_of.ml
@@ -2,28 +2,31 @@ module Check = Make_checkTest.M (Qsp_syntax.Type_of)
let _position = (Lexing.dummy_pos, Lexing.dummy_pos)
-let _test_instruction : string -> Qsp_syntax.Report.t list -> unit =
- Check._test_instruction
-
-let type_mismatch () =
- _test_instruction {|abc = 'ABC'|}
- [
+let message level =
+ [
+ Qsp_syntax.Report.
{
- level = Error;
+ level;
loc = _position;
message = "The type Integer is expected but got String";
};
- ]
+ ]
-let type_mismatch2 () =
- _test_instruction {|abc[''] = $Var|}
- [
+let message' level =
+ [
+ Qsp_syntax.Report.
{
- level = Warn;
+ level;
loc = _position;
- message = "The type Integer is expected but got String";
+ message = "The type String is expected but got Integer";
};
- ]
+ ]
+
+let _test_instruction : string -> Qsp_syntax.Report.t list -> unit =
+ Check._test_instruction
+
+let type_mismatch () = _test_instruction {|abc = 'ABC'|} (message Error)
+let type_mismatch2 () = _test_instruction {|abc[''] = $Var|} (message Warn)
let type_conversion () =
_test_instruction {|abc = '123'|}
@@ -39,6 +42,15 @@ let type_conversion () =
let type_conversion' () = _test_instruction {|abc = '<<123>>'|} []
let type_comparaison () = _test_instruction {|(abc = '123')|} []
+let type_comparaison_eq () = _test_instruction {|($abc = 123)|} (message Warn)
+let type_comparaison_eq' () = _test_instruction {|(1 = "abc")|} (message' Error)
+let type_comparaison_gte () = _test_instruction {|($abc >= 123)|} (message Warn)
+
+let type_comparaison_gte' () =
+ _test_instruction {|(1 >= "abc")|} (message' Error)
+
+let type_comparaison_gt () = _test_instruction {|($abc > 123)|} (message Warn)
+let type_comparaison_gt' () = _test_instruction {|(123 > 'a')|} (message' Error)
let type_comparaison_mismatch () =
_test_instruction {|(abc = 'ABC')|}
@@ -68,6 +80,12 @@ let test =
Alcotest.test_case "Conversion" `Quick type_conversion;
Alcotest.test_case "Conversion'" `Quick type_conversion';
Alcotest.test_case "Comparaison" `Quick type_comparaison;
+ Alcotest.test_case "eq(str, int)" `Quick type_comparaison_eq;
+ Alcotest.test_case "eq(int, str)" `Quick type_comparaison_eq';
+ Alcotest.test_case "gte(str, int)" `Quick type_comparaison_gte;
+ Alcotest.test_case "gte(int, str)" `Quick type_comparaison_gte';
+ Alcotest.test_case "gt(str, int)" `Quick type_comparaison_gt;
+ Alcotest.test_case "gt(int, str)" `Quick type_comparaison_gt';
Alcotest.test_case "Comparaison Mismatch" `Quick type_comparaison_mismatch;
Alcotest.test_case "Wrong predicate" `Quick wrong_predicate;
] )