2 # Copyright (C) 2001-2008, 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'
24 'test_set_size'() # 2 tests
25 'test_reset_size'() # 1 test
26 'test_set_first'() # 3 tests
27 'test_set_second'() # 3 tests
28 'test_out_of_bounds'() # 4 tests
29 'test_set_via_pmc'() # 3 tests
30 'test_get_via_pmc'() # 4 tests
31 'test_interface_done'() # 4 tests
32 'test_get_iter'() # 1 test
33 'test_equality'() # 5 tests
37 $P0 = new ['FixedIntegerArray']
40 is($I0, 0, "Fresh array has 0 elements")
44 is($I0, 42, "Size was set correctly")
47 .sub 'test_reset_size'
48 $P0 = new ['FixedIntegerArray']
58 ok($I0, "Can't resize")
62 $P0 = new ['FixedIntegerArray']
67 is($I0, -7, "First element set to integer properly")
71 is($I0, 3, "First element set to number properly")
75 is($I0, 17, "First element set to string properly")
78 .sub 'test_set_second'
79 $P0 = new ['FixedIntegerArray']
84 is($I0, -7, "Second element set to integer properly")
88 is($I0, 3, "Second element set to number properly")
92 is($I0, 17, "Second element set to string properly")
96 .sub 'test_out_of_bounds'
97 $P0 = new ['FixedIntegerArray']
105 ok($I0, "Can't set out-of-bounds element")
108 push_eh handle_set_negative
112 ok($I0, "Can't set element on negative index")
119 ok($I0, "Can't get out-of-bounds element")
122 push_eh handle_get_negative
126 ok($I0, "Can't get element with negative index")
130 # Set via PMC keys, access via INTs
131 .sub 'test_set_via_pmc'
132 $P0 = new ['FixedIntegerArray']
140 is($I0, 25, "Set INTVAL via PMC Key works")
145 is($I0, 2, "Set FLOATVAL via PMC Key works")
150 is($I0, 17, "Set STRING via PMC Key works")
153 # Set via INTs, access via PMC Keys
154 .sub 'test_get_via_pmc'
155 $P0 = new ['FixedIntegerArray']
162 $P1 = new ['Integer']
170 is($I0, 125, "Get INTVAL via Key works")
174 is($N0, 10.0, "Get FLOATVAL via Key works")
178 is($S0, "17", "Get STRING via Key works")
182 is($I0, 123456, "Get INTVAL for stored PMC via Key works")
186 .sub 'test_interface_done'
188 pmc1 = new ['FixedIntegerArray']
190 does bool1, pmc1, "scalar"
191 nok(bool1, "Does not scalar")
192 does bool1, pmc1, "array"
193 ok(bool1, "Does array")
194 does bool1, pmc1, "no_interface"
195 nok(bool1, "Does not no_interface")
199 $P0 = new ['FixedIntegerArray']
207 unless $P1 goto loop_end
212 is($S0, "424344", "Iteration works")
217 a1 = new ['FixedIntegerArray']
218 a2 = new ['FixedIntegerArray']
220 is(a1, a2, "Empty arrays are equal")
223 isnt(a1, a2, "Different size arrays aren't equal")
229 is(a1, a2, "Equal with first element set")
232 isnt(a1, a2, "Not equal when second element differ")
235 is(a1, a2, "Equal when second element same")
241 # cperl-indent-level: 4
244 # vim: expandtab shiftwidth=4: