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 os [ windows? ] [ openbsd? ] bi or [
53 [ overflow-c ] [ { "kernel-error" 14 f f } = ] must-fail-with
56 [ -7 <byte-array> ] must-fail
58 [ 3 ] [ t 3 and ] unit-test
59 [ f ] [ f 3 and ] unit-test
60 [ f ] [ 3 f and ] unit-test
61 [ 4 ] [ 4 6 or ] unit-test
62 [ 6 ] [ f 6 or ] unit-test
63 [ f ] [ 1 2 xor ] unit-test
64 [ 1 ] [ 1 f xor ] unit-test
65 [ 2 ] [ f 2 xor ] unit-test
66 [ f ] [ f f xor ] unit-test
71 [ 1 [ call ] dip ] must-fail
74 [ 1 2 [ call ] dip ] must-fail
77 [ 5 ] [ 1 [ 2 2 + ] dip + ] unit-test
79 [ [ ] keep ] must-fail
81 [ 6 ] [ 2 [ sq ] keep + ] unit-test
83 [ [ ] 2keep ] must-fail
84 [ 1 [ ] 2keep ] must-fail
85 [ 3 1 2 ] [ 1 2 [ 2drop 3 ] 2keep ] unit-test
87 [ 0 ] [ f [ sq ] [ 0 ] if* ] unit-test
88 [ 4 ] [ 2 [ sq ] [ 0 ] if* ] unit-test
90 [ 0 ] [ f [ 0 ] unless* ] unit-test
91 [ t ] [ t [ "Hello" ] unless* ] unit-test
93 [ "2\n" ] [ [ 1 2 [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
94 [ "9\n" ] [ [ 3 f [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
96 [ f ] [ f (clone) ] unit-test
97 [ -123 ] [ -123 (clone) ] unit-test
99 [ 6 2 ] [ 1 2 [ 5 + ] dip ] unit-test
101 [ ] [ callstack set-callstack ] unit-test
103 [ 3drop datastack ] must-fail
106 ! Doesn't compile; important
109 << \ foo t "no-compile" set-word-prop >>
111 [ drop foo ] must-fail
115 : (loop) ( a b c d -- )
116 [ pick ] dip swap [ pick ] dip swap
117 < [ [ 1 + ] 3dip (loop) ] [ 2drop 2drop ] if ; inline recursive
120 H{ } values swap [ dup length swap ] dip [ 0 ] 3dip (loop) ;
124 ! Discovered on Windows
125 : total-failure-1 ( -- a ) "" [ ] map unimplemented ;
127 [ total-failure-1 ] must-fail
129 [ 1 1 2 2 3 3 ] [ 1 2 3 [ dup ] tri@ ] unit-test
130 [ 1 4 9 ] [ 1 2 3 [ sq ] tri@ ] unit-test
131 [ [ sq ] tri@ ] must-infer
133 [ 4 ] [ 1 { [ 1 ] [ 2 ] } dispatch sq ] unit-test
135 ! Test traceback accuracy
136 : last-frame ( -- pair )
137 error-continuation get call>> callstack>array 6 head* 3 tail* ;
140 { [ 1 2 [ 3 throw ] call 4 ] [ 1 2 [ 3 throw ] call 4 ] 3 }
142 [ [ 1 2 [ 3 throw ] call 4 ] call ] ignore-errors
147 { [ 1 2 [ 3 throw ] dip 4 ] [ 1 2 [ 3 throw ] dip 4 ] 3 }
149 [ [ 1 2 [ 3 throw ] dip 4 ] call ] ignore-errors
154 { [ 1 2 3 throw [ ] call 4 ] [ 1 2 3 throw [ ] call 4 ] 3 }
156 [ [ 1 2 3 throw [ ] call 4 ] call ] ignore-errors
161 { [ 1 2 3 throw [ ] dip 4 ] [ 1 2 3 throw [ ] dip 4 ] 3 }
163 [ [ 1 2 3 throw [ ] dip 4 ] call ] ignore-errors
168 { [ 1 2 3 throw [ ] [ ] if 4 ] [ 1 2 3 throw [ ] [ ] if 4 ] 3 }
170 [ [ 1 2 3 throw [ ] [ ] if 4 ] call ] ignore-errors
174 [ 10 2 3 4 5 ] [ 1 2 3 4 5 [ 10 * ] 4dip ] unit-test
176 [ 3 -1 5/6 ] [ 1 2 3 4 5 6 [ + ] [ - ] [ / ] 2tri* ] unit-test
178 [ { 1 2 } { 3 4 } { 5 6 } ] [ 1 2 3 4 5 6 [ 2array ] 2tri@ ] unit-test
180 [ t ] [ { } identity-hashcode fixnum? ] unit-test
181 [ 123 ] [ 123 identity-hashcode ] unit-test
182 [ t ] [ f identity-hashcode fixnum? ] unit-test