aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChimrod <>2024-06-06 15:11:05 +0200
committerChimrod <>2024-06-06 15:11:05 +0200
commit89c19613764368afba6659e8586dec010c9b9d6b (patch)
tree803ad12c0b9b7effc0e5d0b50ce049f036fa0811 /test
parent4535058e48fc8edc44be20b92a182279eb9e1569 (diff)
Forgot the case where + is used as a concatenation operator
Diffstat (limited to 'test')
-rw-r--r--test/get_type.ml45
-rw-r--r--test/qsp_parser_test.ml1
-rw-r--r--test/type_of.ml3
3 files changed, 49 insertions, 0 deletions
diff --git a/test/get_type.ml b/test/get_type.ml
new file mode 100644
index 0000000..d7bb333
--- /dev/null
+++ b/test/get_type.ml
@@ -0,0 +1,45 @@
+module Get_type = Qsp_syntax.Get_type
+module T = Qsp_syntax.T
+
+let _position = (Lexing.dummy_pos, Lexing.dummy_pos)
+
+let type_of : Get_type.t Alcotest.testable =
+ Alcotest.testable Get_type.pp Get_type.equal
+
+let add_number () =
+ let actual =
+ Get_type.boperator _position T.Plus
+ (Get_type.integer _position "0")
+ (Get_type.integer _position "1")
+ in
+ let expected = Get_type.(Raw Integer) in
+ let msg = "Adding integer" in
+ Alcotest.(check' type_of ~msg ~expected ~actual)
+
+let add_literal_number () =
+ let actual =
+ Get_type.boperator _position T.Plus
+ (Get_type.literal _position [ T.Text "2" ])
+ (Get_type.integer _position "1")
+ in
+ let expected = Get_type.(Raw Integer) in
+ let msg = "A string containing integer is considered as integer" in
+ Alcotest.(check' type_of ~msg ~expected ~actual)
+
+let concat_text () =
+ let actual =
+ Get_type.boperator _position T.Plus
+ (Get_type.literal _position [ T.Text "a" ])
+ (Get_type.integer _position "1")
+ in
+ let expected = Get_type.(Raw String) in
+ let msg = "Concatenate" 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;
+ ] )
diff --git a/test/qsp_parser_test.ml b/test/qsp_parser_test.ml
index 4754a15..ada04d3 100644
--- a/test/qsp_parser_test.ml
+++ b/test/qsp_parser_test.ml
@@ -4,6 +4,7 @@ let () =
Syntax.test;
Literals.test;
Syntax_error.test;
+ Get_type.test;
Type_of.test;
Dead_end.test;
Nested_string.test;
diff --git a/test/type_of.ml b/test/type_of.ml
index d2be5e7..aac928e 100644
--- a/test/type_of.ml
+++ b/test/type_of.ml
@@ -73,6 +73,8 @@ let wrong_predicate () =
};
]
+let concat_text () = _test_instruction {|$a = 'A' + 1|} []
+
let test =
( "Typechecking",
[
@@ -90,4 +92,5 @@ let test =
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;
+ Alcotest.test_case "+(int, str)" `Quick concat_text;
] )