]> gitweb.factorcode.org Git - factor.git/blob - core/slots/slots-tests.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / core / slots / slots-tests.factor
1 USING: math accessors slots strings generic.single kernel
2 tools.test generic words parser eval math.functions ;
3 IN: slots.tests
4
5 TUPLE: r/w-test foo ;
6
7 TUPLE: r/o-test { foo read-only } ;
8
9 [ r/o-test new 123 >>foo ] [ no-method? ] must-fail-with
10
11 TUPLE: decl-test { foo integer } ;
12
13 [ decl-test new 1.0 >>foo ] [ bad-slot-value? ] must-fail-with
14
15 TUPLE: hello length ;
16
17 [ 3 ] [ "xyz" length>> ] unit-test
18
19 [ "xyz" 4 >>length ] [ no-method? ] must-fail-with
20
21 [ t ] [ r/o-test \ foo>> method "foldable" word-prop ] unit-test
22 [ t ] [ r/o-test \ foo>> method "flushable" word-prop ] unit-test
23
24 [ f ] [ r/w-test \ foo>> method "foldable" word-prop ] unit-test
25 [ t ] [ r/w-test \ foo>> method "flushable" word-prop ] unit-test
26
27 ! See if declarations are cleared on redefinition
28 [ ] [ "IN: slots.tests TUPLE: r/w-test { foo read-only } ;" eval( -- ) ] unit-test
29
30 [ t ] [ r/w-test \ foo>> method "foldable" word-prop ] unit-test
31 [ t ] [ r/w-test \ foo>> method "flushable" word-prop ] unit-test
32
33 [ ] [ "IN: slots.tests TUPLE: r/w-test foo ;" eval( -- ) ] unit-test
34
35 [ f ] [ r/w-test \ foo>> method "foldable" word-prop ] unit-test
36 [ t ] [ r/w-test \ foo>> method "flushable" word-prop ] unit-test
37
38 ! Test protocol slots
39 SLOT: my-protocol-slot-test
40
41 TUPLE: protocol-slot-test-tuple x ;
42
43 M: protocol-slot-test-tuple my-protocol-slot-test>> x>> sq ;
44 M: protocol-slot-test-tuple (>>my-protocol-slot-test) [ sqrt ] dip (>>x) ;
45
46 [ 9 ] [ T{ protocol-slot-test-tuple { x 3 } } my-protocol-slot-test>> ] unit-test
47
48 [ 4.0 ] [
49     T{ protocol-slot-test-tuple { x 3 } } clone
50     [ 7 + ] change-my-protocol-slot-test x>>
51 ] unit-test