aboutsummaryrefslogtreecommitdiff
path: root/test/syntax.ml
diff options
context:
space:
mode:
Diffstat (limited to 'test/syntax.ml')
-rw-r--r--test/syntax.ml121
1 files changed, 89 insertions, 32 deletions
diff --git a/test/syntax.ml b/test/syntax.ml
index a49bd1c..432ca8d 100644
--- a/test/syntax.ml
+++ b/test/syntax.ml
@@ -2,6 +2,7 @@ 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 location_id, e1 = Check.build (module Tree)
@@ -78,7 +79,10 @@ let test_numeric_expression () =
let test_negative_numeric_expression () =
_test_instruction "-123"
- [ Expression (Op (_position, Neg, Integer (_position, "123"))) ]
+ [
+ Tree.Ast.Expression
+ (Tree.Ast.Op (_position, T.Neg, Tree.Ast.Integer (_position, "123")));
+ ]
let test_negative_numeric_expression2 () =
let index = None in
@@ -113,18 +117,25 @@ let test_let_literal () =
let index = None in
let var = { Ast.pos = _position; name = "VALUE"; index } in
_test_instruction "let value = '123'"
- Ast.[ Declaration (_position, var, Eq', Literal (_position, "123")) ]
+ Ast.
+ [
+ Declaration (_position, var, Eq', Literal (_position, [ T.Text "123" ]));
+ ]
let test_set_array_append () =
let var = { Ast.pos = _position; name = "$VALUE"; index = None } in
_test_instruction "set $value[] = ''"
- Ast.[ Declaration (_position, var, Eq', Literal (_position, "")) ]
+ Ast.
+ [ Declaration (_position, var, Eq', Literal (_position, [ T.Text "" ])) ]
let test_direct_assignation () =
let index = None in
let var = { Ast.pos = _position; name = "VALUE"; index } in
_test_instruction "value = '123'"
- Ast.[ Declaration (_position, var, Eq', Literal (_position, "123")) ]
+ Ast.
+ [
+ Declaration (_position, var, Eq', Literal (_position, [ T.Text "123" ]));
+ ]
let test_command_assignation () =
let index = None in
@@ -137,7 +148,9 @@ let test_command_assignation () =
st_1,
Eq',
Function
- (_position, Input, [ Literal (_position, "Enter the amount") ]) );
+ ( _position,
+ Input,
+ [ Literal (_position, [ T.Text "Enter the amount" ]) ] ) );
]
let test_assignation2 () =
@@ -155,7 +168,8 @@ $a = '123'
}|}
Ast.
[
- Declaration (_position, var, Eq', Literal (_position, "\n$a = '123'\n"));
+ Declaration
+ (_position, var, Eq', Literal (_position, [ T.Text "\n$a = '123'\n" ]));
]
let test_nested_literal () =
@@ -172,7 +186,7 @@ let test_nested_literal () =
( _position,
{ Ast.pos = _position; name = "VALUE"; index = None },
Qsp_syntax.T.Eq',
- Ast.Literal (_position, "\n\n {\n\n }\n") );
+ Ast.Literal (_position, [ T.Text "\n\n {\n\n }\n" ]) );
]
let test_concat_literal () =
@@ -181,16 +195,21 @@ let test_concat_literal () =
+'456'
|}
[
- Ast.Expression (Ast.Literal (_position, "123"));
+ Ast.Expression (Ast.Literal (_position, [ T.Text "123" ]));
Ast.Expression
- (Ast.Op (_position, Qsp_syntax.T.Add, Ast.Literal (_position, "456")));
+ (Ast.Op
+ ( _position,
+ Qsp_syntax.T.Add,
+ Ast.Literal (_position, [ T.Text "456" ]) ));
]
let test_literal () =
- _test_instruction "'123'" [ Expression (Literal (_position, "123")) ]
+ _test_instruction "'123'"
+ [ Expression (Literal (_position, [ T.Text "123" ])) ]
let test_qutoted_literal () =
- _test_instruction "'12''3'" [ Expression (Literal (_position, "12'3")) ]
+ _test_instruction "'12''3'"
+ [ Expression (Literal (_position, [ T.Text "12'3" ])) ]
let test_multiline1 () =
let content = {|
@@ -263,7 +282,11 @@ let test_plus_litt () =
[
Ast.(
Expression
- (BinaryOp (_position, Plus, Literal (_position, "five"), Ident pears)));
+ (BinaryOp
+ ( _position,
+ Plus,
+ Literal (_position, [ T.Text "five" ]),
+ Ident pears )));
]
let test_concat () =
@@ -285,7 +308,7 @@ $firstName + ' ' + $lastName
name = "$FIRSTNAME";
index = None;
},
- Tree.Ast.Literal (_position, " ") ),
+ Tree.Ast.Literal (_position, [ T.Text " " ]) ),
Tree.Ast.Ident
{ Tree.Ast.pos = _position; name = "$LASTNAME"; index = None } ));
]
@@ -341,7 +364,9 @@ let test_comment6 () =
initialized"
[
Ast.Call
- (_position, Qsp_syntax.T.Gosub, [ Ast.Literal (_position, "stat") ]);
+ ( _position,
+ Qsp_syntax.T.Gosub,
+ [ Ast.Literal (_position, [ T.Text "stat" ]) ] );
Ast.Comment _position;
]
@@ -382,8 +407,10 @@ let test_precedence2 () =
let test_if () =
let index = Some Ast.(Integer (_position, "0")) in
let args = Ast.(Ident { pos = _position; name = "$ARGS"; index })
- and expr1 = Ast.(Literal (_position, "blockA"))
- and expr2 = Ast.(Expression (Literal (_position, "You are in block A"))) in
+ and expr1 = Ast.(Literal (_position, [ T.Text "blockA" ]))
+ and expr2 =
+ Ast.(Expression (Literal (_position, [ T.Text "You are in block A" ])))
+ in
_test_instruction {| if $ARGS[0] = 'blockA':
'You are in block A'
end |}
@@ -401,8 +428,10 @@ end |}
let test_if2 () =
let index = Some Ast.(Integer (_position, "0")) in
let args = Ast.(Ident { pos = _position; name = "$ARGS"; index })
- and expr1 = Ast.(Literal (_position, "blockA"))
- and expr2 = Ast.(Expression (Literal (_position, "You are in block A"))) in
+ and expr1 = Ast.(Literal (_position, [ T.Text "blockA" ]))
+ and expr2 =
+ Ast.(Expression (Literal (_position, [ T.Text "You are in block A" ])))
+ in
_test_instruction {| if $ARGS[0] = 'blockA':
'You are in block A'
end if|}
@@ -531,13 +560,13 @@ let test_if_inline_act () =
Ast.Act
{
loc = _position;
- label = Ast.Literal (_position, "go");
+ label = Ast.Literal (_position, [ T.Text "go" ]);
statements =
[
Ast.Call
( _position,
Qsp_syntax.T.Goto,
- [ Ast.Literal (_position, "go") ] );
+ [ Ast.Literal (_position, [ T.Text "go" ]) ] );
];
};
] );
@@ -559,13 +588,13 @@ let test_if_inline_act2 () =
Ast.Act
{
loc = _position;
- label = Ast.Literal (_position, "go");
+ label = Ast.Literal (_position, [ T.Text "go" ]);
statements =
[
Ast.Call
( _position,
Qsp_syntax.T.Goto,
- [ Ast.Literal (_position, "go") ] );
+ [ Ast.Literal (_position, [ T.Text "go" ]) ] );
Ast.Comment _position;
];
};
@@ -578,8 +607,9 @@ let test_if_inline_act2 () =
let test_precedence3 () =
let index = Some Ast.(Integer (_position, "0")) in
let args = Ast.(Ident { pos = _position; name = "$ARGS"; index })
- and expr1 = Ast.(Literal (_position, "blockA"))
- and expr2 = Ast.(Expression (Literal (_position, "You are in block A")))
+ and expr1 = Ast.(Literal (_position, [ T.Text "blockA" ]))
+ and expr2 =
+ Ast.(Expression (Literal (_position, [ T.Text "You are in block A" ])))
and expr3 = Ast.(Expression (Integer (_position, "0"))) in
_test_instruction {| if $ARGS[0] = 'blockA': 'You are in block A' & 0|}
Ast.
@@ -599,7 +629,11 @@ let test_precedence3 () =
let test_gs () =
_test_instruction "gs '123'"
[
- Ast.(Call (_position, Qsp_syntax.T.Gosub, [ Literal (_position, "123") ]));
+ Ast.(
+ Call
+ ( _position,
+ Qsp_syntax.T.Gosub,
+ [ Literal (_position, [ T.Text "123" ]) ] ));
]
let test_gt () =
@@ -615,7 +649,10 @@ let test_gt () =
let test_nl () =
_test_instruction "*NL 'It'"
[
- Ast.Call (_position, Qsp_syntax.T.Nl', [ Ast.Literal (_position, "It") ]);
+ Ast.Call
+ ( _position,
+ Qsp_syntax.T.Nl',
+ [ Ast.Literal (_position, [ T.Text "It" ]) ] );
]
let test_function () =
@@ -693,7 +730,8 @@ let test_dyneval () =
_test_instruction "dyneval ''"
[
Ast.Expression
- (Ast.Function (_position, Dyneval, [ Ast.Literal (_position, "") ]));
+ (Ast.Function
+ (_position, Dyneval, [ Ast.Literal (_position, [ T.Text "" ]) ]));
]
(** The parens after input are considered as arguments for the function, not a
@@ -709,8 +747,10 @@ let test_input () =
( _position,
Eq,
Tree.Ast.Function
- (_position, Input, [ Tree.Ast.Literal (_position, "") ]),
- Tree.Ast.Literal (_position, "") ));
+ ( _position,
+ Input,
+ [ Tree.Ast.Literal (_position, [ T.Text "" ]) ] ),
+ Tree.Ast.Literal (_position, [ T.Text "" ]) ));
]
let test_mutiple_inline_ifs () =
@@ -762,7 +802,7 @@ let test_precedence7 () =
Plus,
Tree.Ast.Integer (_position, "1"),
Tree.Ast.Integer (_position, "1") ),
- Tree.Ast.Literal (_position, "") ));
+ Tree.Ast.Literal (_position, [ T.Text "" ]) ));
]
let test_precedence8 () =
@@ -791,8 +831,24 @@ let nested_string () =
Tree.Ast.Expression
(Tree.Ast.Literal
( _position,
- {|<a href="exec: dynamic 'killvar''$zapis'',<<jur_temp>>">Delete</a>|}
- ));
+ [
+ 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 () =
+ _test_instruction {|day-7|}
+ [
+ Tree.Ast.Expression
+ (Tree.Ast.BinaryOp
+ ( _position,
+ T.Minus,
+ Tree.Ast.Ident
+ { Tree.Ast.pos = _position; name = "DAY"; index = None },
+ Tree.Ast.Integer (_position, "7") ));
]
let test =
@@ -860,4 +916,5 @@ let test =
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;
] )