2008-09-02 14:04:33 -04:00
|
|
|
USING: tuple-arrays sequences tools.test namespaces kernel
|
2010-08-06 03:15:22 -04:00
|
|
|
math accessors classes.tuple eval classes.struct ;
|
2008-03-08 05:27:19 -05:00
|
|
|
IN: tuple-arrays.tests
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
SYMBOL: mat
|
2010-02-17 09:57:02 -05:00
|
|
|
TUPLE: foo bar ; final
|
2007-09-20 18:09:08 -04:00
|
|
|
C: <foo> foo
|
2009-04-26 14:31:10 -04:00
|
|
|
TUPLE-ARRAY: foo
|
|
|
|
|
|
|
|
[ 2 ] [ 2 <foo-array> dup mat set length ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
[ T{ foo } ] [ mat get first ] unit-test
|
2008-09-03 07:05:50 -04:00
|
|
|
[ T{ foo f 2 } ] [ T{ foo f 2 } 0 mat get [ set-nth ] keep first ] unit-test
|
2009-04-26 14:31:10 -04:00
|
|
|
[ t ] [ { T{ foo f 1 } T{ foo f 2 } } >foo-array dup mat set foo-array? ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
[ T{ foo f 3 } t ]
|
2009-04-26 14:31:10 -04:00
|
|
|
[ mat get [ bar>> 2 + <foo> ] map [ first ] keep foo-array? ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-04-26 14:31:10 -04:00
|
|
|
[ 2 ] [ 2 <foo-array> dup mat set length ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
[ T{ foo } ] [ mat get first ] unit-test
|
2008-09-03 07:05:50 -04:00
|
|
|
[ T{ foo f 1 } ] [ T{ foo f 1 } 0 mat get [ set-nth ] keep first ] unit-test
|
2008-07-14 04:30:33 -04:00
|
|
|
|
2010-02-17 09:57:02 -05:00
|
|
|
TUPLE: baz { bing integer } bong ; final
|
2009-04-26 14:31:10 -04:00
|
|
|
TUPLE-ARRAY: baz
|
|
|
|
|
|
|
|
[ 0 ] [ 1 <baz-array> first bing>> ] unit-test
|
|
|
|
[ f ] [ 1 <baz-array> first bong>> ] unit-test
|
2009-04-26 22:24:55 -04:00
|
|
|
|
2010-02-17 09:57:02 -05:00
|
|
|
TUPLE: broken x ; final
|
2009-04-26 22:24:55 -04:00
|
|
|
: broken ( -- ) ;
|
|
|
|
|
|
|
|
TUPLE-ARRAY: broken
|
|
|
|
|
2010-02-17 09:57:02 -05:00
|
|
|
[ 100 ] [ 100 <broken-array> length ] unit-test
|
|
|
|
|
|
|
|
! Can't define a tuple array for a non-tuple class
|
|
|
|
[ "IN: tuple-arrays.tests USING: tuple-arrays words ; TUPLE-ARRAY: word" eval( -- ) ]
|
|
|
|
[ error>> not-a-tuple? ]
|
|
|
|
must-fail-with
|
|
|
|
|
|
|
|
! Can't define a tuple array for a non-final class
|
|
|
|
TUPLE: non-final x ;
|
|
|
|
|
|
|
|
[ "IN: tuple-arrays.tests USE: tuple-arrays TUPLE-ARRAY: non-final" eval( -- ) ]
|
|
|
|
[ error>> not-final? ]
|
2010-08-06 03:15:22 -04:00
|
|
|
must-fail-with
|
|
|
|
|
|
|
|
! Empty tuple
|
|
|
|
TUPLE: empty-tuple ; final
|
|
|
|
|
|
|
|
TUPLE-ARRAY: empty-tuple
|
|
|
|
|
|
|
|
[ 100 ] [ 100 <empty-tuple-array> length ] unit-test
|
|
|
|
[ T{ empty-tuple } ] [ 100 <empty-tuple-array> first ] unit-test
|
|
|
|
[ ] [ T{ empty-tuple } 100 <empty-tuple-array> set-first ] unit-test
|
|
|
|
|
|
|
|
! Changing a tuple into a struct shouldn't break the tuple array to the point
|
|
|
|
! of crashing Factor
|
|
|
|
TUPLE: tuple-to-struct x ; final
|
|
|
|
|
|
|
|
TUPLE-ARRAY: tuple-to-struct
|
|
|
|
|
|
|
|
[ f ] [ tuple-to-struct struct-class? ] unit-test
|
|
|
|
|
|
|
|
! This shouldn't crash
|
|
|
|
[ ] [
|
|
|
|
"IN: tuple-arrays.tests
|
|
|
|
USING: alien.c-types classes.struct ;
|
|
|
|
STRUCT: tuple-to-struct { x int } ;"
|
|
|
|
eval( -- )
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [ tuple-to-struct struct-class? ] unit-test
|