2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/pmc/stringiterator.t - StringIterator.
11 % prove t/pmc/stringiterator.t
15 Tests the C<StringIterator> PMC. Iterate over string in both directions.
19 .include 'iterator.pasm'
20 .include 'except_types.pasm'
23 .include 'test_more.pir'
30 iterate_forward() # 11 tests
31 iterate_backward() # 8 tests
32 iterate_wrong() # 1 test
33 iterate_out() # 1 test
40 .local pmc s, it, sget
45 is(s, sget, 'deref StringIterator gives the iterated string')
55 # Get a clone and make sure both the original and the clone
62 is(nit, nitc, "clone has same length as original")
76 is(ns, nit, "iter elements is equal to string length")
78 is(ns, nit, "iter get_integer is equal to string length")
81 .sub 'iterate_forward'
87 nok(it, "Iterator for empty string is empty")
88 $I0 = isa it, 'Iterator'
89 ok($I0, "Have proper type")
95 ok(it, "Iterator for 'bar' is not empty")
97 ok(it, "Can shift 1st character")
98 is($S0, 'b', "With correct value")
101 is($S0, 'a', "can get string keyed int correct value")
104 ok(it, "Can shift 2nd character")
105 is($S0, 'a', "With correct value")
108 nok(it, "Iterator is finished after 3rd shift")
109 is($P0, 'r', "3rd character has correct value as PMC")
117 ok($I0, "Shifting from finished iterator throws exception")
121 .sub 'iterate_backward'
128 it = .ITERATE_FROM_END
129 ok(it, "Iterator reset to backward iteration")
132 ok(it, "Can shift 1st character")
133 is($S0, 'Z', "With expected value")
136 ok(it, "Can shift 2nd character")
137 is($S0, 'A', "With expected value")
140 nok(it, "Iterator is finished after third shift")
141 is($P0, 'B', "3rd element has correct value as PMC")
149 ok($I0, "Shifting from finished iterator throws exception")
161 it = 42 # Let's hope we'll never have such direction
170 ok(r, "Caught wrong direction")
173 # out of bounds conditions not covered by previous tests
182 eh = new ['ExceptionHandler']
217 ok(1, "Caught out of bounds iterations")
220 ok(0, "Out of bounds iteration should throw")
227 .local int result, i1
233 is(s1, 'h', 'get_string_keyed_int - zero')
235 is(s1, 'i', 'get_string_keyed_int - not zero')
237 eh = new ['ExceptionHandler']
238 eh.'handle_types'(.EXCEPTION_OUT_OF_BOUNDS)
247 ok(result, 'get_string_keyed_int out of bounds')
252 is(s1, 'h', 'get_integer_keyed_int')
261 ok(result, 'get_integer_keyed_int out of bounds')
268 # vim: expandtab shiftwidth=4 ft=pir: