aboutsummaryrefslogtreecommitdiff
path: root/test/literals.ml
diff options
context:
space:
mode:
authorChimrod <>2023-10-29 11:05:47 +0100
committerChimrod <>2023-11-02 14:53:02 +0100
commita1bb96e73f54eaa7c7e4af5d930e9d10074afb08 (patch)
treeb51a0900a4220765c1cbefce3fb39ab57bd1ffaa /test/literals.ml
parent77ae152ece4efbf8dde983c03bd995c982522bfd (diff)
Added tests for the nested literal mecanism
Diffstat (limited to 'test/literals.ml')
-rw-r--r--test/literals.ml56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/literals.ml b/test/literals.ml
new file mode 100644
index 0000000..0d7799d
--- /dev/null
+++ b/test/literals.ml
@@ -0,0 +1,56 @@
+module Tree = Qsp_syntax.Tree
+module Ast = Tree.Ast
+module Check = Qsp_syntax.Check
+module S = Qsp_syntax.S
+module T = Qsp_syntax.T
+
+let _test_instruction = Syntax._test_instruction
+let _position = Syntax._position
+
+let result =
+ [
+ Tree.Ast.Expression
+ (Tree.Ast.Literal
+ ( _position,
+ [
+ T.Expression [ Tree.Ast.Literal (_position, [ T.Text "key" ]) ];
+ T.Text "";
+ ] ));
+ ]
+
+(* String and escaped delimiter *)
+
+let nested_squote () = _test_instruction "'<<''key''>>'" result
+let nested_dquote () = _test_instruction {|"<<""key"">>"|} result
+let long_quote () = _test_instruction {|{<<{key}>>}|} result
+
+(* Mix bewteen string enclosing *)
+
+let nested_string_literal2 () = _test_instruction {|"<<'key'>>"|} result
+let nested_string_literal4 () = _test_instruction {|{<<'key'>>}|} result
+
+(* The current state shall remain when we are inside an expression. *)
+
+let nested_string_expression1 () = _test_instruction {|'<<(''key'')>>'|} result
+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 test =
+ ( "Literals",
+ [
+ Alcotest.test_case "Nested squote" `Quick nested_squote;
+ Alcotest.test_case "Nested string with literal2" `Quick
+ nested_string_literal2;
+ Alcotest.test_case "Nested dquote" `Quick nested_dquote;
+ Alcotest.test_case "Nested string with literal4" `Quick
+ nested_string_literal4;
+ Alcotest.test_case "Nested long_quote" `Quick long_quote;
+ Alcotest.test_case "Nested string with expression1" `Quick
+ nested_string_expression1;
+ Alcotest.test_case "Nested string with expression2" `Quick
+ nested_string_expression2;
+ Alcotest.test_case "Nested comment" `Quick nested_comment;
+ ] )