summaryrefslogtreecommitdiff
path: root/tests/typ/bugs/3275-loop-errors.typ
diff options
context:
space:
mode:
authorLeedehai <18319900+Leedehai@users.noreply.github.com>2024-01-31 04:12:06 -0500
committerGitHub <noreply@github.com>2024-01-31 09:12:06 +0000
commit51854ba4df0e941bd17acee499fdb3a7e43b31e0 (patch)
tree32bde5fc13107df85d82aa8e1d5c0384e4b9db91 /tests/typ/bugs/3275-loop-errors.typ
parentce5abf5a4e338a151f8c8a49bc5ba864c1319d9d (diff)
Adjust for-loop's pattern matching rules (#3308)
Diffstat (limited to 'tests/typ/bugs/3275-loop-errors.typ')
-rw-r--r--tests/typ/bugs/3275-loop-errors.typ49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/typ/bugs/3275-loop-errors.typ b/tests/typ/bugs/3275-loop-errors.typ
new file mode 100644
index 00000000..0f05d6af
--- /dev/null
+++ b/tests/typ/bugs/3275-loop-errors.typ
@@ -0,0 +1,49 @@
+// Issue #3275: clearer errors for loops, https://github.com/typst/typst/issues/3275
+// Ref: false
+
+---
+// Normal variable.
+#for x in (1, 2) {}
+#for x in (a: 1, b: 2) {}
+#for x in "foo" {}
+
+---
+// Placeholder.
+#for _ in (1, 2) {}
+#for _ in (a: 1, b: 2) {}
+#for _ in "foo" {}
+
+---
+// Destructuring.
+#for (k, v) in (("a", 1), ("b", 2), ("c", 3)) {}
+#for (k, ..) in (("a", 1), ("b", 2), ("c", 3)) {}
+#for (k, v) in (a: 1, b: 2, c: 3) {}
+#for (.., v) in (a: 1, b: 2, c: 3) {}
+
+---
+// Error: 11-17 cannot loop over content
+#for x in [1, 2] {}
+
+---
+// Error: 11-25 cannot loop over bytes
+#for _ in bytes((22, 0)) {}
+
+---
+// Error: 16-21 cannot loop over integer
+#for (x, y) in 12306 {}
+
+---
+// Error: 16-22 cannot loop over content
+#for (x, y) in [1, 2] {}
+
+---
+// Error: 6-12 cannot destructure values of string
+#for (x, y) in "foo" {}
+
+---
+// Error: 6-12 cannot destructure string
+#for (x, y) in ("foo", "bar") {}
+
+---
+// Error: 6-12 cannot destructure integer
+#for (x, y) in (1, 2) {}