[cage] Fix pgegrep, which was merely an innocent bystander in the Great Namespace...
[parrot.git] / t / pmc / arrayiterator.t
blob925e65a3d20fd7563589696f73c19a93505ed357
1 #! parrot
2 # Copyright (C) 2001-2009, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 t/pmc/arrayiterator.t - ArrayIterator PMC
9 =head1 SYNOPSIS
11     % prove t/pmc/arrayiterator.t
13 =head1 DESCRIPTION
15 Tests C<ArrayIterator> PMC. Navigate in both directions, check bounds.
17 =cut
19 .namespace []
21 .include 'iterator.pasm'
23 .sub main :main
24     .include 'test_more.pir'
26     plan(21)
28     iterate_forward() # 8 tests
29     iterate_backward() # 6 tests
30     iterate_backward_string() # 6 test
31     iterator_init() # 1 test
32 .end
35 .sub 'iterate_forward'
36     .local pmc foo, it
38     foo = new ['ResizablePMCArray']
40     it = iter foo
41     nok(it, "Iterator for empty array is empty")
42     $I0 = isa it, 'Iterator'
43     ok($I0, "Have proper type")
45     push foo, 1
46     push foo, 42
48     it = iter foo
49     ok(it, "Iterator for 2-elem list is not empty")
50     $P0 = shift it
51     ok(it, "Can shift 1st element")
52     is($P0, 1, "With expected value")
53     $P0 = shift it
54     nok(it, "Iterator is finished after second shift")
55     is($P0, 42, "2nd element has correct value")
57     $I0 = 1
58     push_eh fail
59     $P0 = shift it
60     $I0 = 0
61   fail:
62     pop_eh
63     ok($I0, "Shifting from finished iterator throws exception")
65 .end
67 .sub 'iterate_backward'
68     .local pmc foo, it
70     foo = new ['ResizablePMCArray']
71     push foo, 1
72     push foo, 42
74     it = iter foo
75     it = .ITERATE_FROM_END
76     ok(it, "Iterator reset to backward iteration")
77     $P0 = pop it
78     ok(it, "Can shift 1st element")
79     is($P0, 42, "With expected value")
80     $P0 = pop it
81     nok(it, "Iterator is finished after second shift")
82     is($P0, 1, "2nd element has correct value")
84     $I0 = 1
85     push_eh fail
86     $P0 = shift it
87     $I0 = 0
88   fail:
89     pop_eh
90     ok($I0, "Shifting from finished iterator throws exception")
91 .end
93 .sub 'iterate_backward_string'
94     .local pmc foo, it
96     foo = new ['ResizableStringArray']
97     push foo, 'First'
98     push foo, 'Other'
100     it = iter foo
101     it = .ITERATE_FROM_END
102     ok(it, "Iterator reset to backward iteration - string")
103     $S0 = pop it
104     ok(it, "Can shift 1st element - string")
105     is($S0, 'Other', "With expected value- string")
106     $S0 = pop it
107     nok(it, "Iterator is finished after second shift - string")
108     is($S0, 'First', "2nd element has correct value - string")
110     $I0 = 1
111     push_eh fail
112     $S0 = shift it
113     $I0 = 0
114   fail:
115     pop_eh
116     ok($I0, "Shifting from finished iterator throws exception - string")
117 .end
119 .sub 'iterator_init'
120     .local pmc it, e
121     .local string msg
122     msg = "ArrayIterator can't be directly instantiated, init must throw"
123     push_eh CATCH
124     it = new 'ArrayIterator'
125     pop_eh
126     ok(0, msg)
127     goto DONE
128 CATCH:
129     .get_results(e)
130     pop_eh
131     ok(1, msg)
132 DONE:
133 .end
136 # Local Variables:
137 #   mode: cperl
138 #   cperl-indent-level: 4
139 #   fill-column: 100
140 # End:
141 # vim: expandtab shiftwidth=4: