2 # Copyright (C) 2001-2009, 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'
24 .include 'test_more.pir'
28 iterate_forward() # 8 tests
29 iterate_backward() # 6 tests
30 iterate_backward_string() # 6 test
31 iterator_init() # 1 test
35 .sub 'iterate_forward'
38 foo = new ['ResizablePMCArray']
41 nok(it, "Iterator for empty array is empty")
42 $I0 = isa it, 'Iterator'
43 ok($I0, "Have proper type")
49 ok(it, "Iterator for 2-elem list is not empty")
51 ok(it, "Can shift 1st element")
52 is($P0, 1, "With expected value")
54 nok(it, "Iterator is finished after second shift")
55 is($P0, 42, "2nd element has correct value")
63 ok($I0, "Shifting from finished iterator throws exception")
67 .sub 'iterate_backward'
70 foo = new ['ResizablePMCArray']
75 it = .ITERATE_FROM_END
76 ok(it, "Iterator reset to backward iteration")
78 ok(it, "Can shift 1st element")
79 is($P0, 42, "With expected value")
81 nok(it, "Iterator is finished after second shift")
82 is($P0, 1, "2nd element has correct value")
90 ok($I0, "Shifting from finished iterator throws exception")
93 .sub 'iterate_backward_string'
96 foo = new ['ResizableStringArray']
101 it = .ITERATE_FROM_END
102 ok(it, "Iterator reset to backward iteration - string")
104 ok(it, "Can shift 1st element - string")
105 is($S0, 'Other', "With expected value- string")
107 nok(it, "Iterator is finished after second shift - string")
108 is($S0, 'First', "2nd element has correct value - string")
116 ok($I0, "Shifting from finished iterator throws exception - string")
122 msg = "ArrayIterator can't be directly instantiated, init must throw"
124 it = new 'ArrayIterator'
138 # cperl-indent-level: 4
141 # vim: expandtab shiftwidth=4: