aboutsummaryrefslogtreecommitdiff
path: root/tests/type/map/testscript
blob: 29f5ed49083ad1ffed951a53e962e6ac5a5fd301 (plain)
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
# file      : tests/type/map/testscript
# license   : MIT; see accompanying LICENSE file

# See also tests in function/*/ (size(), keys()), type/json/ (json_map).

.include ../../common.testscript

: basics
:
$* <<EOI >>EOO
m = [string_map] a@0 b@2 a@1
print $m
m += c@3 b@0
print $m
m =+ d@4 b@1
print $m
EOI
a@1 b@2
a@1 b@0 c@3
a@1 b@0 c@3 d@4
EOO

: type
:
$* <<EOI >>EOO
m = [string_map]
print $type($m)
EOI
string_map
EOO

: subscript
:
$* <<EOI >>EOO
m = [string_map] a@1 b@2 c@3
print ($m[b])
print $type($m[b])
print ($m[z])
EOI
2
string
[null]
EOO

: iteration
:
$* <<EOI >>EOO
for p: [string_map] a@1 b@2 c@3
  print $first($p) $second($p)

for p: [string_map, null]
  fail bad
EOI
a 1
b 2
c 3
EOO

: iteration-index
:
$* <<EOI >>EOO
m = [string_map] a@1 b@2 c@3
k = $keys($m)
for i: $integer_sequence(0, $size($k))
  print $i ($k[$i]) ($m[($k[$i])]) # @@ TMP: nested subscript
EOI
0 a 1
1 b 2
2 c 3
EOO