summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/typ/compiler/closure.typ4
-rw-r--r--tests/typ/compiler/spread.typ34
2 files changed, 36 insertions, 2 deletions
diff --git a/tests/typ/compiler/closure.typ b/tests/typ/compiler/closure.typ
index bdd8a549..a1e51d56 100644
--- a/tests/typ/compiler/closure.typ
+++ b/tests/typ/compiler/closure.typ
@@ -156,6 +156,10 @@
#let f(a, b, a: none, b: none, c, b) = none
---
+// Error: 13-14 duplicate parameter
+#let f(a, ..a) = none
+
+---
// Error: 7-17 expected identifier, named pair or argument sink, found keyed pair
#((a, "named": b) => none)
diff --git a/tests/typ/compiler/spread.typ b/tests/typ/compiler/spread.typ
index 690e8931..1bfef7b0 100644
--- a/tests/typ/compiler/spread.typ
+++ b/tests/typ/compiler/spread.typ
@@ -27,7 +27,7 @@
#{
let save(..args) = {
test(type(args), "arguments")
- test(repr(args), "(1, 2, three: true)")
+ test(repr(args), "(three: true, 1, 2)")
}
save(1, 2, three: true)
@@ -56,6 +56,11 @@
#f(..for x in () [])
---
+// unnamed spread
+#let f(.., a) = a
+#test(f(1, 2, 3), 3)
+
+---
// Error: 13-19 cannot spread string
#calc.min(.."nope")
@@ -64,7 +69,7 @@
#let f(..true) = none
---
-// Error: 15-16 only one argument sink is allowed
+// Error: 13-16 only one argument sink is allowed
#let f(..a, ..b) = none
---
@@ -91,3 +96,28 @@
---
// Error: 5-11 cannot spread array into dictionary
#(..(1, 2), a: 1)
+
+---
+// Spread at beginning.
+#{
+ let f(..a, b) = (a, b)
+ test(repr(f(1)), "((), 1)")
+ test(repr(f(1, 2, 3)), "((1, 2), 3)")
+ test(repr(f(1, 2, 3, 4, 5)), "((1, 2, 3, 4), 5)")
+}
+
+---
+// Spread in the middle.
+#{
+ let f(a, ..b, c) = (a, b, c)
+ test(repr(f(1, 2)), "(1, (), 2)")
+ test(repr(f(1, 2, 3, 4, 5)), "(1, (2, 3, 4), 5)")
+}
+
+---
+#{
+ let f(..a, b, c, d) = none
+
+ // Error: 4-10 missing argument: d
+ f(1, 2)
+}