1 USING: tuple-arrays sequences tools.test namespaces kernel
2 math accessors classes.tuple eval classes.struct ;
10 [ 2 ] [ 2 <foo-array> dup mat set length ] unit-test
11 [ T{ foo } ] [ mat get first ] unit-test
12 [ T{ foo f 2 } ] [ T{ foo f 2 } 0 mat get [ set-nth ] keep first ] unit-test
13 [ t ] [ { T{ foo f 1 } T{ foo f 2 } } >foo-array dup mat set foo-array? ] unit-test
15 [ mat get [ bar>> 2 + <foo> ] map [ first ] keep foo-array? ] unit-test
17 [ 2 ] [ 2 <foo-array> dup mat set length ] unit-test
18 [ T{ foo } ] [ mat get first ] unit-test
19 [ T{ foo f 1 } ] [ T{ foo f 1 } 0 mat get [ set-nth ] keep first ] unit-test
21 TUPLE: baz { bing integer } bong ; final
24 [ 0 ] [ 1 <baz-array> first bing>> ] unit-test
25 [ f ] [ 1 <baz-array> first bong>> ] unit-test
27 TUPLE: broken x ; final
32 [ 100 ] [ 100 <broken-array> length ] unit-test
34 ! Can't define a tuple array for a non-tuple class
35 [ "IN: tuple-arrays.tests USING: tuple-arrays words ; TUPLE-ARRAY: word" eval( -- ) ]
36 [ error>> not-a-tuple? ]
39 ! Can't define a tuple array for a non-final class
42 [ "IN: tuple-arrays.tests USE: tuple-arrays TUPLE-ARRAY: non-final" eval( -- ) ]
43 [ error>> not-final? ]
47 TUPLE: empty-tuple ; final
49 TUPLE-ARRAY: empty-tuple
51 [ 100 ] [ 100 <empty-tuple-array> length ] unit-test
52 [ T{ empty-tuple } ] [ 100 <empty-tuple-array> first ] unit-test
53 [ ] [ T{ empty-tuple } 100 <empty-tuple-array> set-first ] unit-test
55 ! Changing a tuple into a struct shouldn't break the tuple array to the point
57 TUPLE: tuple-to-struct x ; final
59 TUPLE-ARRAY: tuple-to-struct
61 [ f ] [ tuple-to-struct struct-class? ] unit-test
63 ! This shouldn't crash
65 "IN: tuple-arrays.tests
66 USING: alien.c-types classes.struct ;
67 STRUCT: tuple-to-struct { x int } ;"
71 [ t ] [ tuple-to-struct struct-class? ] unit-test