This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
/
table.t
150 lines (129 loc) · 2.71 KB
/
table.t
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! ../../parrot
# Copyright (C) 2009, Parrot Foundation.
# $Id$
=head1 LuaTable
=head2 Synopsis
% parrot t/pmc/table.t
=head2 Description
Tests C<table> type
(implemented in F<languages/lua/src/pmc/luatable.pmc>).
=cut
.sub 'main' :main
loadlib $P0, 'lua_group'
.include 'test_more.pir'
plan(18)
check_inheritance()
check_interface()
check_name()
check_get_string()
check_get_bool()
check_logical_not()
check_key_PMC()
check_key_nil()
check_deletion()
.end
.sub 'check_inheritance'
$P0 = new 'LuaTable'
$I0 = isa $P0, 'scalar'
nok($I0, "check ingeritance")
$I0 = isa $P0, 'LuaAny'
ok($I0)
$I0 = isa $P0, 'LuaTable'
ok($I0)
.end
.sub 'check_interface'
$P0 = new 'LuaTable'
$I0 = does $P0, 'scalar'
nok($I0, "check interface")
$I0 = does $P0, 'no_interface'
nok($I0)
.end
.sub 'check_name'
$P0 = new 'LuaTable'
$S0 = typeof $P0
is($S0, 'table', "check name")
.end
.sub 'check_get_string'
$P0 = new 'LuaTable'
$S0 = $P0
like($S0, '^table: <[0..9A..Fa..f]>*', "check get_string")
.end
.sub 'check_get_bool'
$P0 = new 'LuaTable'
$I0 = istrue $P0
is($I0, 1, "check get_bool")
.end
.sub 'check_logical_not'
$P0 = new 'LuaTable'
$P1 = not $P0
$S0 = $P1
is($S0, 'false', "check logical_not")
$S0 = typeof $P1
is($S0, 'boolean')
.end
.sub 'check_key_PMC'
$P0 = new 'LuaTable'
.local pmc val1
val1 = new 'LuaString'
val1 = "value1"
.local pmc val2
val2 = new 'LuaString'
val2 = "value2"
$P0[val1] = val1
$P0[val2] = val2
$P1 = $P0[val1]
$S0 = $P1
is($S0, "value1", "check key PMC")
$P1 = $P0[val2]
$S0 = $P1
is($S0, "value2")
$P1 = $P0[$P0]
$S0 = $P1
is($S0, 'nil')
.end
.sub 'check_key_nil'
$P0 = new 'LuaTable'
.local pmc val1
val1 = new 'LuaString'
val1 = "value1"
.local pmc nil
nil = new 'LuaNil'
push_eh _handler
$P0[nil] = val1
ok(0, "check key nil")
pop_eh
end
_handler:
.local pmc ex
.get_results (ex)
$S0 = ex
# table index is nil
like($S0, '^table', "check key nil")
.end
.sub 'check_deletion' # by assignment of nil
$P0 = new 'LuaTable'
.local pmc val1
val1 = new 'LuaString'
val1 = "value1"
.local pmc val2
val2 = new 'LuaString'
val2 = "value2"
$I0 = elements $P0
is($I0, 0, "check deletion")
$P0[val1] = val1
$I0 = elements $P0
is($I0, 1)
$P0[val2] = val2
$I0 = elements $P0
is($I0, 2)
.local pmc nil
nil = new 'LuaNil'
$P0[val1] = nil
$I0 = elements $P0
is($I0, 1)
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: