]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/io/buffers/buffers-tests.factor
Slices over specialized arrays can now be passed to C functions, written to binary...
[factor.git] / basis / io / buffers / buffers-tests.factor
index 93d2f5b2fc60ce3a1107c4b97918f9296a7660b4..07e783f26743be087ae58d9fe6bae02ae1d5fd59 100644 (file)
@@ -4,8 +4,9 @@ kernel.private libc sequences tools.test namespaces byte-arrays
 strings accessors destructors ;
 
 : buffer-set ( string buffer -- )
-    over >byte-array over ptr>> byte-array>memory
-    [ length ] dip buffer-reset ;
+    [ ptr>> swap >byte-array binary-object memcpy ]
+    [ [ length ] dip buffer-reset ]
+    2bi ;
 
 : string>buffer ( string -- buffer )
     dup length <buffer> [ buffer-set ] keep ;
@@ -58,3 +59,7 @@ strings accessors destructors ;
 100 <buffer> "b" set
 [ 1000 "b" get n>buffer >string ] must-fail
 "b" get dispose
+
+"hello world" string>buffer "b" set
+[ "hello" CHAR: \s ] [ " " "b" get buffer-until [ >string ] dip ] unit-test
+"b" get dispose