2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/pmc/fixedintegerarray.t - FixedIntegerArray PMC
11 % prove t/pmc/fixedintegerarray.t
15 Tests C<FixedIntegerArray> PMC. Checks size, sets various elements, including
16 out-of-bounds test. Checks INT and PMC keys.
21 .include 'test_more.pir'
37 test_invalid_init_tt1509()
40 .sub 'test_new_style_init'
41 $P0 = new 'FixedIntegerArray', 10
44 is($I0, 10, "New style init creates the correct # of elements")
46 $P0 = new ['FixedIntegerArray'], 10
49 is($I0, 10, "New style init creates the correct # of elements for a key constant")
53 $P0 = new ['FixedIntegerArray']
56 is($I0, 0, "Fresh array has 0 elements")
60 is($I0, 42, "Size was set correctly")
63 .sub 'test_reset_size'
64 $P0 = new ['FixedIntegerArray']
74 ok($I0, "Can't resize")
78 $P0 = new ['FixedIntegerArray']
83 is($I0, -7, "First element set to integer properly")
87 is($I0, 3, "First element set to number properly")
91 is($I0, 17, "First element set to string properly")
94 .sub 'test_set_second'
95 $P0 = new ['FixedIntegerArray']
100 is($I0, -7, "Second element set to integer properly")
104 is($I0, 3, "Second element set to number properly")
108 is($I0, 17, "Second element set to string properly")
112 .sub 'test_out_of_bounds'
113 $P0 = new ['FixedIntegerArray']
121 ok($I0, "Can't set out-of-bounds element")
124 push_eh handle_set_negative
128 ok($I0, "Can't set element on negative index")
135 ok($I0, "Can't get out-of-bounds element")
138 push_eh handle_get_negative
142 ok($I0, "Can't get element with negative index")
146 # Set via PMC keys, access via INTs
147 .sub 'test_set_via_pmc'
148 $P0 = new ['FixedIntegerArray']
156 is($I0, 25, "Set INTVAL via PMC Key works")
161 is($I0, 2, "Set FLOATVAL via PMC Key works")
166 is($I0, 17, "Set STRING via PMC Key works")
169 # Set via INTs, access via PMC Keys
170 .sub 'test_get_via_pmc'
171 $P0 = new ['FixedIntegerArray']
178 $P1 = new ['Integer']
186 is($I0, 125, "Get INTVAL via Key works")
190 is($N0, 10.0, "Get FLOATVAL via Key works")
194 is($S0, "17", "Get STRING via Key works")
198 is($I0, 123456, "Get INTVAL for stored PMC via Key works")
202 .sub 'test_interface_done'
204 pmc1 = new ['FixedIntegerArray']
206 does bool1, pmc1, "scalar"
207 nok(bool1, "Does not scalar")
208 does bool1, pmc1, "array"
209 ok(bool1, "Does array")
210 does bool1, pmc1, "no_interface"
211 nok(bool1, "Does not no_interface")
215 $P0 = new ['FixedIntegerArray']
223 unless $P1 goto loop_end
228 is($S0, "424344", "Iteration works")
232 .local pmc a1, a2, a3
233 a1 = new ['FixedIntegerArray']
234 a2 = new ['FixedIntegerArray']
236 is(a1, a2, "Empty arrays are equal")
239 isnt(a1, a2, "Different size arrays aren't equal")
245 is(a1, a2, "Equal with first element set")
248 isnt(a1, a2, "Not equal when second element differ")
251 is(a1, a2, "Equal when second element same")
254 isnt(a1, a3, "Different PMC type is not equal")
260 a1 = new ['FixedIntegerArray']
265 is(r, '[ 7, 1 ]', 'get_repr')
268 .sub 'test_new_style_init'
269 $P0 = new ['FixedIntegerArray'], 10
272 is($I0, 10, "New style init creates the correct # of elements")
277 a1 = new ['FixedIntegerArray'], 3
282 a2 = new ['FixedIntegerArray'], 3
289 is($I0, 1, 'default sort')
292 .sub test_invalid_init_tt1509
293 throws_substring(<<'CODE', 'FixedIntegerArray: Cannot set array size to a negative number (-10)', 'New style init does not dump core for negative array lengths')
295 $P0 = new ['FixedIntegerArray'], -10
299 throws_substring(<<'CODE', 'FixedIntegerArray: Cannot set array size to a negative number (-10)', 'New style init (key constant) does not dump core for negative array lengths')
301 $P0 = new 'FixedIntegerArray', -10
312 # vim: expandtab shiftwidth=4 ft=pir: