aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChimrod <>2023-10-30 08:22:39 +0100
committerChimrod <>2023-11-02 14:53:02 +0100
commit05f74bee05c0c56da593a5e89069711d5993e3b1 (patch)
treed09dbc7fb8228b8091a48f7d4bf5f095638f2bad /test
parenta1bb96e73f54eaa7c7e4af5d930e9d10074afb08 (diff)
Managed the strings in strings
Diffstat (limited to 'test')
-rw-r--r--test/literals.ml64
-rw-r--r--test/type_of.ml4
2 files changed, 66 insertions, 2 deletions
diff --git a/test/literals.ml b/test/literals.ml
index 0d7799d..6070f86 100644
--- a/test/literals.ml
+++ b/test/literals.ml
@@ -20,7 +20,7 @@ let result =
(* String and escaped delimiter *)
-let nested_squote () = _test_instruction "'<<''key''>>'" result
+let nested_squote () = _test_instruction {|'<<''key''>>'|} result
let nested_dquote () = _test_instruction {|"<<""key"">>"|} result
let long_quote () = _test_instruction {|{<<{key}>>}|} result
@@ -36,7 +36,63 @@ let nested_string_expression2 () = _test_instruction {|"<<('key')>>"|} result
(* The block shall also interpreted when inside a comment *)
-let nested_comment () = _test_instruction "!! '<<variable>>'" result
+let nested_comment () =
+ _test_instruction {|!'<<expr>>'|} [ Tree.Ast.Comment _position ];
+ _test_instruction {|!"<<expr>>"|} [ Tree.Ast.Comment _position ];
+ _test_instruction {|!{<<expr>>}|} [ Tree.Ast.Comment _position ]
+
+let comment2 () =
+ _test_instruction {|!"text <<expr>>"|} [ Tree.Ast.Comment _position ];
+ _test_instruction {|!{text <<expr>>}|} [ Tree.Ast.Comment _position ];
+ _test_instruction {|!'text <<expr>>'|} [ Tree.Ast.Comment _position ]
+
+(** A single quote inside a string does not mean we are starting nested string
+ *)
+let direct_text () =
+ _test_instruction {|"don't"|}
+ [ Tree.Ast.Expression (Tree.Ast.Literal (_position, [ T.Text "don't" ])) ];
+ _test_instruction {|'don"t'|}
+ [ Tree.Ast.Expression (Tree.Ast.Literal (_position, [ T.Text "don\"t" ])) ];
+ _test_instruction {|'don{t'|}
+ [ Tree.Ast.Expression (Tree.Ast.Literal (_position, [ T.Text "don{t" ])) ]
+
+let elements_sequence () =
+ _test_instruction {|"'<<$array[''key'']>>'"|}
+ [
+ Tree.Ast.Expression
+ (Tree.Ast.Literal (_position, [ T.Text "'<<$array[''key'']>>'" ]));
+ ]
+
+let expression () =
+ _test_instruction {|'<<iif(var=0,1,0)>>'|}
+ [
+ Tree.Ast.Expression
+ (Tree.Ast.Literal
+ ( _position,
+ [
+ T.Expression
+ [
+ Tree.Ast.Function
+ ( _position,
+ T.Iif,
+ [
+ Tree.Ast.BinaryOp
+ ( _position,
+ T.Eq,
+ Tree.Ast.Ident
+ {
+ Tree.Ast.pos = _position;
+ name = "VAR";
+ index = None;
+ },
+ Tree.Ast.Integer (_position, "0") );
+ Tree.Ast.Integer (_position, "1");
+ Tree.Ast.Integer (_position, "0");
+ ] );
+ ];
+ T.Text "";
+ ] ));
+ ]
let test =
( "Literals",
@@ -53,4 +109,8 @@ let test =
Alcotest.test_case "Nested string with expression2" `Quick
nested_string_expression2;
Alcotest.test_case "Nested comment" `Quick nested_comment;
+ Alcotest.test_case "Comment2" `Quick comment2;
+ Alcotest.test_case "Quote in string" `Quick direct_text;
+ Alcotest.test_case "elements_sequence" `Quick elements_sequence;
+ Alcotest.test_case "expression" `Quick expression;
] )
diff --git a/test/type_of.ml b/test/type_of.ml
index 18aae1f..a73684a 100644
--- a/test/type_of.ml
+++ b/test/type_of.ml
@@ -25,6 +25,9 @@ let type_conversion () =
};
]
+(** This expression is not considered as a string *)
+let type_conversion' () = _test_instruction {|abc = '<<123>>'|} []
+
let type_comparaison () = _test_instruction {|(abc = '123')|} []
let type_comparaison_mismatch () =
@@ -52,6 +55,7 @@ let test =
[
Alcotest.test_case "Assign" `Quick type_mismatch;
Alcotest.test_case "Conversion" `Quick type_conversion;
+ 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;