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

bacek at svn.parrot.org bacek at svn.parrot.org
Thu May 6 14:20:15 UTC 2010


Author: bacek
Date: Thu May  6 14:20:15 2010
New Revision: 46357
URL: https://trac.parrot.org/parrot/changeset/46357

Log:
Implement StringBuilder.set_string_native

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

Modified: trunk/src/pmc/stringbuilder.pmc
==============================================================================
--- trunk/src/pmc/stringbuilder.pmc	Thu May  6 14:19:50 2010	(r46356)
+++ trunk/src/pmc/stringbuilder.pmc	Thu May  6 14:20:15 2010	(r46357)
@@ -184,6 +184,19 @@
         SELF.push_string(VTABLE_get_string(INTERP, p));
     }
 
+/*
+
+=item C<VTABLE set_string_native()>
+
+Set content of buffer to passed string
+
+=cut
+
+*/
+    VTABLE void set_string_native(STRING *s) {
+        SET_ATTR_buffer(INTERP, SELF, Parrot_str_clone(INTERP, s));
+    }
+
 
 /*
 

Modified: trunk/t/pmc/stringbuilder.t
==============================================================================
--- trunk/t/pmc/stringbuilder.t	Thu May  6 14:19:50 2010	(r46356)
+++ trunk/t/pmc/stringbuilder.t	Thu May  6 14:20:15 2010	(r46357)
@@ -20,11 +20,12 @@
 .sub 'main' :main
     .include 'test_more.pir'
 
-    plan(14)
+    plan(17)
     test_create()               # 2 tests
     test_push_string()          # 9 tests
     test_push_string_unicode()  # 1 test
     test_i_concatenate()        # 1 test
+    test_set_string_native()    # 3 tests
 
     # END_OF_TESTS
 .end
@@ -121,6 +122,23 @@
 
 .end
 
+.sub 'test_set_string_native'
+    .local pmc sb
+    sb = new ["StringBuilder"]
+
+    $S99 = "foo"
+    sb   = $S99
+
+    $S0  = sb
+    is( $S0, "foo", "Assignment works")
+
+    sb .= "bar"
+    $S0  = sb
+    is( $S0, "foobar", "... with appending string after")
+    is( $S99, "foo", "... without touching of original string")
+
+.end
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100


More information about the parrot-commits mailing list