]> gitweb.factorcode.org Git - factor.git/blob - core/kernel/kernel-tests.factor
8a51d45447a2e88307b4140e08a9a331670f4d0b
[factor.git] / core / kernel / kernel-tests.factor
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 ;
5 IN: kernel.tests
6
7 [ 0 ] [ f size ] unit-test
8 [ t ] [ [ \ = \ = ] all-equal? ] unit-test
9
10 ! Don't leak extra roots if error is thrown
11 [ ] [ 10000 [ [ 3 throw ] ignore-errors ] times ] unit-test
12
13 [ ] [ 10000 [ [ -1 f <array> ] ignore-errors ] times ] unit-test
14
15 ! Make sure we report the correct error on stack underflow
16 [ clear drop ] [ { "kernel-error" 11 f f } = ] must-fail-with
17
18 [ ] [ :c ] unit-test
19
20 [ { } set-retainstack r> ] [ { "kernel-error" 13 f f } = ] must-fail-with
21
22 [ ] [ :c ] unit-test
23
24 : overflow-d 3 overflow-d ;
25
26 [ overflow-d ] [ { "kernel-error" 12 f f } = ] must-fail-with
27
28 [ ] [ :c ] unit-test
29
30 : (overflow-d-alt) 3 ;
31
32 : overflow-d-alt (overflow-d-alt) overflow-d-alt ;
33
34 [ overflow-d-alt ] [ { "kernel-error" 12 f f } = ] must-fail-with
35
36 [ ] [ [ :c ] with-string-writer drop ] unit-test
37
38 : overflow-r 3 >r overflow-r ;
39
40 [ overflow-r ] [ { "kernel-error" 14 f f } = ] must-fail-with
41
42 [ ] [ :c ] unit-test
43
44 [ -7 <byte-array> ] must-fail
45
46 [ 2 3 4 1 ] [ 1 2 3 4 roll ] unit-test
47 [ 1 2 3 4 ] [ 2 3 4 1 -roll ] unit-test
48
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
58
59 [ slip ] must-fail
60 [ ] [ :c ] unit-test
61
62 [ 1 slip ] must-fail
63 [ ] [ :c ] unit-test
64
65 [ 1 2 slip ] must-fail
66 [ ] [ :c ] unit-test
67
68 [ 1 2 3 slip ] must-fail
69 [ ] [ :c ] unit-test
70
71
72 [ 5 ] [ [ 2 2 + ] 1 slip + ] unit-test
73
74 [ [ ] keep ] must-fail
75
76 [ 6 ] [ 2 [ sq ] keep + ] unit-test
77
78 [ [ ] 2keep ] must-fail
79 [ 1 [ ] 2keep ] must-fail
80 [ 3 1 2 ] [ 1 2 [ 2drop 3 ] 2keep ] unit-test
81
82 [ 0 ] [ f [ sq ] [ 0 ] if* ] unit-test
83 [ 4 ] [ 2 [ sq ] [ 0 ] if* ] unit-test
84
85 [ 0 ] [ f [ 0 ] unless* ] unit-test
86 [ t ] [ t [ "Hello" ] unless* ] unit-test
87
88 [ "2\n" ] [ [ 1 2 [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
89 [ "9\n" ] [ [ 3 f [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
90
91 [ f ] [ f (clone) ] unit-test
92 [ -123 ] [ -123 (clone) ] unit-test
93
94 [ 6 2 ] [ 1 2 [ 5 + ] dip ] unit-test
95
96 [ ] [ callstack set-callstack ] unit-test
97
98 [ 3drop datastack ] must-fail
99 [ ] [ :c ] unit-test
100
101 ! Doesn't compile; important
102 : foo 5 + 0 [ ] each ;
103
104 [ drop foo ] must-fail
105 [ ] [ :c ] unit-test
106
107 ! Regression
108 : (loop) ( a b c d -- )
109     >r pick r> swap >r pick r> swap
110     < [ >r >r >r 1+ r> r> r> (loop) ] [ 2drop 2drop ] if ; inline
111
112 : loop ( obj obj -- )
113     H{ } values swap >r dup length swap r> 0 -roll (loop) ;
114
115 [ loop ] must-fail
116
117 ! Discovered on Windows
118 : total-failure-1 "" [ ] map unimplemented ;
119
120 [ total-failure-1 ] must-fail
121
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
125
126 [ 4 ] [ 1 { [ 1 ] [ 2 ] } dispatch sq ] unit-test