aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/get_type.ml34
-rw-r--r--test/type_of.ml25
2 files changed, 47 insertions, 12 deletions
diff --git a/test/get_type.ml b/test/get_type.ml
index d7bb333..627e2a8 100644
--- a/test/get_type.ml
+++ b/test/get_type.ml
@@ -36,10 +36,44 @@ let concat_text () =
let msg = "Concatenate" in
Alcotest.(check' type_of ~msg ~expected ~actual)
+let literal_1 () =
+ let actual =
+ Get_type.literal _position [ T.Expression (Get_type.Raw Integer) ]
+ and expected = Get_type.(Raw NumericString) in
+ let msg = "" in
+ Alcotest.(check' type_of ~msg ~expected ~actual)
+
+let literal_2 () =
+ let actual =
+ Get_type.literal _position
+ Get_type.[ T.Text "1"; T.Expression (Raw Integer) ]
+ and expected = Get_type.(Raw NumericString) in
+ let msg = "" in
+ Alcotest.(check' type_of ~msg ~expected ~actual)
+
+let literal_3 () =
+ let actual =
+ Get_type.literal _position
+ Get_type.[ T.Text "b"; T.Expression (Raw Integer) ]
+ and expected = Get_type.(Raw String) in
+ let msg = "" in
+ Alcotest.(check' type_of ~msg ~expected ~actual)
+
+let literal_4 () =
+ let actual =
+ Get_type.literal _position [ T.Expression (Get_type.Variable Integer) ]
+ and expected = Get_type.(Variable NumericString) in
+ let msg = "" in
+ Alcotest.(check' type_of ~msg ~expected ~actual)
+
let test =
( "Type expression",
[
Alcotest.test_case "int + int" `Quick add_number;
Alcotest.test_case "'int' + int" `Quick add_literal_number;
Alcotest.test_case "str + int" `Quick concat_text;
+ Alcotest.test_case "<<int>>" `Quick literal_1;
+ Alcotest.test_case "1<<int>>" `Quick literal_2;
+ Alcotest.test_case "b<<int>>" `Quick literal_3;
+ Alcotest.test_case "<<$int>>" `Quick literal_4;
] )
diff --git a/test/type_of.ml b/test/type_of.ml
index e5f7f9b..53d01bd 100644
--- a/test/type_of.ml
+++ b/test/type_of.ml
@@ -22,25 +22,26 @@ let message' level =
};
]
+let integer_as_string =
+ [
+ Qsp_syntax.Report.
+ {
+ level = Warn;
+ loc = _position;
+ message = "The type Integer is expected but got Integer as String";
+ };
+ ]
+
let _test_instruction : string -> Qsp_syntax.Report.t list -> unit =
Check._test_instruction
let type_mismatch () = _test_instruction {|abc = 'ABC'|} (message Error)
let assign_int_str () = _test_instruction {|$abc = 123|} (message Warn)
let type_mismatch2 () = _test_instruction {|abc[''] = $Var|} (message Warn)
+let type_conversion () = _test_instruction {|abc = '123'|} integer_as_string
-let type_conversion () =
- _test_instruction {|abc = '123'|}
- [
- {
- level = Warn;
- loc = _position;
- message = "The type Integer is expected but got Integer as String";
- };
- ]
-
-(** This expression is not considered as a string *)
-let type_conversion' () = _test_instruction {|abc = '<<123>>'|} []
+let type_conversion' () =
+ _test_instruction {|abc = '<<123>>'|} integer_as_string
let type_comparaison () = _test_instruction {|(abc = '123')|} []
let type_comparaison_eq () = _test_instruction {|($abc = 123)|} (message Warn)