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 ;
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" 11 f f } = ] must-fail-with
20 [ 3 [ { } set-retainstack ] dip ] [ { "kernel-error" 13 f f } = ] must-fail-with
24 : overflow-d 3 overflow-d ;
26 [ overflow-d ] [ { "kernel-error" 12 f f } = ] must-fail-with
30 : (overflow-d-alt) 3 ;
32 : overflow-d-alt (overflow-d-alt) overflow-d-alt ;
34 [ overflow-d-alt ] [ { "kernel-error" 12 f f } = ] must-fail-with
36 [ ] [ [ :c ] with-string-writer drop ] unit-test
38 : overflow-r 3 load-local overflow-r ;
40 [ overflow-r ] [ { "kernel-error" 14 f f } = ] must-fail-with
44 [ -7 <byte-array> ] must-fail
46 [ 2 3 4 1 ] [ 1 2 3 4 roll ] unit-test
47 [ 1 2 3 4 ] [ 2 3 4 1 -roll ] unit-test
49 [ 3 ] [ t 3 and ] unit-test
50 [ f ] [ f 3 and ] unit-test
51 [ f ] [ 3 f and ] unit-test
52 [ 4 ] [ 4 6 or ] unit-test
53 [ 6 ] [ f 6 or ] unit-test
54 [ f ] [ 1 2 xor ] unit-test
55 [ 1 ] [ 1 f xor ] unit-test
56 [ 2 ] [ f 2 xor ] unit-test
57 [ f ] [ f f xor ] unit-test
65 [ 1 2 slip ] must-fail
68 [ 1 2 3 slip ] must-fail
72 [ 5 ] [ [ 2 2 + ] 1 slip + ] unit-test
74 [ [ ] keep ] must-fail
76 [ 6 ] [ 2 [ sq ] keep + ] unit-test
78 [ [ ] 2keep ] must-fail
79 [ 1 [ ] 2keep ] must-fail
80 [ 3 1 2 ] [ 1 2 [ 2drop 3 ] 2keep ] unit-test
82 [ 0 ] [ f [ sq ] [ 0 ] if* ] unit-test
83 [ 4 ] [ 2 [ sq ] [ 0 ] if* ] unit-test
85 [ 0 ] [ f [ 0 ] unless* ] unit-test
86 [ t ] [ t [ "Hello" ] unless* ] unit-test
88 [ "2\n" ] [ [ 1 2 [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
89 [ "9\n" ] [ [ 3 f [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
91 [ f ] [ f (clone) ] unit-test
92 [ -123 ] [ -123 (clone) ] unit-test
94 [ 6 2 ] [ 1 2 [ 5 + ] dip ] unit-test
96 [ ] [ callstack set-callstack ] unit-test
98 [ 3drop datastack ] must-fail
101 ! Doesn't compile; important
102 : foo 5 + 0 [ ] each ;
104 [ drop foo ] must-fail
108 : (loop) ( a b c d -- )
109 [ pick ] dip swap [ pick ] dip swap
110 < [ [ 1+ ] 3dip (loop) ] [ 2drop 2drop ] if ; inline
112 : loop ( obj obj -- )
113 H{ } values swap [ dup length swap ] dip 0 -roll (loop) ;
117 ! Discovered on Windows
118 : total-failure-1 "" [ ] map unimplemented ;
120 [ total-failure-1 ] must-fail
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
126 [ 4 ] [ 1 { [ 1 ] [ 2 ] } dispatch sq ] unit-test
128 ! Test traceback accuracy
129 : last-frame ( -- pair )
130 error-continuation get call>> callstack>array 4 head* 2 tail* ;
133 { [ 1 2 [ 3 throw ] call 4 ] 3 }
135 [ [ 1 2 [ 3 throw ] call 4 ] call ] ignore-errors
140 { [ 1 2 [ 3 throw ] dip 4 ] 3 }
142 [ [ 1 2 [ 3 throw ] dip 4 ] call ] ignore-errors
147 { [ 1 2 3 throw [ ] call 4 ] 3 }
149 [ [ 1 2 3 throw [ ] call 4 ] call ] ignore-errors
154 { [ 1 2 3 throw [ ] dip 4 ] 3 }
156 [ [ 1 2 3 throw [ ] dip 4 ] call ] ignore-errors
161 { [ 1 2 3 throw [ ] [ ] if 4 ] 3 }
163 [ [ 1 2 3 throw [ ] [ ] if 4 ] call ] ignore-errors
167 [ 10 2 3 4 5 ] [ 1 2 3 4 5 [ 10 * ] 4dip ] unit-test
169 [ 3 -1 5/6 ] [ 1 2 3 4 5 6 [ + ] [ - ] [ / ] 2tri* ] unit-test
171 [ { 1 2 } { 3 4 } { 5 6 } ] [ 1 2 3 4 5 6 [ 2array ] 2tri@ ] unit-test