]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/specialized-arrays/specialized-arrays-tests.factor
use radix literals
[factor.git] / basis / specialized-arrays / specialized-arrays-tests.factor
old mode 100755 (executable)
new mode 100644 (file)
index dd561e9..ca0194d
@@ -1,43 +1,44 @@
+USING: tools.test alien.syntax specialized-arrays sequences
+alien accessors kernel arrays combinators compiler
+compiler.units classes.struct combinators.smart
+compiler.tree.debugger math libc destructors sequences.private
+multiline eval words vocabs namespaces assocs prettyprint
+alien.data math.vectors definitions compiler.test ;
+FROM: specialized-arrays.private => specialized-array-vocab ;
+FROM: alien.c-types => int float bool uchar char float ulonglong ushort uint
+heap-size ;
+FROM: alien.data => little-endian? ;
 IN: specialized-arrays.tests
-USING: tools.test alien.syntax specialized-arrays
-specialized-arrays.private sequences alien.c-types accessors
-kernel arrays combinators compiler compiler.units classes.struct
-combinators.smart compiler.tree.debugger math libc destructors
-sequences.private multiline eval words vocabs namespaces
-assocs prettyprint alien.data math.vectors definitions ;
-FROM: alien.c-types => float ;
 
 SPECIALIZED-ARRAY: int
-SPECIALIZED-ARRAYS: bool ushort char uint float ulonglong ;
+SPECIALIZED-ARRAYS: bool uchar ushort char uint float ulonglong ;
 
-[ ulonglong ] [ ulonglong-array{ } element-type ] unit-test
-
-[ t ] [ { 1 2 3 } >int-array int-array? ] unit-test
+[ t ] [ { 1 2 3 } int >c-array int-array? ] unit-test
 
 [ t ] [ int-array{ 1 2 3 } int-array? ] unit-test
 
 [ 2 ] [ int-array{ 1 2 3 } second ] unit-test
 
 [ t ] [
-    { t f t } >bool-array underlying>>
-    { 1 0 1 } "bool" heap-size {
-        { 1 [ >char-array ] }
-        { 4 [ >uint-array ] }
+    { t f t } bool >c-array underlying>>
+    { 1 0 1 } bool heap-size {
+        { 1 [ char >c-array ] }
+        { 4 [ uint >c-array ] }
     } case underlying>> =
 ] unit-test
 
 [ ushort-array{ 1234 } ] [
-    little-endian? B{ 210 4 } B{ 4 210 } ? byte-array>ushort-array
+    little-endian? B{ 210 4 } B{ 4 210 } ? ushort cast-array
 ] unit-test
 
-[ B{ 210 4 1 } byte-array>ushort-array ] must-fail
+[ B{ 210 4 1 } ushort cast-array ] must-fail
 
 [ { 3 1 3 3 7 } ] [
-    int-array{ 3 1 3 3 7 } malloc-byte-array 5 <direct-int-array> >array
+    int-array{ 3 1 3 3 7 } malloc-byte-array 5 int <c-direct-array> >array
 ] unit-test
 
-[ float-array{ HEX: 1.222,222   HEX: 1.111,112   } ]
-[ float-array{ HEX: 1.222,222,2 HEX: 1.111,111,1 } ] unit-test
+[ float-array{ 0x1.222,222   0x1.111,112   } ]
+[ float-array{ 0x1.222,222,2 0x1.111,111,1 } ] unit-test
 
 [ f ] [ float-array{ 4 3 2 1 } dup clone [ underlying>> ] bi@ eq? ] unit-test
 
@@ -74,7 +75,7 @@ SPECIALIZED-ARRAY: test-struct
 
 [ 5/4 ] [
     [
-        2 malloc-test-struct-array
+        2 \ test-struct malloc-array
         dup &free drop
         1 2 make-point over set-first
         3 4 make-point over set-second
@@ -86,7 +87,7 @@ SPECIALIZED-ARRAY: test-struct
 
 [ ] [
     [
-        10 malloc-test-struct-array
+        10 \ test-struct malloc-array
         &free drop
     ] with-destructors
 ] unit-test
@@ -101,6 +102,12 @@ SPECIALIZED-ARRAY: test-struct
     } second
 ] unit-test
 
+[ ] [
+    [
+        test-struct specialized-array-vocab forget-vocab
+    ] with-compilation-unit
+] unit-test
+
 ! Regression
 STRUCT: fixed-string { text char[64] } ;
 
@@ -115,9 +122,15 @@ SPECIALIZED-ARRAY: fixed-string
     ALIEN: 123 100 <direct-int-array> byte-length
 ] unit-test
 
+[ ] [
+    [
+        fixed-string specialized-array-vocab forget-vocab
+    ] with-compilation-unit
+] unit-test
+
 ! Test prettyprinting
 [ "int-array{ 1 2 3 }" ] [ int-array{ 1 2 3 } unparse ] unit-test
-[ "int-array@ f 100" ] [ f 100 <direct-int-array> unparse ] unit-test
+[ "c-array@ int f 100" ] [ f 100 <direct-int-array> unparse ] unit-test
 
 ! If the C type doesn't exist, don't generate a vocab
 SYMBOL: __does_not_exist__
@@ -143,7 +156,7 @@ SPECIALIZED-ARRAY: __does_not_exist__
 
 [ f ] [
     "__does_not_exist__-array{"
-    __does_not_exist__ specialized-array-vocab lookup
+    __does_not_exist__ specialized-array-vocab lookup-word
     deferred?
 ] unit-test
 
@@ -162,7 +175,7 @@ SPECIALIZED-ARRAY: struct-resize-test
 
 : struct-resize-test-usage ( seq -- seq )
     [ struct-resize-test <struct> swap >>x ] map
-    >struct-resize-test-array
+    \ struct-resize-test >c-array
     [ x>> ] { } map-as ;
     
 [ { 10 20 30 } ] [ { 10 20 30 } struct-resize-test-usage ] unit-test
@@ -172,3 +185,24 @@ SPECIALIZED-ARRAY: struct-resize-test
 [ 80 ] [ 10 <struct-resize-test-array> byte-length ] unit-test
 
 [ { 10 20 30 } ] [ { 10 20 30 } struct-resize-test-usage ] unit-test
+
+[ ] [
+    [
+        struct-resize-test specialized-array-vocab forget-vocab
+        \ struct-resize-test-usage forget
+    ] with-compilation-unit
+] unit-test
+
+[ int-array{ 4 5 6 } ] [ 3 6 int-array{ 1 2 3 4 5 6 7 8 } direct-slice ] unit-test
+[ int-array{ 1 2 3 } ] [ int-array{ 1 2 3 4 5 6 7 8 } 3 direct-head ] unit-test
+[ int-array{ 1 2 3 4 5 } ] [ int-array{ 1 2 3 4 5 6 7 8 } 3 direct-head* ] unit-test
+[ int-array{ 4 5 6 7 8 } ] [ int-array{ 1 2 3 4 5 6 7 8 } 3 direct-tail ] unit-test
+[ int-array{ 6 7 8 } ] [ int-array{ 1 2 3 4 5 6 7 8 } 3 direct-tail* ] unit-test
+
+[ uchar-array{ 0 1 255 } ] [ 3 6 B{ 1 1 1 0 1 255 2 2 2 } direct-slice ] unit-test
+
+[ int-array{ 1 2 3 4 55555 6 7 8 } ] [
+    int-array{ 1 2 3 4 5 6 7 8 }
+    3 6 pick direct-slice [ 55555 1 ] dip set-nth
+] unit-test
+