]> gitweb.factorcode.org Git - factor.git/blobdiff - core/io/files/files-tests.factor
Slices over specialized arrays can now be passed to C functions, written to binary...
[factor.git] / core / io / files / files-tests.factor
index cf58dbfe05585a5823cf367c90af71840974c7a3..5db1822d9e5152942d7499654e3822c11a8fd974 100644 (file)
@@ -1,8 +1,9 @@
-USING: arrays debugger.threads destructors io io.directories
-io.encodings.ascii io.encodings.binary io.encodings.string
-io.encodings.8-bit.latin1 io.files io.files.private
-io.files.temp io.files.unique kernel make math sequences system
-threads tools.test generic.single specialized-arrays alien.c-types ;
+USING: alien alien.c-types arrays classes.struct
+debugger.threads destructors generic.single io io.directories
+io.encodings.8-bit.latin1 io.encodings.ascii
+io.encodings.binary io.encodings.string io.files
+io.files.private io.files.temp io.files.unique kernel make math
+sequences specialized-arrays system threads tools.test ;
 SPECIALIZED-ARRAY: int
 IN: io.files.tests
 
@@ -80,6 +81,44 @@ IN: io.files.tests
     byte-array>int-array
 ] unit-test
 
+[ ] [
+    BV{ 0 1 2 } "test.txt" temp-file binary set-file-contents
+] unit-test
+
+[ t ] [
+    "test.txt" temp-file binary file-contents
+    B{ 0 1 2 } =
+] unit-test
+
+STRUCT: pt { x uint } { y uint } ;
+SPECIALIZED-ARRAY: pt
+
+CONSTANT: pt-array-1
+    pt-array{ S{ pt f 1 1 } S{ pt f 2 2 } S{ pt f 3 3 } }
+
+[ ] [
+    pt-array-1
+    "test.txt" temp-file binary set-file-contents
+] unit-test
+
+[ t ] [
+    "test.txt" temp-file binary file-contents
+    pt-array-1 >c-ptr sequence=
+] unit-test
+
+! Slices should support >c-ptr and byte-length
+
+[ ] [
+    pt-array-1 rest-slice
+    "test.txt" temp-file binary set-file-contents
+] unit-test
+
+[ t ] [
+    "test.txt" temp-file binary file-contents
+    byte-array>pt-array
+    pt-array-1 rest-slice sequence=
+] unit-test
+
 ! Writing strings to binary streams should fail
 [
     "test.txt" temp-file binary [