diff options
-rw-r--r-- | test/dune | 1 | ||||
-rw-r--r-- | test/literals.ml | 56 | ||||
-rw-r--r-- | test/qsp_parser_test.ml | 4 | ||||
-rw-r--r-- | test/syntax.ml | 18 |
4 files changed, 63 insertions, 16 deletions
@@ -1,5 +1,6 @@ (test (name qsp_parser_test) + (modes byte exe) (libraries alcotest sedlex 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; + ] ) diff --git a/test/qsp_parser_test.ml b/test/qsp_parser_test.ml index 0828e22..7fd5b52 100644 --- a/test/qsp_parser_test.ml +++ b/test/qsp_parser_test.ml @@ -1,3 +1,5 @@ let () = Alcotest.run "qsp_parser" - [ Syntax.test; Syntax_error.test; Type_of.test; Dead_end.test ] + [ + Syntax.test; Literals.test; Syntax_error.test; Type_of.test; Dead_end.test; + ] diff --git a/test/syntax.ml b/test/syntax.ml index 432ca8d..aabe2a8 100644 --- a/test/syntax.ml +++ b/test/syntax.ml @@ -790,6 +790,7 @@ let test_mutiple_inline_ifs () = }; ] +(** The boolean comparaison has greater precedence than arithmetic operator *) let test_precedence7 () = _test_instruction "(1 + 1 = '')" [ @@ -805,6 +806,7 @@ let test_precedence7 () = Tree.Ast.Literal (_position, [ T.Text "" ]) )); ] +(** The OR operator has greater precedence than boolean comparaison *) let test_precedence8 () = _test_instruction "(0 = 1 or 0 = 1)" [ @@ -824,19 +826,6 @@ let test_precedence8 () = Tree.Ast.Integer (_position, "1") ) )); ] -let nested_string () = - _test_instruction - {|'<a href="exec: dynamic ''killvar''''$zapis'''',<<jur_temp>>">Delete</a>'|} - [ - Tree.Ast.Expression - (Tree.Ast.Literal - ( _position, - [ - T.Text - {|<a href="exec: dynamic 'killvar''$zapis'',<<jur_temp>>">Delete</a>|}; - ] )); - ] - (** Test showing the - should be considered as an operator and cannot be aggregated inside the integer value. *) let minus_operator () = @@ -861,6 +850,7 @@ let test = test_negative_numeric_expression; Alcotest.test_case "-Numeric expression2" `Quick test_negative_numeric_expression2; + Alcotest.test_case "Minus op" `Quick minus_operator; Alcotest.test_case "$Variable expression" `Quick test_str_variable; Alcotest.test_case " Variable expression" `Quick test_variable; Alcotest.test_case "Indexed Variable expression" `Quick @@ -915,6 +905,4 @@ let test = Alcotest.test_case "inline if else if" `Quick test_mutiple_inline_ifs; Alcotest.test_case "Precedence7" `Quick test_precedence7; Alcotest.test_case "Precedence8" `Quick test_precedence8; - Alcotest.test_case "Nested string" `Quick nested_string; - Alcotest.test_case "Nested string" `Quick minus_operator; ] ) |