2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/pmc/fixedstringarray.t - FixedStringArray PMC
11 % prove t/pmc/fixedstringarray.t
15 Tests C<FixedStringArray> PMC. Checks size, sets various elements, including
16 out-of-bounds test. Checks INT and PMC keys.
21 .include 'test_more.pir'
33 test_clone_unitialized()
42 test_invalid_init_tt1509()
46 $P0 = new ['FixedStringArray']
49 is($I0, 0, "Fresh array has 0 elements")
53 is($I0, 42, "Size was set correctly")
56 .sub 'test_reset_size'
57 $P0 = new ['FixedStringArray']
67 ok($I0, "Can't resize")
72 $P0 = new ['FixedStringArray']
77 is($I0, -7, "First element set to integer properly")
81 is($N0, 3.7, "First element set to number properly")
85 is($S0, "muwhahaha", "First element set to string properly")
89 .sub 'test_set_second'
90 $P0 = new ['FixedStringArray']
95 is($I0, -7, "Second element set to integer properly")
99 is($I0, 3, "Second element set to number properly")
103 is($S0, "purple", "Second element set to string properly")
106 .sub 'test_out_of_bounds'
107 $P0 = new ['FixedStringArray']
115 ok($I0, "Can't set out-of-bounds element")
119 push_eh handle_set_negative
123 ok($I0, "Can't set element on negative index")
131 ok($I0, "Can't get out-of-bounds element")
135 push_eh handle_get_negative
139 ok($I0, "Can't get element with negative index")
145 # Set via PMC keys, access via INTs
146 .sub 'test_set_via_pmc'
147 $P0 = new ['FixedStringArray']
155 is($S0, "25", "Set INTVAL via PMC Key works")
160 is($S0, "2.5", "Set FLOATVAL via PMC Key works")
165 is($S0, "bleep", "Set STRING via PMC Key works")
168 # Set via INTs, access via PMC Keys
169 .sub 'test_get_via_pmc'
170 $P0 = new ['FixedStringArray']
177 $P1 = new ['Integer']
185 is($I0, 125, "Get INTVAL via Key works")
189 is($N0, 10.2, "Get FLOATVAL via Key works")
193 is($S0, "blah", "Get STRING via Key works")
197 is($I0, 123456, "Get INTVAL for stored PMC via Key works")
202 .sub 'test_interface_done'
204 pmc1 = new ['FixedStringArray']
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")
216 new $P0, ['FixedStringArray']
226 is($S0, "abcde", "First element cloned")
228 is($S0, "fghi", "Second element cloned")
230 is($S0, "jkl", "Third element cloned")
233 .sub 'test_clone_unitialized'
234 $P0 = new ['FixedStringArray']
244 ok($I0, "Resize of uninitialized clone successful")
252 ok($I0, "Resize of initialization not successful")
258 $P0 = new ['FixedStringArray']
259 nok($P0, "Empty array is false")
261 ok($P0, "Non-empty array is true")
265 $P0 = new ['FixedStringArray']
273 if $I0 < 8192 goto loop
276 is($S0, "1000", "1000th element survived")
278 is($S0, "2000", "2000th element survived")
280 is($S0, "4000", "4000th element survived")
282 is($S0, "8000", "8000th element survived")
286 $P0 = new ['FixedStringArray']
294 unless $P1 goto loop_end
299 is($S0, "foobarbaz", "Iteration works")
302 .sub 'test_freez_thaw'
306 new fsa, ['FixedStringArray']
320 unless it goto loop_end
325 is($S0, "42434499101", "get_iter works")
328 .sub 'test_get_string'
329 $P0 = new ['FixedStringArray']
332 is($P0, '[ "foo", "" ]', "Array stringified properly")
336 .local pmc a1, a2, other
339 a1 = new ['FixedStringArray']
340 a2 = new ['FixedStringArray']
341 other = new ['Integer']
343 is(a1, a2, "Empty arrays are equal")
346 is(i, 0, "Not equal to other type")
349 isnt(a1, a2, "Different size arrays aren't equal")
355 is(a1, a2, "Equal with first element set")
359 isnt(a1, a2, "Not equal when second element differ")
362 is(a1, a2, "Equal when second element same")
366 isnt(a1, a2, "Not equal when second element is null")
372 fsa = new ['FixedStringArray']
376 is($I0, 3, "get_integer returns correct size")
378 is($N0, 3.0, "get_number returns correct size")
381 .sub 'test_new_style_init'
382 $P0 = new 'FixedStringArray', 10
385 is($I0, 10, "New style init creates the correct # of elements")
387 $P0 = new ['FixedStringArray'], 10
390 is($I0, 10, "New style init creates the correct # of elements for a key constant")
393 .sub test_invalid_init_tt1509
394 throws_substring(<<'CODE', 'FixedStringArray: Cannot set array size to a negative number (-10)', 'New style init does not dump core for negative array lengths')
396 $P0 = new ['FixedStringArray'], -10
400 throws_substring(<<'CODE', 'FixedStringArray: Cannot set array size to a negative number (-10)', 'New style init (key constant) does not dump core for negative array lengths')
402 $P0 = new 'FixedStringArray', -10
411 # vim: expandtab shiftwidth=4 ft=pir: