1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
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 {|!'<<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",
[
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;
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;
] )
|