summaryrefslogtreecommitdiff
path: root/tests/typ/code/dict.typ
blob: d791f77bededfa75278fc329d8a470d57af2bb78 (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
// Test dictionaries.
// Ref: false

---
// Ref: true

// Empty
{(:)}

// Two pairs and string key.
#let dict = (normal: 1, "spacy key": 2)
#dict

#test(dict.normal, 1)
#test(dict("spacy key"), 2)

---
// Test lvalue and rvalue access.
{
  let dict = (a: 1, "b b": 1)
  dict("b b") += 1
  dict.state = (ok: true, err: false)
  test(dict, (a: 1, "b b": 2, state: (ok: true, err: false)))
  test(dict.state.ok, true)
  dict("state").ok = false
  test(dict.state.ok, false)
  test(dict.state.err, false)
}

---
// Test rvalue missing key.
{
  let dict = (a: 1, b: 2)
  // Error: 11-20 dictionary does not contain key "c"
  let x = dict("c")
}

---
// Missing lvalue is automatically none-initialized.
{
  let dict = (:)
  dict("b") += 1
  test(dict, (b: 1))
}

---
// Error: 24-32 pair has duplicate key
{(first: 1, second: 2, first: 3)}

---
// Error: 17-23 pair has duplicate key
{(a: 1, "b": 2, "a": 3)}

---
// Simple expression after already being identified as a dictionary.
// Error: 9-10 expected named or keyed pair, found identifier
{(a: 1, b)}

// Identified as dictionary due to initial colon.
// Error: 4-5 expected named or keyed pair, found integer
// Error: 5 expected comma
// Error: 12-16 expected identifier or string, found boolean
// Error: 17-18 expected expression, found colon
{(:1 b:"", true::)}

---
// Error: 3-15 cannot mutate a temporary value
{ (key: value).other = "some" }

---
{
  let object = none
  // Error: 3-9 expected dictionary, found none
  object.property = "value"
}