1 USING: alien arrays definitions generic assocs hashtables io
2 kernel math namespaces parser prettyprint sequences strings
3 tools.test vectors words quotations classes
4 classes.private classes.union classes.mixin classes.predicate
5 classes.algebra vectors definitions source-files
6 compiler.units kernel.private sorting vocabs io.streams.string
8 IN: classes.union.tests
12 UNION: bah fixnum alien ;
13 [ bah ] [ \ bah? "predicating" word-prop ] unit-test
15 [ "USING: alien math ;\nIN: classes.union.tests\nUNION: bah fixnum alien ;\n" ]
16 [ [ \ bah see ] with-string-writer ] unit-test
18 ! Test redefinition of classes
19 UNION: union-1 fixnum float ;
21 GENERIC: generic-update-test ( x -- y )
23 M: union-1 generic-update-test drop "union-1" ;
25 [ f ] [ bignum union-1 class<= ] unit-test
26 [ t ] [ union-1 number class<= ] unit-test
27 [ "union-1" ] [ 1.0 generic-update-test ] unit-test
29 "IN: classes.union.tests USE: math USE: arrays UNION: union-1 rational array ;" eval
31 [ t ] [ bignum union-1 class<= ] unit-test
32 [ f ] [ union-1 number class<= ] unit-test
33 [ "union-1" ] [ { 1.0 } generic-update-test ] unit-test
35 "IN: classes.union.tests USE: math PREDICATE: union-1 < integer even? ;" eval
37 [ f ] [ union-1 union-class? ] unit-test
38 [ t ] [ union-1 predicate-class? ] unit-test
39 [ "union-1" ] [ 8 generic-update-test ] unit-test
40 [ -7 generic-update-test ] must-fail
42 ! Empty unions were causing problems
43 GENERIC: empty-union-test ( obj -- obj )
45 UNION: empty-union-1 ;
47 M: empty-union-1 empty-union-test ;
49 UNION: empty-union-2 ;
51 M: empty-union-2 empty-union-test ;
53 ! Redefining a class didn't update containing unions
54 UNION: redefine-bug-1 fixnum ;
56 UNION: redefine-bug-2 redefine-bug-1 quotation ;
58 [ t ] [ fixnum redefine-bug-2 class<= ] unit-test
59 [ t ] [ quotation redefine-bug-2 class<= ] unit-test
61 [ ] [ "IN: classes.union.tests USE: math UNION: redefine-bug-1 bignum ;" eval ] unit-test
63 [ t ] [ bignum redefine-bug-1 class<= ] unit-test
64 [ f ] [ fixnum redefine-bug-2 class<= ] unit-test
65 [ t ] [ bignum redefine-bug-2 class<= ] unit-test
67 ! Too eager with reset-class
69 [ ] [ "IN: classes.union.tests SINGLETON: foo UNION: blah foo ;" <string-reader> "union-reset-test" parse-stream drop ] unit-test
71 [ t ] [ "blah" "classes.union.tests" lookup union-class? ] unit-test
73 [ ] [ "IN: classes.union.tests USE: math UNION: blah integer ;" <string-reader> "union-reset-test" parse-stream drop ] unit-test
75 [ t ] [ "blah" "classes.union.tests" lookup union-class? ] unit-test
77 GENERIC: test-generic ( x -- y )
81 UNION: a-union a-tuple ;
83 M: a-union test-generic ;
85 [ f ] [ \ test-generic "methods" word-prop assoc-empty? ] unit-test
87 [ ] [ [ \ a-tuple forget-class ] with-compilation-unit ] unit-test
89 [ t ] [ \ test-generic "methods" word-prop assoc-empty? ] unit-test