2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/pmc/arrayiterator.t - ArrayIterator PMC
11 % prove t/pmc/arrayiterator.t
15 Tests C<ArrayIterator> PMC. Navigate in both directions, check bounds.
21 .include 'iterator.pasm'
22 .include 'except_types.pasm'
25 .include 'test_more.pir'
29 iterate_forward() # 8 tests
30 iterate_backward() # 6 tests
31 iterate_backward_string() # 6 test
32 iterate_wrong() # 1 test
33 iterator_init() # 1 test
37 .sub 'iterate_forward'
40 foo = new ['ResizablePMCArray']
43 nok(it, "Iterator for empty array is empty")
44 $I0 = isa it, 'Iterator'
45 ok($I0, "Have proper type")
51 ok(it, "Iterator for 2-elem list is not empty")
53 ok(it, "Can shift 1st element")
54 is($P0, 1, "With expected value")
56 $P1 = new ['Integer'], 0
58 is($I0, 1, "exists_keyed gives expected value")
61 is($I0, 1, "defined_keyed gives expected value")
64 is($P2, 42, "get_pmc_keyed gives expected value")
67 is($I0, 42, "get_integer_keyed gives expected value")
70 is($N0, 42.0, "get_number_keyed gives expected value")
73 is($S0, '42', "get_string_keyed gives expected value")
76 nok(it, "Iterator is finished after second shift")
77 is($P0, 42, "2nd element has correct value")
82 ehandler = new ['ExceptionHandler']
83 ehandler.'handle_types'(.EXCEPTION_OUT_OF_BOUNDS)
86 set_addr ehandler, handlep
91 set_addr ehandler, handlei
96 set_addr ehandler, handlen
101 set_addr ehandler, handles
110 ok(result, "Shifting from finished iterator throws out of bounds exception")
114 .sub 'iterate_backward'
117 foo = new ['ResizablePMCArray']
122 it = .ITERATE_FROM_END
123 ok(it, "Iterator reset to backward iteration")
125 ok(it, "Can shift 1st element")
126 is($P0, 42, "With expected value")
128 nok(it, "Iterator is finished after second shift")
129 is($P0, 1, "2nd element has correct value")
134 ehandler = new ['ExceptionHandler']
135 ehandler.'handle_types'(.EXCEPTION_OUT_OF_BOUNDS)
138 set_addr ehandler, handlep
143 set_addr ehandler, handlei
148 set_addr ehandler, handlen
153 set_addr ehandler, handles
162 ok(result, "pop from finished iterator throws out of bounds exception")
166 .sub 'iterate_backward_string'
169 foo = new ['ResizableStringArray']
174 it = .ITERATE_FROM_END
175 ok(it, "Iterator reset to backward iteration - string")
177 ok(it, "Can shift 1st element - string")
178 is($S0, 'Other', "With expected value- string")
180 nok(it, "Iterator is finished after second shift - string")
181 is($S0, 'First', "2nd element has correct value - string")
189 ok($I0, "Shifting from finished iterator throws exception - string")
193 .local pmc foo, it, ex
196 foo = new ['FixedIntegerArray'], 1
200 it = 42 # Let's hope we'll never have such direction
209 ok(r, "Caught wrong direction")
215 msg = "ArrayIterator can't be directly instantiated, init must throw"
217 it = new 'ArrayIterator'
232 # vim: expandtab shiftwidth=4 ft=pir: