2011-10-29 20:09:56 -04:00
|
|
|
USING: accessors alien arrays definitions generic assocs
|
|
|
|
hashtables io kernel math namespaces parser prettyprint
|
|
|
|
sequences strings tools.test vectors words quotations classes
|
2008-07-04 02:32:11 -04:00
|
|
|
classes.private classes.union classes.mixin classes.predicate
|
2011-10-29 20:09:56 -04:00
|
|
|
classes.algebra classes.union.private source-files
|
|
|
|
compiler.units kernel.private sorting vocabs io.streams.string
|
2011-11-22 02:00:52 -05:00
|
|
|
eval see math.private slots ;
|
2008-07-04 02:32:11 -04:00
|
|
|
IN: classes.union.tests
|
|
|
|
|
|
|
|
! DEFER: bah
|
|
|
|
! FORGET: bah
|
|
|
|
UNION: bah fixnum alien ;
|
|
|
|
[ bah ] [ \ bah? "predicating" word-prop ] unit-test
|
|
|
|
|
2008-07-04 02:32:38 -04:00
|
|
|
[ "USING: alien math ;\nIN: classes.union.tests\nUNION: bah fixnum alien ;\n" ]
|
2008-07-04 02:32:11 -04:00
|
|
|
[ [ \ bah see ] with-string-writer ] unit-test
|
|
|
|
|
|
|
|
! Test redefinition of classes
|
|
|
|
UNION: union-1 fixnum float ;
|
|
|
|
|
|
|
|
GENERIC: generic-update-test ( x -- y )
|
|
|
|
|
|
|
|
M: union-1 generic-update-test drop "union-1" ;
|
|
|
|
|
|
|
|
[ f ] [ bignum union-1 class<= ] unit-test
|
|
|
|
[ t ] [ union-1 number class<= ] unit-test
|
|
|
|
[ "union-1" ] [ 1.0 generic-update-test ] unit-test
|
|
|
|
|
2009-04-17 16:49:21 -04:00
|
|
|
"IN: classes.union.tests USE: math USE: arrays UNION: union-1 rational array ;" eval( -- )
|
2008-07-04 02:32:11 -04:00
|
|
|
|
|
|
|
[ t ] [ bignum union-1 class<= ] unit-test
|
|
|
|
[ f ] [ union-1 number class<= ] unit-test
|
|
|
|
[ "union-1" ] [ { 1.0 } generic-update-test ] unit-test
|
|
|
|
|
2009-04-17 16:49:21 -04:00
|
|
|
"IN: classes.union.tests USE: math PREDICATE: union-1 < integer even? ;" eval( -- )
|
2008-07-04 02:32:11 -04:00
|
|
|
|
|
|
|
[ f ] [ union-1 union-class? ] unit-test
|
|
|
|
[ t ] [ union-1 predicate-class? ] unit-test
|
|
|
|
[ "union-1" ] [ 8 generic-update-test ] unit-test
|
|
|
|
[ -7 generic-update-test ] must-fail
|
|
|
|
|
|
|
|
! Empty unions were causing problems
|
|
|
|
GENERIC: empty-union-test ( obj -- obj )
|
|
|
|
|
|
|
|
UNION: empty-union-1 ;
|
|
|
|
|
|
|
|
M: empty-union-1 empty-union-test ;
|
|
|
|
|
|
|
|
UNION: empty-union-2 ;
|
|
|
|
|
|
|
|
M: empty-union-2 empty-union-test ;
|
|
|
|
|
2011-10-29 20:09:56 -04:00
|
|
|
[ [ drop f ] ] [ \ empty-union-1? def>> ] unit-test
|
|
|
|
|
2008-07-04 02:32:11 -04:00
|
|
|
! Redefining a class didn't update containing unions
|
|
|
|
UNION: redefine-bug-1 fixnum ;
|
|
|
|
|
|
|
|
UNION: redefine-bug-2 redefine-bug-1 quotation ;
|
|
|
|
|
|
|
|
[ t ] [ fixnum redefine-bug-2 class<= ] unit-test
|
|
|
|
[ t ] [ quotation redefine-bug-2 class<= ] unit-test
|
|
|
|
|
2009-04-17 16:49:21 -04:00
|
|
|
[ ] [ "IN: classes.union.tests USE: math UNION: redefine-bug-1 bignum ;" eval( -- ) ] unit-test
|
2008-07-04 02:32:11 -04:00
|
|
|
|
|
|
|
[ t ] [ bignum redefine-bug-1 class<= ] unit-test
|
|
|
|
[ f ] [ fixnum redefine-bug-2 class<= ] unit-test
|
|
|
|
[ t ] [ bignum redefine-bug-2 class<= ] unit-test
|
|
|
|
|
|
|
|
! Too eager with reset-class
|
|
|
|
|
|
|
|
[ ] [ "IN: classes.union.tests SINGLETON: foo UNION: blah foo ;" <string-reader> "union-reset-test" parse-stream drop ] unit-test
|
|
|
|
|
2011-11-06 18:57:24 -05:00
|
|
|
[ t ] [ "blah" "classes.union.tests" lookup-word union-class? ] unit-test
|
2008-07-04 02:32:11 -04:00
|
|
|
|
2011-11-06 18:57:24 -05:00
|
|
|
[ t ] [ "foo?" "classes.union.tests" lookup-word predicate? ] unit-test
|
2009-03-13 05:22:16 -04:00
|
|
|
|
2008-07-04 02:32:11 -04:00
|
|
|
[ ] [ "IN: classes.union.tests USE: math UNION: blah integer ;" <string-reader> "union-reset-test" parse-stream drop ] unit-test
|
|
|
|
|
2011-11-06 18:57:24 -05:00
|
|
|
[ t ] [ "blah" "classes.union.tests" lookup-word union-class? ] unit-test
|
2008-07-04 02:32:11 -04:00
|
|
|
|
2011-11-06 18:57:24 -05:00
|
|
|
[ f ] [ "foo?" "classes.union.tests" lookup-word predicate? ] unit-test
|
2009-03-13 05:22:16 -04:00
|
|
|
|
2008-07-04 02:32:11 -04:00
|
|
|
GENERIC: test-generic ( x -- y )
|
|
|
|
|
|
|
|
TUPLE: a-tuple ;
|
|
|
|
|
|
|
|
UNION: a-union a-tuple ;
|
|
|
|
|
|
|
|
M: a-union test-generic ;
|
|
|
|
|
|
|
|
[ f ] [ \ test-generic "methods" word-prop assoc-empty? ] unit-test
|
|
|
|
|
|
|
|
[ ] [ [ \ a-tuple forget-class ] with-compilation-unit ] unit-test
|
|
|
|
|
|
|
|
[ t ] [ \ test-generic "methods" word-prop assoc-empty? ] unit-test
|
2011-10-29 20:09:56 -04:00
|
|
|
|
|
|
|
! Fast union predicates
|
|
|
|
|
|
|
|
[ t ] [ integer union-of-builtins? ] unit-test
|
|
|
|
|
|
|
|
[ t ] [ \ integer? def>> \ fixnum-bitand swap member? ] unit-test
|
|
|
|
|
|
|
|
[ ] [ "IN: classes.union.tests USE: math UNION: fast-union-1 fixnum ; UNION: fast-union-2 fast-union-1 bignum ;" eval( -- ) ] unit-test
|
|
|
|
|
2011-11-06 18:57:24 -05:00
|
|
|
[ t ] [ "fast-union-2?" "classes.union.tests" lookup-word def>> \ fixnum-bitand swap member? ] unit-test
|
2011-10-29 20:09:56 -04:00
|
|
|
|
|
|
|
[ ] [ "IN: classes.union.tests USE: vectors UNION: fast-union-1 vector ;" eval( -- ) ] unit-test
|
|
|
|
|
2011-11-06 18:57:24 -05:00
|
|
|
[ f ] [ "fast-union-2?" "classes.union.tests" lookup-word def>> \ fixnum-bitand swap member? ] unit-test
|