summaryrefslogtreecommitdiff
path: root/tests/typ/compiler/ops.typ
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-02-21 09:38:47 +0100
committerGitHub <noreply@github.com>2024-02-21 08:38:47 +0000
commitbe49935753f0e37ae8e04fb53111e6f116c63f47 (patch)
tree0fbc875af61bdedb0d0de42b8809bdb4aae8586f /tests/typ/compiler/ops.typ
parentb2e509d472634fd5dd43514dbde24eedab566abd (diff)
Destructuring improvements (#3463)
Diffstat (limited to 'tests/typ/compiler/ops.typ')
-rw-r--r--tests/typ/compiler/ops.typ32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/typ/compiler/ops.typ b/tests/typ/compiler/ops.typ
index 4d3b071f..e148dd19 100644
--- a/tests/typ/compiler/ops.typ
+++ b/tests/typ/compiler/ops.typ
@@ -274,6 +274,38 @@
#test(b, 1)
---
+// Test comma placement in destructuring assignment.
+#let array = (1, 2, 3)
+#((key: array.at(1)) = (key: "hi"))
+#test(array, (1, "hi", 3))
+
+#let array = (1, 2, 3)
+#((array.at(1)) = ("hi"))
+#test(array, (1, "hi", 3))
+
+#let array = (1, 2, 3)
+#((array.at(1),) = ("hi",))
+#test(array, (1, "hi", 3))
+
+#let array = (1, 2, 3)
+#((array.at(1)) = ("hi",))
+#test(array, (1, ("hi",), 3))
+
+---
+// Test nested destructuring assignment.
+#let a
+#let b
+#let c
+#(((a, b), (key: c)) = ((1, 2), (key: 3)))
+#test((a, b, c), (1, 2, 3))
+
+---
+#let array = (1, 2, 3)
+// Error: 3-17 cannot destructure string
+#((array.at(1),) = ("hi"))
+#test(array, (1, ("hi",), 3))
+
+---
// Error: 3-6 cannot mutate a constant: box
#(box = 1)