summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarmare314 <49279081+Marmare314@users.noreply.github.com>2023-04-25 11:22:12 +0200
committerGitHub <noreply@github.com>2023-04-25 11:22:12 +0200
commitd5d98b67a83944d72a5c0f8e8e2f43aeee667122 (patch)
tree11580441926d1c24c6243868232b44b844663c4b /tests
parentefad1e71fa699e0d2413d3a6a3ce5a4163e38112 (diff)
Destructuring assign (#703)
Diffstat (limited to 'tests')
-rw-r--r--tests/typ/compiler/let.typ10
-rw-r--r--tests/typ/compiler/ops-invalid.typ4
-rw-r--r--tests/typ/compiler/ops.typ42
3 files changed, 54 insertions, 2 deletions
diff --git a/tests/typ/compiler/let.typ b/tests/typ/compiler/let.typ
index 160d2147..7081bcf0 100644
--- a/tests/typ/compiler/let.typ
+++ b/tests/typ/compiler/let.typ
@@ -121,6 +121,12 @@ Three
// Error: 13-14 at most one binding per identifier is allowed
#let (a: a, a) = (a: 1, b: 2)
+// Error: 13-20 expected identifier, found function call
+#let (a, b: b.at(0)) = (a: 1, b: 2)
+
+// Error: 7-14 expected identifier or destructuring sink, found function call
+#let (a.at(0),) = (1,)
+
---
// Error: 13-14 not enough elements to destructure
#let (a, b, c) = (1, 2)
@@ -181,11 +187,11 @@ Three
#let (a, b) = (a: 1)
---
-// Error: 13-14 destructuring key not found in dictionary
+// Error: 10-11 destructuring key not found in dictionary
#let (a, b: b) = (a: 1)
---
-// Error: 7-8 cannot destructure named elements from an array
+// Error: 7-11 cannot destructure named elements from an array
#let (a: a, b) = (1, 2, 3)
---
diff --git a/tests/typ/compiler/ops-invalid.typ b/tests/typ/compiler/ops-invalid.typ
index 3ab62929..2af3b767 100644
--- a/tests/typ/compiler/ops-invalid.typ
+++ b/tests/typ/compiler/ops-invalid.typ
@@ -101,6 +101,10 @@
#((x) = "")
---
+// Error: 4-5 unknown variable: x
+#((x,) = (1,))
+
+---
// Error: 3-8 cannot mutate a temporary value
#(1 + 2 += 3)
diff --git a/tests/typ/compiler/ops.typ b/tests/typ/compiler/ops.typ
index a6c64cbd..2bb06e4d 100644
--- a/tests/typ/compiler/ops.typ
+++ b/tests/typ/compiler/ops.typ
@@ -201,6 +201,48 @@
#(x += "thing") #test(x, "something")
---
+// Test destructuring assignments.
+
+#let a = none
+#let b = none
+#let c = none
+#((a,) = (1,))
+#test(a, 1)
+
+#((_, a, b, _) = (1, 2, 3, 4))
+#test(a, 2)
+#test(b, 3)
+
+#((a, b, ..c) = (1, 2, 3, 4, 5, 6))
+#test(a, 1)
+#test(b, 2)
+#test(c, (3, 4, 5, 6))
+
+#((a: a, b, x: c) = (a: 1, b: 2, x: 3))
+#test(a, 1)
+#test(b, 2)
+#test(c, 3)
+
+#let a = (1, 2)
+#((a: a.at(0), b) = (a: 3, b: 4))
+#test(a, (3, 2))
+#test(b, 4)
+
+#let a = (1, 2)
+#((a.at(0), b) = (3, 4))
+#test(a, (3, 2))
+#test(b, 4)
+
+#((a, ..b) = (1, 2, 3, 4))
+#test(a, 1)
+#test(b, (2, 3, 4))
+
+#let a = (1, 2)
+#((b, ..a.at(0)) = (1, 2, 3, 4))
+#test(a, ((2, 3, 4), 2))
+#test(b, 1)
+
+---
// Error: 3-6 cannot mutate a constant: box
#(box = 1)