summaryrefslogtreecommitdiff
path: root/tests/typ/code/spread.typ
blob: 5f7d2061782b4f6001d301a54af5518846c8bc61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Test argument sinks and spreading.
// Ref: false

---
// Test standard argument overriding.
{
  let f(style: "normal", weight: "regular") = {
    "(style: " + style + ", weight: " + weight + ")"
  }

  let myf(..args) = f(weight: "bold", ..args)
  test(myf(), "(style: normal, weight: bold)")
  test(myf(weight: "black"), "(style: normal, weight: black)")
  test(myf(style: "italic"), "(style: italic, weight: bold)")
}

---
// Test multiple calls.
{
  let f(b, c: "!") = b + c
  let g(a, ..sink) = a + f(..sink)
  test(g("a", "b", c: "c"), "abc")
}

---
// Test storing arguments in a variable.
{
  let args
  let save(..sink) = {
    args = sink
  }

  save(1, 2, three: true)
  test(type(args), "arguments")
  test(repr(args), "(1, 2, three: true)")
}

---
// Test spreading array and dictionary.
{
  let more = (3, -3, 6, 10)
  test(min(1, 2, ..more), -3)
  test(max(..more, 9), 10)
  test(max(..more, 11), 11)
}

{
  let more = (c: 3, d: 4)
  let tostr(..args) = repr(args)
  test(tostr(a: 1, ..more, b: 2), "(a: 1, c: 3, d: 4, b: 2)")
}

---
// None is spreadable.
#let f() = none
#f(..none)
#f(..if false {})
#f(..for x in () [])

---
// Error: 8-14 cannot spread string
#min(.."nope")

---
// Error: 8-14 expected identifier
#let f(..true) = none

---
// Error: 15-16 only one argument sink is allowed
#let f(..a, ..b) = none

---
// Error: 3-6 spreading is not allowed here
{(..x)}

---
// Error: 9-17 spreading is not allowed here
{(1, 2, ..(1, 2))}