cvsuser 05/01/03 14:13:53
Modified: classes resizablestringarray.pmc
t/pmc resizablestringarray.t
Log:
Implement and test pop_string
Revision Changes Path
1.8 +30 -1 parrot/classes/resizablestringarray.pmc
Index: resizablestringarray.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/resizablestringarray.pmc,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- resizablestringarray.pmc 29 Dec 2004 23:38:29 -0000 1.7
+++ resizablestringarray.pmc 3 Jan 2005 22:13:50 -0000 1.8
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: resizablestringarray.pmc,v 1.7 2004/12/29 23:38:29 scog Exp $
+$Id: resizablestringarray.pmc,v 1.8 2005/01/03 22:13:50 scog Exp $
=head1 NAME
@@ -92,6 +92,35 @@
/*
+=item C<STRING* pop_string()>
+
+Removes and returns the last element in the array.
+
+=cut
+
+*/
+
+ STRING* pop_string() {
+ INTVAL size;
+ STRING* value;
+ SizeStringData *sd;
+
+ size = PMC_int_val(SELF);
+ sd = (SizeStringData *)PMC_data(SELF);
+
+ if (sd == NULL || size == 0) {
+ internal_exception(OUT_OF_BOUNDS,
+ "ResizableStringArray: Can't pop from an empty array!");
+ }
+
+ value = sd->data[size - 1];
+ DYNSELF.set_integer_native(size - 1);
+
+ return value;
+ }
+
+/*
+
=item C<void set_integer_native(INTVAL size)>
Resizes the array to C<size> elements.
1.8 +77 -2 parrot/t/pmc/resizablestringarray.t
Index: resizablestringarray.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/resizablestringarray.t,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- resizablestringarray.t 29 Dec 2004 23:38:09 -0000 1.7
+++ resizablestringarray.t 3 Jan 2005 22:13:52 -0000 1.8
@@ -1,6 +1,6 @@
#! perl -w
# Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-# $Id: resizablestringarray.t,v 1.7 2004/12/29 23:38:09 scog Exp $
+# $Id: resizablestringarray.t,v 1.8 2005/01/03 22:13:52 scog Exp $
=head1 NAME
@@ -17,7 +17,7 @@
=cut
-use Parrot::Test tests => 12;
+use Parrot::Test tests => 16;
use Test::More;
my $fp_equality_macro = <<'ENDOFMACRO';
@@ -315,6 +315,81 @@
two zero one zero
OUTPUT
+output_is(<<'CODE', <<'OUTPUT', 'basic pop');
+ new P0, .ResizableStringArray
+ set P0[0], "foo"
+ set P0[1], "bar"
+ set P0[2], "bax"
+ pop S0, P0
+ eq S0, "bax", OK1
+ print "not "
+OK1: print "ok 1\n"
+
+ pop S0, P0
+ eq S0, "bar", OK2
+ print "not "
+OK2: print "ok 2\n"
+
+ pop S0, P0
+ eq S0, "foo", OK3
+ print "not "
+OK3: print "ok 3\n"
+ end
+CODE
+ok 1
+ok 2
+ok 3
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', 'pop many values');
+ new P0, .ResizableStringArray
+ set I0, 0
+L1: set S0, I0
+ set P0[I0], S0
+ inc I0
+ lt I0, 100000, L1
+
+L2: dec I0
+ set S1, I0
+ pop S0, P0
+ eq S0, S1, OK
+ branch NOT_OK
+OK: gt I0, 0, L2
+ print "ok\n"
+ end
+
+NOT_OK:
+ print S0
+ print "\n"
+ print S1
+ print "\n"
+ end
+CODE
+ok
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', 'push/pop');
+ new P0, .ResizableStringArray
+ push P0, "abcde"
+ push P0, "bcdea"
+ push P0, "cdeab"
+ pop S0, P0
+ eq S0, "cdeab", OK1
+ print "not "
+OK1: print "ok 1\n"
+ end
+CODE
+ok 1
+OUTPUT
+
+output_like(<<'CODE', <<'OUTPUT', 'pop from empty array');
+ new P0, .ResizableStringArray
+ pop S0, P0
+ end
+CODE
+/ResizableStringArray: Can't pop from an empty array!/
+OUTPUT
+
output_is(<< 'CODE', << 'OUTPUT', "clone");
new P0, .ResizableStringArray
set P0, 1024