2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/pmc/fixedbooleanarray.t - FixedBooleanArray PMC
11 % prove t/pmc/fixedbooleanarray.t
15 Tests C<FixedBooleanArray> PMC. Checks size, sets various elements, including
16 out-of-bounds test. Checks INT and PMC keys.
21 .include 'test_more.pir'
26 resizing_not_allowed()
27 setting_first_element()
28 setting_second_element()
29 setting_out_of_bounds()
30 getting_out_of_bounds()
41 test_invalid_init_tt1509()
44 .sub 'setting_array_size'
45 $P0 = new ['FixedBooleanArray']
47 is($I0, 0, 'size is initially zero')
51 is($I0, 1, 'size set to 1')
54 .sub 'resizing_not_allowed'
55 $P0 = new ['FixedBooleanArray']
57 push_eh resizing_not_allowed_handler
60 nok(1, 'resizing should not have succeeded')
64 resizing_not_allowed_handler:
66 ok(1, 'resizing does not work on a fixed-size array')
69 .sub 'setting_first_element'
70 $P0 = new ['FixedBooleanArray']
75 is($I0, 1, 'setting first element to a true int value')
79 is($N0, 1.0, 'setting first element to a true num value')
83 is($S0, "1", 'setting first element to a true string value')
86 .sub 'setting_second_element'
87 $P0 = new ['FixedBooleanArray']
92 is($I0, 1, 'setting second element to a true int value')
96 is($N0, 1.0, 'setting second element to a true num value')
100 is($S0, "1", 'setting second element to a true string value')
103 .sub 'setting_out_of_bounds'
104 $P0 = new ['FixedBooleanArray']
107 push_eh setting_out_of_bounds_handler
110 nok(1, "Setting out-of-bounds element wrongly succeeded")
113 setting_out_of_bounds_handler:
115 ok(1, "Setting out-of-bounds element did not succeed")
118 .sub 'getting_out_of_bounds'
119 $P0 = new ['FixedBooleanArray']
122 push_eh getting_out_of_bounds_handler
125 nok(1, "Getting out-of-bounds element wrongly succeeded")
128 getting_out_of_bounds_handler:
130 ok(1, "Getting out-of-bounds element does not succeed")
133 .sub 'set_pmc_access_int'
134 $P0 = new ['FixedBooleanArray']
148 is($I0, 1, "Set via PMC keys, access via INTs: int value")
151 is($N0, 1.0, "Set via PMC keys, access via INTs: num value")
154 is($S0, "1", "Set via PMC keys, access via INTs: string value")
157 .sub 'set_int_access_pmc'
158 $P0 = new ['FixedBooleanArray']
164 $P1 = new ['Integer']
172 is($I0, 1, 'Set via INTs, access via PMC Keys: int value')
176 is($N0, 1.0, 'Set via INTs, access via PMC Keys: num value')
180 is($S0, '1', 'Set via INTs, access via PMC Keys: string value')
184 is($P3, 1, 'Set via INTs, access via PMC Keys: PMC value')
188 $P0 = new ['FixedBooleanArray']
190 $I0 = does $P0, 'scalar'
191 nok($I0, 'FixedBooleanArray does not scalar')
192 $I0 = does $P0, 'array'
193 ok($I0, 'FixedBooleanArray does array')
194 $I0 = does $P0, 'no_interface'
195 nok($I0, 'FixedBooleanArray does not no_interface')
199 $P0 = new ['FixedBooleanArray']
201 nok($P0, 'Empty FixedBooleanArray is false')
204 ok($P0, 'Non-empty FixedBooleanArray is true')
207 ok($P0, 'FixedBooleanArray is true, no matter what its values are')
210 .sub 'pmc_keys_and_values'
211 $P0 = new ['FixedBooleanArray']
216 $P2 = new ['Integer']
221 is($I0, 1, 'PMC keys & values')
229 fba = new ['FixedBooleanArray']
239 is($S0, '01001000100010010', 'FixedBooleanArray before freeze')
244 is($S0, '01001000100010010', 'FixedBooleanArray after thaw')
248 .local pmc fba1, fba2
252 fba1 = new ['FixedBooleanArray']
262 is($S0, '01001000100010010', 'FixedBooleanArray before clone')
265 is($S0, $S1, "clones have the same string representation")
269 $P0 = new ['FixedBooleanArray']
277 is($I2, 1, 'get_iter: first element')
279 is($I2, 0, 'get_iter: second element')
281 is($I2, 1, 'get_iter: third element')
283 nok($P1, 'iterator exhausted')
287 $P0 = new ['FixedBooleanArray']
289 ok(1, 'Filling empty array')
291 .local int result, i, size
295 # Fresh array is empty.
299 unless i < size goto initial_false_end
301 result = or result, $I0
303 goto initial_false_loop
305 nok(result, "Fresh array filled with 0")
312 unless i < size goto fill_true_end
314 result = and result, $I0
318 ok(result, "Fill with 1")
325 unless i < size goto fill_false_end
327 result = or result, $I0
331 nok(result, "Fill with 0")
335 .sub test_new_style_init
336 $P0 = new 'FixedBooleanArray', 10
339 is($I0, 10, "New style init creates the correct # of elements")
341 $P0 = new ['FixedBooleanArray'], 10
344 is($I0, 10, "New style init creates the correct # of elements for a key constant")
347 .sub test_invalid_init_tt1509
348 throws_substring(<<'CODE', 'FixedBooleanArray: Cannot set array size to a negative number (-10)', 'New style init does not dump core for negative array lengths')
350 $P0 = new ['FixedBooleanArray'], -10
354 throws_substring(<<'CODE', 'FixedBooleanArray: Cannot set array size to a negative number (-10)', 'New style init (key constant) does not dump core for negative array lengths')
356 $P0 = new 'FixedBooleanArray', -10
365 # vim: expandtab shiftwidth=4 ft=pir: