summaryrefslogtreecommitdiff
path: root/tests/suite/scripting/while.typ
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-04-13 10:39:45 +0200
committerGitHub <noreply@github.com>2024-04-13 08:39:45 +0000
commit020294fca9a7065d4b9cf4e677f606ebaaa29b00 (patch)
treec0027ad22046e2726c22298461327823d6b88d53 /tests/suite/scripting/while.typ
parent72dd79210602ecc799726fc096b078afbb47f299 (diff)
Better test runner (#3922)
Diffstat (limited to 'tests/suite/scripting/while.typ')
-rw-r--r--tests/suite/scripting/while.typ59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/suite/scripting/while.typ b/tests/suite/scripting/while.typ
new file mode 100644
index 00000000..5e452a89
--- /dev/null
+++ b/tests/suite/scripting/while.typ
@@ -0,0 +1,59 @@
+// Test while expressions.
+
+--- while-loop-basic ---
+// Should output `2 4 6 8 10`.
+#let i = 0
+#while i < 10 [
+ #(i += 2)
+ #i
+]
+
+// Should output `Hi`.
+#let iter = true
+#while iter {
+ iter = false
+ "Hi."
+}
+
+#while false {
+ dont-care
+}
+
+--- while-loop-expr ---
+// Value of while loops.
+
+#test(while false {}, none)
+
+#let i = 0
+#test(type(while i < 1 [#(i += 1)]), content)
+
+--- while-loop-condition-content-invalid ---
+// Condition must be boolean.
+// Error: 8-14 expected boolean, found content
+#while [nope] [nope]
+
+--- while-loop-condition-always-true ---
+// Error: 8-25 condition is always true
+#while 2 < "hello".len() {}
+
+--- while-loop-limit ---
+// Error: 2:2-2:24 loop seems to be infinite
+#let i = 1
+#while i > 0 { i += 1 }
+
+--- while-loop-incomplete ---
+// Error: 7 expected expression
+#while
+
+// Error: 8 expected expression
+#{while}
+
+// Error: 9 expected block
+#while x
+
+// Error: 7 expected expression
+#while
+x {}
+
+// Error: 9 expected block
+#while x something