[svn:parrot] r40112 - in trunk: src/pmc t/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Thu Jul 16 10:23:49 UTC 2009
Author: bacek
Date: Thu Jul 16 10:23:47 2009
New Revision: 40112
URL: https://trac.parrot.org/parrot/changeset/40112
Log:
[cage][t] Add tests for ArrayIterator.
Also inherit ArrayIterator from Iterator.
Added:
trunk/t/pmc/arrayiterator.t
Modified:
trunk/src/pmc/arrayiterator.pmc
Modified: trunk/src/pmc/arrayiterator.pmc
==============================================================================
--- trunk/src/pmc/arrayiterator.pmc Wed Jul 15 22:14:37 2009 (r40111)
+++ trunk/src/pmc/arrayiterator.pmc Thu Jul 16 10:23:47 2009 (r40112)
@@ -51,7 +51,7 @@
*/
-pmclass ArrayIterator no_ro {
+pmclass ArrayIterator extends Iterator no_ro {
ATTR PMC *array; /* the array which this Iterator iterates */
ATTR INTVAL pos; /* Current position of iterator for forward iterator */
/* Previous position of iterator for reverse iterator */
Added: trunk/t/pmc/arrayiterator.t
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/t/pmc/arrayiterator.t Thu Jul 16 10:23:47 2009 (r40112)
@@ -0,0 +1,94 @@
+#! parrot
+# Copyright (C) 2001-2009, Parrot Foundation.
+# $Id$
+
+=head1 NAME
+
+t/pmc/arrayiterator.t - ArrayIterator PMC
+
+=head1 SYNOPSIS
+
+ % prove t/pmc/array.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(14)
+
+ iterate_forward() # 8 tests
+ iterate_backward() # 5 tests
+.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:
+ 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:
+ ok($I0, "Shifting from finished iterator throws exception")
+.end
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
More information about the parrot-commits
mailing list