]> gitweb.factorcode.org Git - factor.git/blob - core/words/words-tests.factor
merge project-euler.factor
[factor.git] / core / words / words-tests.factor
1 USING: arrays generic assocs kernel math namespaces
2 sequences tools.test words definitions parser quotations
3 vocabs continuations classes.tuple compiler.units
4 io.streams.string accessors eval words.symbol ;
5 IN: words.tests
6
7 [ 4 ] [
8     [
9         "poo" "words.tests" create [ 2 2 + ] (( -- n )) define-declared
10     ] with-compilation-unit
11     "poo" "words.tests" lookup execute
12 ] unit-test
13
14 [ t ] [ t vocabs [ words [ word? and ] each ] each ] unit-test
15
16 DEFER: plist-test
17
18 [ t ] [
19     \ plist-test t "sample-property" set-word-prop
20     \ plist-test "sample-property" word-prop
21 ] unit-test
22
23 [ f ] [
24     \ plist-test f "sample-property" set-word-prop
25     \ plist-test "sample-property" word-prop
26 ] unit-test
27
28 "create-test" "scratchpad" create { 1 2 } "testing" set-word-prop
29 [ { 1 2 } ] [
30     "create-test" "scratchpad" lookup "testing" word-prop
31 ] unit-test
32
33 [
34     [ t ] [ \ array? "array?" "arrays" lookup = ] unit-test
35
36     [ ] [ "test-scope" "scratchpad" create drop ] unit-test
37 ] with-scope
38
39 [ "test-scope" ] [
40     "test-scope" "scratchpad" lookup name>> 
41 ] unit-test
42
43 [ t ] [ vocabs array? ] unit-test
44 [ t ] [ vocabs [ words [ word? ] all? ] all? ] unit-test
45
46 [ f ] [ gensym gensym = ] unit-test
47
48 SYMBOL: a-symbol
49 [ t ] [ \ a-symbol symbol? ] unit-test
50
51 ! See if redefining a generic as a colon def clears some
52 ! word props.
53 GENERIC: testing ( a -- b )
54 "IN: words.tests : testing ( -- ) ;" eval( -- )
55
56 [ f ] [ \ testing generic? ] unit-test
57
58 : forgotten ( -- ) ;
59 : another-forgotten ( -- ) ;
60
61 FORGET: forgotten
62
63 FORGET: another-forgotten
64 : another-forgotten ( -- ) ;
65
66
67 DEFER: x
68 [ x ] [ undefined? ] must-fail-with
69
70 [ ] [ "no-loc" "words.tests" create drop ] unit-test
71 [ f ] [ "no-loc" "words.tests" lookup where ] unit-test
72
73 [ ] [ "IN: words.tests : no-loc-2 ( -- ) ;" eval( -- ) ] unit-test
74 [ f ] [ "no-loc-2" "words.tests" lookup where ] unit-test
75
76 [ ] [ "IN: words.tests : test-last ( -- ) ;" eval( -- ) ] unit-test
77 [ "test-last" ] [ word name>> ] unit-test
78
79 "undef-test" "words.tests" lookup [
80     [ forget ] with-compilation-unit
81 ] when*
82
83 [ "IN: words.tests : undef-test ( -- ) ; << undef-test >>" eval( -- ) ]
84 [ error>> undefined? ] must-fail-with
85
86 [ ] [
87     "IN: words.tests GENERIC: symbol-generic ( -- )" eval( -- )
88 ] unit-test
89
90 [ ] [
91     "IN: words.tests SYMBOL: symbol-generic" eval( -- )
92 ] unit-test
93
94 [ t ] [ "symbol-generic" "words.tests" lookup symbol? ] unit-test
95 [ f ] [ "symbol-generic" "words.tests" lookup generic? ] unit-test
96
97 [ ] [
98     "IN: words.tests GENERIC: symbol-generic ( a -- b )" <string-reader>
99     "symbol-generic-test" parse-stream drop
100 ] unit-test
101
102 [ ] [
103     "IN: words.tests TUPLE: symbol-generic ;" <string-reader>
104     "symbol-generic-test" parse-stream drop
105 ] unit-test
106
107 [ t ] [ "symbol-generic" "words.tests" lookup symbol? ] unit-test
108 [ f ] [ "symbol-generic" "words.tests" lookup generic? ] unit-test
109
110 ! Regressions
111 [ ] [ "IN: words.tests : decl-forget-test ( -- ) ; foldable" eval( -- ) ] unit-test
112 [ t ] [ "decl-forget-test" "words.tests" lookup "foldable" word-prop ] unit-test
113 [ ] [ "IN: words.tests : decl-forget-test ( -- ) ;" eval( -- ) ] unit-test
114 [ f ] [ "decl-forget-test" "words.tests" lookup "foldable" word-prop ] unit-test
115
116 [ ] [ "IN: words.tests : decl-forget-test ( -- ) ; flushable" eval( -- ) ] unit-test
117 [ t ] [ "decl-forget-test" "words.tests" lookup "flushable" word-prop ] unit-test
118 [ ] [ "IN: words.tests : decl-forget-test ( -- ) ;" eval( -- ) ] unit-test
119 [ f ] [ "decl-forget-test" "words.tests" lookup "flushable" word-prop ] unit-test
120
121 [ { } ]
122 [
123     all-words [
124         "compiled-uses" word-prop
125         keys [ "forgotten" word-prop ] filter
126     ] map harvest
127 ] unit-test
128
129 [ "hi" word-xt ] must-fail