1 USING: arrays byte-arrays kernel kernel.private literals math
2 memory namespaces sequences tools.test math.private quotations
3 continuations prettyprint io.streams.string debugger assocs
4 sequences.private accessors locals.backend grouping words
5 system alien alien.accessors kernel.private ;
8 { 0 } [ f size ] unit-test
9 { t } [ [ \ = \ = ] all-equal? ] unit-test
24 } [ 1 2 10 iota [ 3array ] 2with map ] unit-test
26 ! Don't leak extra roots if error is thrown
27 { } [ 1000 [ [ 3 throw ] ignore-errors ] times ] unit-test
29 { } [ 1000 [ [ -1 f <array> ] ignore-errors ] times ] unit-test
31 ! Make sure we report the correct error on stack underflow
33 2 head ${ "kernel-error" ERROR-DATASTACK-UNDERFLOW } =
39 3 [ { } set-retainstack ] dip ]
40 [ 2 head ${ "kernel-error" ERROR-RETAINSTACK-UNDERFLOW } =
45 : overflow-d ( -- ) 3 overflow-d ;
47 : (overflow-d-alt) ( -- n ) 3 ;
49 : overflow-d-alt ( -- ) (overflow-d-alt) overflow-d-alt ;
51 : overflow-r ( -- ) 3 load-local overflow-r ;
54 { overflow-d (overflow-d-alt) overflow-d-alt overflow-r }
55 [ t "no-compile" set-word-prop ] each
59 2 head ${ "kernel-error" ERROR-DATASTACK-OVERFLOW } =
65 2 head ${ "kernel-error" ERROR-DATASTACK-OVERFLOW } =
68 { } [ [ :c ] with-string-writer drop ] unit-test
71 2 head ${ "kernel-error" ERROR-RETAINSTACK-OVERFLOW } =
76 [ -7 <byte-array> ] must-fail
78 { 3 } [ t 3 and ] unit-test
79 { f } [ f 3 and ] unit-test
80 { f } [ 3 f and ] unit-test
81 { 4 } [ 4 6 or ] unit-test
82 { 6 } [ f 6 or ] unit-test
83 { f } [ 1 2 xor ] unit-test
84 { 1 } [ 1 f xor ] unit-test
85 { 2 } [ f 2 xor ] unit-test
86 { f } [ f f xor ] unit-test
91 [ 1 [ call ] dip ] must-fail
94 [ 1 2 [ call ] dip ] must-fail
97 { 5 } [ 1 [ 2 2 + ] dip + ] unit-test
99 [ [ ] keep ] must-fail
101 { 6 } [ 2 [ sq ] keep + ] unit-test
103 [ [ ] 2keep ] must-fail
104 [ 1 [ ] 2keep ] must-fail
105 { 3 1 2 } [ 1 2 [ 2drop 3 ] 2keep ] unit-test
107 { 0 } [ f [ sq ] [ 0 ] if* ] unit-test
108 { 4 } [ 2 [ sq ] [ 0 ] if* ] unit-test
110 { 0 } [ f [ 0 ] unless* ] unit-test
111 { t } [ t [ "Hello" ] unless* ] unit-test
113 { "2\n" } [ [ 1 2 [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
114 { "9\n" } [ [ 3 f [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
116 { f } [ f (clone) ] unit-test
117 { -123 } [ -123 (clone) ] unit-test
119 { 6 2 } [ 1 2 [ 5 + ] dip ] unit-test
121 { } [ get-callstack set-callstack ] unit-test
123 [ 3drop get-datastack ] must-fail
126 ! Doesn't compile; important
129 << \ foo t "no-compile" set-word-prop >>
131 [ drop foo ] must-fail
135 : (loop) ( a b c d -- )
136 [ pick ] dip swap [ pick ] dip swap
137 < [ [ 1 + ] 3dip (loop) ] [ 4drop ] if ; inline recursive
140 H{ } values swap [ dup length swap ] dip [ 0 ] 3dip (loop) ;
144 ! Discovered on Windows
145 : total-failure-1 ( -- a ) "" [ ] map unimplemented ;
147 [ total-failure-1 ] must-fail
149 { 1 1 2 2 3 3 } [ 1 2 3 [ dup ] tri@ ] unit-test
150 { 1 4 9 } [ 1 2 3 [ sq ] tri@ ] unit-test
151 [ [ sq ] tri@ ] must-infer
153 { 4 } [ 1 { [ 1 ] [ 2 ] } dispatch sq ] unit-test
155 ! Test traceback accuracy
156 : last-frame ( -- pair )
157 error-continuation get call>> callstack>array 6 head* 3 tail* ;
160 { [ 1 2 [ 3 throw ] call 4 ] [ 1 2 [ 3 throw ] call 4 ] 3 }
162 [ [ 1 2 [ 3 throw ] call 4 ] call ] ignore-errors
167 { [ 1 2 [ 3 throw ] dip 4 ] [ 1 2 [ 3 throw ] dip 4 ] 3 }
169 [ [ 1 2 [ 3 throw ] dip 4 ] call ] ignore-errors
174 { [ 1 2 3 throw [ ] call 4 ] [ 1 2 3 throw [ ] call 4 ] 3 }
176 [ [ 1 2 3 throw [ ] call 4 ] call ] ignore-errors
181 { [ 1 2 3 throw [ ] dip 4 ] [ 1 2 3 throw [ ] dip 4 ] 3 }
183 [ [ 1 2 3 throw [ ] dip 4 ] call ] ignore-errors
188 { [ 1 2 3 throw [ ] [ ] if 4 ] [ 1 2 3 throw [ ] [ ] if 4 ] 3 }
190 [ [ 1 2 3 throw [ ] [ ] if 4 ] call ] ignore-errors
194 { 10 2 3 4 5 } [ 1 2 3 4 5 [ 10 * ] 4dip ] unit-test
196 { 3 -1 5/6 } [ 1 2 3 4 5 6 [ + ] [ - ] [ / ] 2tri* ] unit-test
198 { { 1 2 } { 3 4 } { 5 6 } } [ 1 2 3 4 5 6 [ 2array ] 2tri@ ] unit-test
200 { t } [ { } identity-hashcode fixnum? ] unit-test
201 { 123 } [ 123 identity-hashcode ] unit-test
202 { t } [ f identity-hashcode fixnum? ] unit-test
204 ! Make sure memory protection faults work
205 [ f 0 alien-unsigned-1 ] [ vm-error? ] must-fail-with
206 [ 1 <alien> 0 alien-unsigned-1 ] [ vm-error? ] must-fail-with
208 { 1 2 3 1 2 3 } [ 1 2 3 3dup ] unit-test
209 { 1 2 3 4 1 2 3 4 } [ 1 2 3 4 4dup ] unit-test