-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.tcl
executable file
·231 lines (155 loc) · 5.4 KB
/
test.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/expect
spawn ./stubforth
sleep 0.1
set timeout 0
send "decimal \n"
expect plzflushkthx
expect *
set timeout 1
proc test {tx rx} {
send "$tx\n"
expect \
timeout { error timeout } \
-re abort { error abort } \
-re $rx
send_user " \[OK\]\n"
}
set true {-1 $}
set false {\s0 $}
set name {stubforth [0-9a-f]+}
test "hi\n" $name
send_user "the following should abort...\n"
send "should-abort\n"
expect {
timeout { error }
-re abort.*
}
send ".\n"
expect {
timeout { error }
-re abort.*
}
test "85 1 + ." {86 $}
send "hex\n"
test "1 2 3 4 5 * + * + ." {2f $}
test "key A ." {41 $}
test "1 2 3 4 5 6 7 8 9 swap mod + * xor or swap - hex ." {32 $}
test "1 2 3 4 5 6 7 8 9 << >> << swap / ." {99 $}
test "1234 2345 max 9999 min 11 + ." {2356 $}
test "55 emit 1234 2345 dup = 30 + emit = 30 + emit " {U10$}
test "55 emit 1234 2345 swap dup < 30 + emit < 30 + emit " {U01$}
test "55 emit 8 2345 dup dup and 0= 30 + emit and 0= 30 + emit " {U01$}
send "decimal : testsuite-marker 85 emit ;\n"
test "testsuite-marker" {U$}
send "decimal : ifelsethen 85 emit if 64 emit else 65 emit then 85 emit ;\n"
test "1 ifelsethen" U@U
test "0 ifelsethen" UAU
send ": fib dup 0= if else dup 1 = if else 1 - dup recurse swap 1 - recurse + then then ;\n"
test "20 fib ." 6765
send ": gcd dup if tuck mod recurse else drop then ;\n"
test "decimal 11111 12341 gcd ." {41 $}
send "hex\n"
send ": tloop begin 1 - dup 8 < if exit then again ;\n"
test "100 tloop ." {7 $}
send ": tuntil begin 1 - dup 197 < until ;\n"
test " 999 tuntil ." {196 $}
send "decimal\n"
send ": twhile 85 emit begin 64 emit 1 - dup 10 > while 65 emit repeat 85 emit ;\n"
test "16 twhile" {U@A@A@A@A@A@U$}
send "hex\n"
test "variable foo F6F 1 + foo ! foo ?" {f70 $}
test "2ff 1 + constant foo foo ." {300 $}
test "word fubar type" {fubar$}
send "0 variable scratch 10 allot\n"
test "scratch 10 55 fill scratch 8 + c@ 11 + ." {66 $}
test "8 base c! 777 1 + ." {1000 $}
send "decimal "
test "word \[ find drop immediatep ." $true
test "word : find drop immediatep ." $false
test "' hi execute" $name
test {: foo ['] hi execute ; foo} $name
test " -3 3- * ." {9 $}
test " -3 3 * ." {-9 $}
send ": foo 666 throw ; "
send {: bar ['] foo catch 666 = if 85 emit else 65 then ; }
test bar {U$}
test ": foo 99 13 /mod . . ; foo" {7 8 $}
test "create foo 66 , foo @ 2 * . ;" {132 $}
send ": cst <builds , does> @ ;\n"
test "666 cst moo moo 1+ ." {667 $}
test ": t 7 8 2dup . . . . ; t" {8 7 8 7 $}
test ": t 1 2 3 4 2over . . . . . . ; t" {2 1 4 3 2 1 $}
test ": t 1 2 3 4 2swap . . . . ; t" {2 1 4 3 $}
send "abort\n" ;
expect -re abort.*
test "depth 1 2 3 666 5 .s" {#6 0 1 2 3 666 5}
send ": w2345678 ;\n"
test "here word w2345678 find drop drop here = ." {1 $}
test {" fox" " quick brown " type type} {quick brown fox$}
test {: t ," lazy dog" ," jumps over the " type type ; t} {jumps over the lazy dog$}
test {decimal : t 85 emit ." moo" 85 emit ; t} {UmooU$}
test {: t 1 if ." moo" else ." bar" then ; t} {moo$}
send {: t case 0 of ." looks like zero" endof 1 of ." looks like one" endof 2 of ." looks like two" endof ." i dunno" endcase lf ; }
test "4 t" {i dunno}
test "1 t" {looks like one}
send ": t postpone if ; immediate\n"
test {: t2 1 t ." moo" else ." bar" then ; t2} {moo$}
send ": t postpone hi ; immediate\n"
test {: t2 t ; t2} $name
test { " foo" " barz" compare .} {1 $}
test { " 999" " ba" compare .} {-1 $}
test { " hmm" " hmm" compare .} {0 $}
test { here " foo" drop" here = .} {1 $}
# send {here }
# test { 1 [if] 85 emit bl [else] 64 emit bl [then] } {U $}
# test { 0 [if] 85 emit bl [else] 64 emit bl [then] } {@ $}
# test { here = . } { 1$}
test {: t 85 emit try 666 throw catch> 1+ . endtry 64 emit ; t } {U667 @$}
test {: t 125 try 666 1 throw catch> drop endtry 1+ . ; t } {126 $}
test {: t 125 try 666 catch> drop endtry 1+ . ; t } {667 $}
test {.( moo)} {moo}
test { " asdf" " moo" over 3 move type } {moof$}
test { 64 1 putchar call 85 1 putchar call } {@U$}
test { " 667 1 + 0 redirect ! " redirect ! . } {668 $}
test { " 668 1 + . " evaluate } {669 $}
test { : x ?dup if 65 emit 1- restart then ; 666 4 64 emit x 85 emit . } {@AAAAU666 $}
test { -2 666 u< . } {0 $}
test { -2 666 < . } {1 $}
test { -2 666 u> -1 666 > <> 0<> . } {1 $}
# send " : within ( n1|u1 n2|u2 n3|u3 -- flag ) over - >r - r> u< ; "
test { 0 0 0 within . } {0 $}
test { 2 6 5 within . } {1 $}
test { 2 6 2 within . } {0 $}
test { 2 6 6 within . } {0 $}
test { -6 -2 -4 within . } {1 $}
test { -2 -6 -4 within . } {0 $}
test { -6 -2 -2 within . } {0 $}
test { -6 -2 -6 within . } {0 $}
test { -1 2 1 within . } {1 $}
test { -1 2 2 within . } {0 $}
test { -1 2 -1 within . } {0 $}
test { 0 -1 1 within . } {1 $}
test { marker oblivious : oblivion 666 . ; oblivion } {666 $}
send { oblivious oblivion
}
expect {
timeout { error }
-re abort:.*$
}
test { 5 7 2constant twocon twocon twocon . . . . } {7 5 7 5 $}
test { 1 1 <> . } {0 $}
test { 1 2 3 4 3 roll . . . . } {1 4 3 2 $}
test { 1 2 3 4 0 roll . . . . } {4 3 2 1 $}
test { variable bitfiddle
aa bitfiddle ! bitfiddle ? } {aa $}
test { 50 bitfiddle |! bitfiddle ?
5a bitfiddle &! bitfiddle ?
a5 bitfiddle &! bitfiddle ?
aa bitfiddle ^! bitfiddle ?
a5 bitfiddle ^! bitfiddle ?
} {fa 5a 0 aa f $}
test { a0 bitfiddle |! bitfiddle ?
55 bitfiddle ~&! bitfiddle ?
} {af aa $}
send "forget testsuite-marker bye\n"
interact