]> gitweb.factorcode.org Git - factor.git/blob - core/kernel/kernel-tests.factor
Merge branch 'master' of git://github.com/littledan/Factor
[factor.git] / core / kernel / kernel-tests.factor
1 USING: arrays byte-arrays kernel kernel.private math memory
2 namespaces sequences tools.test math.private quotations
3 continuations prettyprint io.streams.string debugger assocs
4 sequences.private accessors locals.backend grouping words ;
5 IN: kernel.tests
6
7 [ 0 ] [ f size ] unit-test
8 [ t ] [ [ \ = \ = ] all-equal? ] unit-test
9
10 ! Don't leak extra roots if error is thrown
11 [ ] [ 10000 [ [ 3 throw ] ignore-errors ] times ] unit-test
12
13 [ ] [ 10000 [ [ -1 f <array> ] ignore-errors ] times ] unit-test
14
15 ! Make sure we report the correct error on stack underflow
16 [ clear drop ] [ { "kernel-error" 10 f f } = ] must-fail-with
17
18 [ ] [ :c ] unit-test
19
20 [ 3 [ { } set-retainstack ] dip ] [ { "kernel-error" 12 f f } = ] must-fail-with
21
22 [ ] [ :c ] unit-test
23
24 : overflow-d ( -- ) 3 overflow-d ;
25
26 : (overflow-d-alt) ( -- n ) 3 ;
27
28 : overflow-d-alt ( -- ) (overflow-d-alt) overflow-d-alt ;
29
30 : overflow-r ( -- ) 3 load-local overflow-r ;
31
32 <<
33 { overflow-d (overflow-d-alt) overflow-d-alt overflow-r }
34 [ t "no-compile" set-word-prop ] each
35 >>
36
37 [ overflow-d ] [ { "kernel-error" 11 f f } = ] must-fail-with
38
39 [ ] [ :c ] unit-test
40
41 [ overflow-d-alt ] [ { "kernel-error" 11 f f } = ] must-fail-with
42
43 [ ] [ [ :c ] with-string-writer drop ] unit-test
44
45 [ overflow-r ] [ { "kernel-error" 13 f f } = ] must-fail-with
46
47 [ ] [ :c ] unit-test
48
49 [ -7 <byte-array> ] must-fail
50
51 [ 3 ] [ t 3 and ] unit-test
52 [ f ] [ f 3 and ] unit-test
53 [ f ] [ 3 f and ] unit-test
54 [ 4 ] [ 4 6 or ] unit-test
55 [ 6 ] [ f 6 or ] unit-test
56 [ f ] [ 1 2 xor ] unit-test
57 [ 1 ] [ 1 f xor ] unit-test
58 [ 2 ] [ f 2 xor ] unit-test
59 [ f ] [ f f xor ] unit-test
60
61 [ dip ] must-fail
62 [ ] [ :c ] unit-test
63
64 [ 1 [ call ] dip ] must-fail
65 [ ] [ :c ] unit-test
66
67 [ 1 2 [ call ] dip ] must-fail
68 [ ] [ :c ] unit-test
69
70 [ 5 ] [ 1 [ 2 2 + ] dip + ] unit-test
71
72 [ [ ] keep ] must-fail
73
74 [ 6 ] [ 2 [ sq ] keep + ] unit-test
75
76 [ [ ] 2keep ] must-fail
77 [ 1 [ ] 2keep ] must-fail
78 [ 3 1 2 ] [ 1 2 [ 2drop 3 ] 2keep ] unit-test
79
80 [ 0 ] [ f [ sq ] [ 0 ] if* ] unit-test
81 [ 4 ] [ 2 [ sq ] [ 0 ] if* ] unit-test
82
83 [ 0 ] [ f [ 0 ] unless* ] unit-test
84 [ t ] [ t [ "Hello" ] unless* ] unit-test
85
86 [ "2\n" ] [ [ 1 2 [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
87 [ "9\n" ] [ [ 3 f [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
88
89 [ f ] [ f (clone) ] unit-test
90 [ -123 ] [ -123 (clone) ] unit-test
91
92 [ 6 2 ] [ 1 2 [ 5 + ] dip ] unit-test
93
94 [ ] [ callstack set-callstack ] unit-test
95
96 [ 3drop datastack ] must-fail
97 [ ] [ :c ] unit-test
98
99 ! Doesn't compile; important
100 : foo ( a -- b ) ;
101
102 << \ foo t "no-compile" set-word-prop >>
103
104 [ drop foo ] must-fail
105 [ ] [ :c ] unit-test
106
107 ! Regression
108 : (loop) ( a b c d -- )
109     [ pick ] dip swap [ pick ] dip swap
110     < [ [ 1 + ] 3dip (loop) ] [ 2drop 2drop ] if ; inline recursive
111
112 : loop ( obj -- )
113     H{ } values swap [ dup length swap ] dip [ 0 ] 3dip (loop) ;
114
115 [ loop ] must-fail
116
117 ! Discovered on Windows
118 : total-failure-1 ( -- a ) "" [ ] map unimplemented ;
119
120 [ total-failure-1 ] must-fail
121
122 [ 1 1 2 2 3 3 ] [ 1 2 3 [ dup ] tri@ ] unit-test
123 [ 1 4 9 ] [ 1 2 3 [ sq ] tri@ ] unit-test
124 [ [ sq ] tri@ ] must-infer
125
126 [ 4 ] [ 1 { [ 1 ] [ 2 ] } dispatch sq ] unit-test
127
128 ! Test traceback accuracy
129 : last-frame ( -- pair )
130     error-continuation get call>> callstack>array 6 head* 3 tail* ;
131
132 [
133     { [ 1 2 [ 3 throw ] call 4 ] [ 1 2 [ 3 throw ] call 4 ] 3 }
134 ] [
135     [ [ 1 2 [ 3 throw ] call 4 ] call ] ignore-errors
136     last-frame
137 ] unit-test
138
139 [
140     { [ 1 2 [ 3 throw ] dip 4 ] [ 1 2 [ 3 throw ] dip 4 ] 3 }
141 ] [
142     [ [ 1 2 [ 3 throw ] dip 4 ] call ] ignore-errors
143     last-frame
144 ] unit-test
145
146 [
147     { [ 1 2 3 throw [ ] call 4 ] [ 1 2 3 throw [ ] call 4 ] 3 }
148 ] [
149     [ [ 1 2 3 throw [ ] call 4 ] call ] ignore-errors
150     last-frame
151 ] unit-test
152
153 [
154     { [ 1 2 3 throw [ ] dip 4 ] [ 1 2 3 throw [ ] dip 4 ] 3 }
155 ] [
156     [ [ 1 2 3 throw [ ] dip 4 ] call ] ignore-errors
157     last-frame
158 ] unit-test
159
160 [
161     { [ 1 2 3 throw [ ] [ ] if 4 ] [ 1 2 3 throw [ ] [ ] if 4 ] 3 }
162 ] [
163     [ [ 1 2 3 throw [ ] [ ] if 4 ] call ] ignore-errors
164     last-frame
165 ] unit-test
166
167 [ 10 2 3 4 5 ] [ 1 2 3 4 5 [ 10 * ] 4dip ] unit-test
168
169 [ 3 -1 5/6 ] [ 1 2 3 4 5 6 [ + ] [ - ] [ / ] 2tri* ] unit-test
170
171 [ { 1 2 } { 3 4 } { 5 6 } ] [ 1 2 3 4 5 6 [ 2array ] 2tri@ ] unit-test
172
173 [ t ] [ { } identity-hashcode fixnum? ] unit-test
174 [ 123 ] [ 123 identity-hashcode ] unit-test
175 [ t ] [ f identity-hashcode fixnum? ] unit-test