aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChimrod <>2023-09-29 16:40:36 +0200
committerChimrod <>2023-09-29 17:22:59 +0200
commit93179b90d8b1006001ce53310a6b01ba9f673fb7 (patch)
treee10f37ceb84b6562dbf6b23941eca3cde44b0792 /test
parent3d74fbfd4bd173ae1aac4bf808b00275d48c4be4 (diff)
New precedence test
Diffstat (limited to 'test')
-rw-r--r--test/qsp_parser_test.ml58
1 files changed, 50 insertions, 8 deletions
diff --git a/test/qsp_parser_test.ml b/test/qsp_parser_test.ml
index 6ea9eab..d827099 100644
--- a/test/qsp_parser_test.ml
+++ b/test/qsp_parser_test.ml
@@ -256,18 +256,24 @@ let test_concat () =
let content = {|
$firstName + ' ' + $lastName
|} in
- let index = None in
- let firstname = { Ast.pos = _position; name = "$FIRSTNAME"; index }
- and lastName = { Ast.pos = _position; name = "$LASTNAME"; index }
- and space = Ast.Literal (_position, " ") in
_test_instruction content
[
- Expression
- (BinaryOp
+ Tree.Ast.Expression
+ (Tree.Ast.BinaryOp
( _position,
Plus,
- Ident firstname,
- BinaryOp (_position, Plus, space, Ident lastName) ));
+ Tree.Ast.BinaryOp
+ ( _position,
+ Plus,
+ Tree.Ast.Ident
+ {
+ Tree.Ast.pos = _position;
+ name = "$FIRSTNAME";
+ index = None;
+ },
+ Tree.Ast.Literal (_position, " ") ),
+ Tree.Ast.Ident
+ { Tree.Ast.pos = _position; name = "$LASTNAME"; index = None } ));
]
let test_comment () = _test_instruction "! Comment" [ Comment _position ]
@@ -721,6 +727,40 @@ let test_mutiple_inline_ifs () =
};
]
+let test_precedence7 () =
+ _test_instruction "(1 + 1 = '')"
+ [
+ Tree.Ast.Expression
+ (Tree.Ast.BinaryOp
+ ( _position,
+ Eq,
+ Tree.Ast.BinaryOp
+ ( _position,
+ Plus,
+ Tree.Ast.Integer (_position, "1"),
+ Tree.Ast.Integer (_position, "1") ),
+ Tree.Ast.Literal (_position, "") ));
+ ]
+
+let test_precedence8 () =
+ _test_instruction "(0 = 1 or 0 = 1)"
+ [
+ Tree.Ast.Expression
+ (Tree.Ast.BinaryOp
+ ( _position,
+ Or,
+ Tree.Ast.BinaryOp
+ ( _position,
+ Eq,
+ Tree.Ast.Integer (_position, "0"),
+ Tree.Ast.Integer (_position, "1") ),
+ Tree.Ast.BinaryOp
+ ( _position,
+ Eq,
+ Tree.Ast.Integer (_position, "0"),
+ Tree.Ast.Integer (_position, "1") ) ));
+ ]
+
let syntax =
( "Syntax",
[
@@ -783,6 +823,8 @@ let syntax =
Alcotest.test_case "Dyneval" `Quick test_dyneval;
Alcotest.test_case "Input" `Quick test_input;
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;
] )
let () = Alcotest.run "qsp_parser" [ syntax ]