-
Notifications
You must be signed in to change notification settings - Fork 138
/
arrayiterator.t
139 lines (109 loc) · 2.76 KB
/
arrayiterator.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!./parrot
# Copyright (C) 2001-2010, Parrot Foundation.
# $Id$
=head1 NAME
t/pmc/arrayiterator.t - ArrayIterator PMC
=head1 SYNOPSIS
% prove t/pmc/arrayiterator.t
=head1 DESCRIPTION
Tests C<ArrayIterator> PMC. Navigate in both directions, check bounds.
=cut
.namespace []
.include 'iterator.pasm'
.sub main :main
.include 'test_more.pir'
plan(21)
iterate_forward() # 8 tests
iterate_backward() # 6 tests
iterate_backward_string() # 6 test
iterator_init() # 1 test
.end
.sub 'iterate_forward'
.local pmc foo, it
foo = new ['ResizablePMCArray']
it = iter foo
nok(it, "Iterator for empty array is empty")
$I0 = isa it, 'Iterator'
ok($I0, "Have proper type")
push foo, 1
push foo, 42
it = iter foo
ok(it, "Iterator for 2-elem list is not empty")
$P0 = shift it
ok(it, "Can shift 1st element")
is($P0, 1, "With expected value")
$P0 = shift it
nok(it, "Iterator is finished after second shift")
is($P0, 42, "2nd element has correct value")
$I0 = 1
push_eh fail
$P0 = shift it
$I0 = 0
fail:
pop_eh
ok($I0, "Shifting from finished iterator throws exception")
.end
.sub 'iterate_backward'
.local pmc foo, it
foo = new ['ResizablePMCArray']
push foo, 1
push foo, 42
it = iter foo
it = .ITERATE_FROM_END
ok(it, "Iterator reset to backward iteration")
$P0 = pop it
ok(it, "Can shift 1st element")
is($P0, 42, "With expected value")
$P0 = pop it
nok(it, "Iterator is finished after second shift")
is($P0, 1, "2nd element has correct value")
$I0 = 1
push_eh fail
$P0 = shift it
$I0 = 0
fail:
pop_eh
ok($I0, "Shifting from finished iterator throws exception")
.end
.sub 'iterate_backward_string'
.local pmc foo, it
foo = new ['ResizableStringArray']
push foo, 'First'
push foo, 'Other'
it = iter foo
it = .ITERATE_FROM_END
ok(it, "Iterator reset to backward iteration - string")
$S0 = pop it
ok(it, "Can shift 1st element - string")
is($S0, 'Other', "With expected value- string")
$S0 = pop it
nok(it, "Iterator is finished after second shift - string")
is($S0, 'First', "2nd element has correct value - string")
$I0 = 1
push_eh fail
$S0 = shift it
$I0 = 0
fail:
pop_eh
ok($I0, "Shifting from finished iterator throws exception - string")
.end
.sub 'iterator_init'
.local pmc it, e
.local string msg
msg = "ArrayIterator can't be directly instantiated, init must throw"
push_eh CATCH
it = new 'ArrayIterator'
pop_eh
ok(0, msg)
goto DONE
CATCH:
.get_results(e)
pop_eh
ok(1, msg)
DONE:
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: