[svn:parrot] r47648 - in trunk: src/pmc t/pmc

NotFound at svn.parrot.org NotFound at svn.parrot.org
Tue Jun 15 22:41:14 UTC 2010


Author: NotFound
Date: Tue Jun 15 22:41:13 2010
New Revision: 47648
URL: https://trac.parrot.org/parrot/changeset/47648

Log:
ByteBuffer push_integer vtable and its tests

Modified:
   trunk/src/pmc/bytebuffer.pmc
   trunk/t/pmc/bytebuffer.t

Modified: trunk/src/pmc/bytebuffer.pmc
==============================================================================
--- trunk/src/pmc/bytebuffer.pmc	Tue Jun 15 21:36:22 2010	(r47647)
+++ trunk/src/pmc/bytebuffer.pmc	Tue Jun 15 22:41:13 2010	(r47648)
@@ -160,7 +160,8 @@
 
 =item C<void set_integer_keyed_int()>
 
-Set the value of the byte at position.
+Set the value of the byte at position, resizing the buffer if the position
+is out of current size.
 
 =cut
 
@@ -211,6 +212,23 @@
 
 /*
 
+=item C<void push_integer(INTVAL value)>
+
+Extends the buffer by adding a byte of value C<value> to the end.
+
+=cut
+
+*/
+
+    VTABLE void push_integer(INTVAL value) {
+        INTVAL size;
+
+        GET_ATTR_size(INTERP, SELF, size);
+        STATICSELF.set_integer_keyed_int(size, value);
+    }
+
+/*
+
 =item C<PMC *get_iter()>
 
 Return a new Iterator for this PMC.

Modified: trunk/t/pmc/bytebuffer.t
==============================================================================
--- trunk/t/pmc/bytebuffer.t	Tue Jun 15 21:36:22 2010	(r47647)
+++ trunk/t/pmc/bytebuffer.t	Tue Jun 15 22:41:13 2010	(r47648)
@@ -21,12 +21,13 @@
 
 .sub 'main' :main
     .include 'test_more.pir'
-    plan(24)
+    plan(26)
 
     test_init()
     test_set_string()
     test_set_byte()
     test_get_string()
+    test_push()
     test_alloc()
     test_iterate()
     test_invalid()
@@ -177,6 +178,22 @@
 end:
 .end
 
+.sub test_push
+    .local pmc bb
+    .local int c, n, m
+    bb = new ['ByteBuffer']
+    bb = 'hell'
+    n = elements bb
+    inc n
+    c = ord 'o'
+    push bb, c
+    m = elements bb
+    is(n, m, "push increments size")
+    .local string s
+    s = bb.'get_string_as'(ascii:"")
+    is(s, 'hello', "push gives expected string result")
+.end
+
 .sub test_alloc
     # Exercise buffer reallocation building a utf16 string with the
     # codepoints 32-8192


More information about the parrot-commits mailing list