]> gitweb.factorcode.org Git - factor.git/blob - core/classes/tuple/parser/parser-tests.factor
Merge branch 'master' of git://tiodante.com/git/factor
[factor.git] / core / classes / tuple / parser / parser-tests.factor
1 IN: classes.tuple.parser.tests
2 USING: accessors classes.tuple.parser lexer words classes
3 sequences math kernel slots tools.test parser compiler.units
4 arrays classes.tuple eval ;
5
6 TUPLE: test-1 ;
7
8 [ t ] [ test-1 "slots" word-prop empty? ] unit-test
9
10 TUPLE: test-2 < test-1 ;
11
12 [ t ] [ test-2 "slots" word-prop empty? ] unit-test
13 [ test-1 ] [ test-2 superclass ] unit-test
14
15 TUPLE: test-3 a ;
16
17 [ { "a" } ] [ test-3 "slots" word-prop [ name>> ] map ] unit-test
18
19 [ object ] [ "a" test-3 "slots" word-prop slot-named class>> ] unit-test
20
21 TUPLE: test-4 < test-3 b ;
22
23 [ { "b" } ] [ test-4 "slots" word-prop [ name>> ] map ] unit-test
24
25 TUPLE: test-5 { a integer } ;
26
27 [ { { "a" integer } } ]
28 [
29     test-5 "slots" word-prop
30     [ [ name>> ] [ class>> ] bi 2array ] map
31 ] unit-test
32
33 TUPLE: test-6 < test-5 { b integer } ;
34
35 [ integer ] [ "b" test-6 "slots" word-prop slot-named class>> ] unit-test
36
37 [ { { "b" integer } } ]
38 [
39     test-6 "slots" word-prop
40     [ [ name>> ] [ class>> ] bi 2array ] map
41 ] unit-test
42
43 TUPLE: test-7 { b integer initial: 3 } ;
44
45 [ 3 ] [ "b" test-7 "slots" word-prop slot-named initial>> ] unit-test
46
47 TUPLE: test-8 { b integer read-only } ;
48
49 [ t ] [ "b" test-8 "slots" word-prop slot-named read-only>> ] unit-test
50
51 DEFER: foo
52
53 [ "IN: classes.tuple.parser.tests TUPLE: foo < test-1 < ;" eval ]
54 [ error>> invalid-slot-name? ]
55 must-fail-with
56
57 [ "IN: classes.tuple.parser.tests TUPLE: foo :" eval ]
58 [ error>> invalid-slot-name? ]
59 must-fail-with
60
61 [ "IN: classes.tuple.parser.tests TUPLE: foo" eval ]
62 [ error>> unexpected-eof? ]
63 must-fail-with
64
65 2 [
66     [ "IN: classes.tuple.parser.tests USE: alien TUPLE: foo { slot dll } ;" eval ]
67     [ error>> no-initial-value? ]
68     must-fail-with
69
70     [ f ] [ \ foo tuple-class? ] unit-test
71 ] times
72
73 2 [
74     [ "IN: classes.tuple.parser.tests USE: arrays TUPLE: foo { slot array initial: 5 } ;" eval ]
75     [ error>> bad-initial-value? ]
76     must-fail-with
77
78     [ f ] [ \ foo tuple-class? ] unit-test
79 ] times
80
81 [ "IN: classes.tuple.parser.tests USE: arrays TUPLE: foo slot { slot array } ;" eval ]
82 [ error>> duplicate-slot-names? ]
83 must-fail-with
84
85 [ f ] [ \ foo tuple-class? ] unit-test
86
87 [ ] [
88     [
89         { test-1 test-2 test-3 test-4 test-5 test-6 test-7 test-8 foo }
90         [ dup class? [ forget-class ] [ drop ] if ] each
91     ] with-compilation-unit
92 ] unit-test
93
94