diff options
author | Chimrod <> | 2023-10-28 13:52:38 +0200 |
---|---|---|
committer | Chimrod <> | 2023-11-02 11:06:12 +0100 |
commit | 872916a5661e31b655471ec0f9bf81a5474bc1ba (patch) | |
tree | db18486f978ec97b8ddb4d4ce4e810ccd5cbf7e7 /test/type_of.ml | |
parent | 8a7bdc73a7c65d23c79e1c470ba0fbff975b59a5 (diff) |
Updated the tests
Diffstat (limited to 'test/type_of.ml')
-rw-r--r-- | test/type_of.ml | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/type_of.ml b/test/type_of.ml new file mode 100644 index 0000000..18aae1f --- /dev/null +++ b/test/type_of.ml @@ -0,0 +1,58 @@ +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'|} + [ + { + level = Error; + loc = _position; + message = "The type Integer is expected but got String"; + }; + ] + +let type_conversion () = + _test_instruction {|abc = '123'|} + [ + { + level = Debug; + loc = _position; + message = "The type Integer is expected but got Integer as String"; + }; + ] + +let type_comparaison () = _test_instruction {|(abc = '123')|} [] + +let type_comparaison_mismatch () = + _test_instruction {|(abc = 'ABC')|} + [ + { + level = Warn; + loc = _position; + message = "The type String is expected but got Integer"; + }; + ] + +let wrong_predicate () = + _test_instruction {| if $var and 1: 0 |} + [ + { + level = Warn; + loc = _position; + message = "The type Bool is expected but got String"; + }; + ] + +let test = + ( "Typechecking", + [ + Alcotest.test_case "Assign" `Quick type_mismatch; + Alcotest.test_case "Conversion" `Quick type_conversion; + Alcotest.test_case "Comparaison" `Quick type_comparaison; + Alcotest.test_case "Comparaison Mismatch" `Quick type_comparaison_mismatch; + Alcotest.test_case "Wrong predicate" `Quick wrong_predicate; + ] ) |