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 ;
7 [ 0 ] [ f size ] unit-test
8 [ t ] [ [ \ = \ = ] all-equal? ] unit-test
10 ! Don't leak extra roots if error is thrown
11 [ ] [ 10000 [ [ 3 throw ] ignore-errors ] times ] unit-test
13 [ ] [ 10000 [ [ -1 f <array> ] ignore-errors ] times ] unit-test
15 ! Make sure we report the correct error on stack underflow
16 [ clear drop ] [ { "kernel-error" 10 f f } = ] must-fail-with
20 [ 3 [ { } set-retainstack ] dip ] [ { "kernel-error" 12 f f } = ] must-fail-with
24 : overflow-d ( -- ) 3 overflow-d ;
26 : (overflow-d-alt) ( -- n ) 3 ;
28 : overflow-d-alt ( -- ) (overflow-d-alt) overflow-d-alt ;
30 : overflow-r ( -- ) 3 load-local overflow-r ;
33 { overflow-d (overflow-d-alt) overflow-d-alt overflow-r }
34 [ t "no-compile" set-word-prop ] each
37 [ overflow-d ] [ { "kernel-error" 11 f f } = ] must-fail-with
41 [ overflow-d-alt ] [ { "kernel-error" 11 f f } = ] must-fail-with
43 [ ] [ [ :c ] with-string-writer drop ] unit-test
45 [ overflow-r ] [ { "kernel-error" 13 f f } = ] must-fail-with
49 : overflow-c ( -- ) overflow-c overflow-c ;
51 [ overflow-c ] [ { "kernel-error" 14 f f } = ] must-fail-with
53 [ -7 <byte-array> ] must-fail
55 [ 3 ] [ t 3 and ] unit-test
56 [ f ] [ f 3 and ] unit-test
57 [ f ] [ 3 f and ] unit-test
58 [ 4 ] [ 4 6 or ] unit-test
59 [ 6 ] [ f 6 or ] unit-test
60 [ f ] [ 1 2 xor ] unit-test
61 [ 1 ] [ 1 f xor ] unit-test
62 [ 2 ] [ f 2 xor ] unit-test
63 [ f ] [ f f xor ] unit-test
68 [ 1 [ call ] dip ] must-fail
71 [ 1 2 [ call ] dip ] must-fail
74 [ 5 ] [ 1 [ 2 2 + ] dip + ] unit-test
76 [ [ ] keep ] must-fail
78 [ 6 ] [ 2 [ sq ] keep + ] unit-test
80 [ [ ] 2keep ] must-fail
81 [ 1 [ ] 2keep ] must-fail
82 [ 3 1 2 ] [ 1 2 [ 2drop 3 ] 2keep ] unit-test
84 [ 0 ] [ f [ sq ] [ 0 ] if* ] unit-test
85 [ 4 ] [ 2 [ sq ] [ 0 ] if* ] unit-test
87 [ 0 ] [ f [ 0 ] unless* ] unit-test
88 [ t ] [ t [ "Hello" ] unless* ] unit-test
90 [ "2\n" ] [ [ 1 2 [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
91 [ "9\n" ] [ [ 3 f [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
93 [ f ] [ f (clone) ] unit-test
94 [ -123 ] [ -123 (clone) ] unit-test
96 [ 6 2 ] [ 1 2 [ 5 + ] dip ] unit-test
98 [ ] [ callstack set-callstack ] unit-test
100 [ 3drop datastack ] must-fail
103 ! Doesn't compile; important
106 << \ foo t "no-compile" set-word-prop >>
108 [ drop foo ] must-fail
112 : (loop) ( a b c d -- )
113 [ pick ] dip swap [ pick ] dip swap
114 < [ [ 1 + ] 3dip (loop) ] [ 2drop 2drop ] if ; inline recursive
117 H{ } values swap [ dup length swap ] dip [ 0 ] 3dip (loop) ;
121 ! Discovered on Windows
122 : total-failure-1 ( -- a ) "" [ ] map unimplemented ;
124 [ total-failure-1 ] must-fail
126 [ 1 1 2 2 3 3 ] [ 1 2 3 [ dup ] tri@ ] unit-test
127 [ 1 4 9 ] [ 1 2 3 [ sq ] tri@ ] unit-test
128 [ [ sq ] tri@ ] must-infer
130 [ 4 ] [ 1 { [ 1 ] [ 2 ] } dispatch sq ] unit-test
132 ! Test traceback accuracy
133 : last-frame ( -- pair )
134 error-continuation get call>> callstack>array 6 head* 3 tail* ;
137 { [ 1 2 [ 3 throw ] call 4 ] [ 1 2 [ 3 throw ] call 4 ] 3 }
139 [ [ 1 2 [ 3 throw ] call 4 ] call ] ignore-errors
144 { [ 1 2 [ 3 throw ] dip 4 ] [ 1 2 [ 3 throw ] dip 4 ] 3 }
146 [ [ 1 2 [ 3 throw ] dip 4 ] call ] ignore-errors
151 { [ 1 2 3 throw [ ] call 4 ] [ 1 2 3 throw [ ] call 4 ] 3 }
153 [ [ 1 2 3 throw [ ] call 4 ] call ] ignore-errors
158 { [ 1 2 3 throw [ ] dip 4 ] [ 1 2 3 throw [ ] dip 4 ] 3 }
160 [ [ 1 2 3 throw [ ] dip 4 ] call ] ignore-errors
165 { [ 1 2 3 throw [ ] [ ] if 4 ] [ 1 2 3 throw [ ] [ ] if 4 ] 3 }
167 [ [ 1 2 3 throw [ ] [ ] if 4 ] call ] ignore-errors
171 [ 10 2 3 4 5 ] [ 1 2 3 4 5 [ 10 * ] 4dip ] unit-test
173 [ 3 -1 5/6 ] [ 1 2 3 4 5 6 [ + ] [ - ] [ / ] 2tri* ] unit-test
175 [ { 1 2 } { 3 4 } { 5 6 } ] [ 1 2 3 4 5 6 [ 2array ] 2tri@ ] unit-test
177 [ t ] [ { } identity-hashcode fixnum? ] unit-test
178 [ 123 ] [ 123 identity-hashcode ] unit-test
179 [ t ] [ f identity-hashcode fixnum? ] unit-test