summaryrefslogtreecommitdiff
path: root/tests/typ/code/ops-prec.typ
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-06-09 10:51:19 +0200
committerLaurenz <laurmaedje@gmail.com>2021-06-09 10:51:19 +0200
commitc7416f18bdddf48f4535a6d48927c2355d842af9 (patch)
tree2730265f83bd98d8f670ac47588d499a43c1ad92 /tests/typ/code/ops-prec.typ
parentedff2ae6803928e59eae96e2f75cd62a7e24c76f (diff)
Move invalid syntax tests into appropriate places
Diffstat (limited to 'tests/typ/code/ops-prec.typ')
-rw-r--r--tests/typ/code/ops-prec.typ30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/typ/code/ops-prec.typ b/tests/typ/code/ops-prec.typ
new file mode 100644
index 00000000..e64e583c
--- /dev/null
+++ b/tests/typ/code/ops-prec.typ
@@ -0,0 +1,30 @@
+// Test operator precedence.
+// Ref: false
+
+---
+// Multiplication binds stronger than addition.
+#test(1+2*-3, -5)
+
+// Subtraction binds stronger than comparison.
+#test(3 == 5 - 2, true)
+
+// Boolean operations bind stronger than '=='.
+#test("a" == "a" and 2 < 3, true)
+#test(not "b" == "b", false)
+
+// Assignment binds stronger than boolean operations.
+// Error: 2-7 cannot assign to this expression
+{not x = "a"}
+
+---
+// Parentheses override precedence.
+#test((1), 1)
+#test((1+2)*-3, -9)
+
+// Error: 14 expected closing paren
+#test({(1 + 1}, 2)
+
+---
+// Precedence doesn't matter for chained unary operators.
+// Error: 2-11 cannot apply '-' to boolean
+{-not true}