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
8 [ 0 ] [ f size ] unit-test
9 [ t ] [ [ \ = \ = ] all-equal? ] unit-test
11 ! Don't leak extra roots if error is thrown
12 [ ] [ 10000 [ [ 3 throw ] ignore-errors ] times ] unit-test
14 [ ] [ 10000 [ [ -1 f <array> ] ignore-errors ] times ] unit-test
16 ! Make sure we report the correct error on stack underflow
17 [ clear drop ] [ { "kernel-error" 10 f f } = ] must-fail-with
21 [ 3 [ { } set-retainstack ] dip ] [ { "kernel-error" 12 f f } = ] must-fail-with
25 : overflow-d ( -- ) 3 overflow-d ;
27 : (overflow-d-alt) ( -- n ) 3 ;
29 : overflow-d-alt ( -- ) (overflow-d-alt) overflow-d-alt ;
31 : overflow-r ( -- ) 3 load-local overflow-r ;
34 { overflow-d (overflow-d-alt) overflow-d-alt overflow-r }
35 [ t "no-compile" set-word-prop ] each
38 [ overflow-d ] [ { "kernel-error" 11 f f } = ] must-fail-with
42 [ overflow-d-alt ] [ { "kernel-error" 11 f f } = ] must-fail-with
44 [ ] [ [ :c ] with-string-writer drop ] unit-test
46 [ overflow-r ] [ { "kernel-error" 13 f f } = ] must-fail-with
50 : overflow-c ( -- ) overflow-c overflow-c ;
52 ! The VM cannot recover from callstack overflow on Windows,
53 ! because no facility exists to run memory protection
54 ! fault handlers on an alternate callstack.
56 [ overflow-c ] [ { "kernel-error" 15 f f } = ] must-fail-with
59 [ -7 <byte-array> ] must-fail
61 [ 3 ] [ t 3 and ] unit-test
62 [ f ] [ f 3 and ] unit-test
63 [ f ] [ 3 f and ] unit-test
64 [ 4 ] [ 4 6 or ] unit-test
65 [ 6 ] [ f 6 or ] unit-test
66 [ f ] [ 1 2 xor ] unit-test
67 [ 1 ] [ 1 f xor ] unit-test
68 [ 2 ] [ f 2 xor ] unit-test
69 [ f ] [ f f xor ] unit-test
74 [ 1 [ call ] dip ] must-fail
77 [ 1 2 [ call ] dip ] must-fail
80 [ 5 ] [ 1 [ 2 2 + ] dip + ] unit-test
82 [ [ ] keep ] must-fail
84 [ 6 ] [ 2 [ sq ] keep + ] unit-test
86 [ [ ] 2keep ] must-fail
87 [ 1 [ ] 2keep ] must-fail
88 [ 3 1 2 ] [ 1 2 [ 2drop 3 ] 2keep ] unit-test
90 [ 0 ] [ f [ sq ] [ 0 ] if* ] unit-test
91 [ 4 ] [ 2 [ sq ] [ 0 ] if* ] unit-test
93 [ 0 ] [ f [ 0 ] unless* ] unit-test
94 [ t ] [ t [ "Hello" ] unless* ] unit-test
96 [ "2\n" ] [ [ 1 2 [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
97 [ "9\n" ] [ [ 3 f [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
99 [ f ] [ f (clone) ] unit-test
100 [ -123 ] [ -123 (clone) ] unit-test
102 [ 6 2 ] [ 1 2 [ 5 + ] dip ] unit-test
104 [ ] [ callstack set-callstack ] unit-test
106 [ 3drop datastack ] must-fail
109 ! Doesn't compile; important
112 << \ foo t "no-compile" set-word-prop >>
114 [ drop foo ] must-fail
118 : (loop) ( a b c d -- )
119 [ pick ] dip swap [ pick ] dip swap
120 < [ [ 1 + ] 3dip (loop) ] [ 2drop 2drop ] if ; inline recursive
123 H{ } values swap [ dup length swap ] dip [ 0 ] 3dip (loop) ;
127 ! Discovered on Windows
128 : total-failure-1 ( -- a ) "" [ ] map unimplemented ;
130 [ total-failure-1 ] must-fail
132 [ 1 1 2 2 3 3 ] [ 1 2 3 [ dup ] tri@ ] unit-test
133 [ 1 4 9 ] [ 1 2 3 [ sq ] tri@ ] unit-test
134 [ [ sq ] tri@ ] must-infer
136 [ 4 ] [ 1 { [ 1 ] [ 2 ] } dispatch sq ] unit-test
138 ! Test traceback accuracy
139 : last-frame ( -- pair )
140 error-continuation get call>> callstack>array 6 head* 3 tail* ;
143 { [ 1 2 [ 3 throw ] call 4 ] [ 1 2 [ 3 throw ] call 4 ] 3 }
145 [ [ 1 2 [ 3 throw ] call 4 ] call ] ignore-errors
150 { [ 1 2 [ 3 throw ] dip 4 ] [ 1 2 [ 3 throw ] dip 4 ] 3 }
152 [ [ 1 2 [ 3 throw ] dip 4 ] call ] ignore-errors
157 { [ 1 2 3 throw [ ] call 4 ] [ 1 2 3 throw [ ] call 4 ] 3 }
159 [ [ 1 2 3 throw [ ] call 4 ] call ] ignore-errors
164 { [ 1 2 3 throw [ ] dip 4 ] [ 1 2 3 throw [ ] dip 4 ] 3 }
166 [ [ 1 2 3 throw [ ] dip 4 ] call ] ignore-errors
171 { [ 1 2 3 throw [ ] [ ] if 4 ] [ 1 2 3 throw [ ] [ ] if 4 ] 3 }
173 [ [ 1 2 3 throw [ ] [ ] if 4 ] call ] ignore-errors
177 [ 10 2 3 4 5 ] [ 1 2 3 4 5 [ 10 * ] 4dip ] unit-test
179 [ 3 -1 5/6 ] [ 1 2 3 4 5 6 [ + ] [ - ] [ / ] 2tri* ] unit-test
181 [ { 1 2 } { 3 4 } { 5 6 } ] [ 1 2 3 4 5 6 [ 2array ] 2tri@ ] unit-test
183 [ t ] [ { } identity-hashcode fixnum? ] unit-test
184 [ 123 ] [ 123 identity-hashcode ] unit-test
185 [ t ] [ f identity-hashcode fixnum? ] unit-test