forth: Add support for & var-args
[jackhill/mal.git] / forth / misc-tests.fs
CommitLineData
59038a10
C
1require printer.fs
2
3\ === basic testing util === /
4: test=
69972a83 5 2dup m= if
59038a10
C
6 2drop
7 else
8 cr ." assert failed on line " sourceline# .
9 swap cr ." | got " . cr ." | expected " . cr
10 endif ;
11
12\ array function tests
13create za 2 , 6 , 7 , 10 , 15 , 80 , 81 ,
14
157 za 2 array-find -1 test= 0 test=
167 za 6 array-find -1 test= 1 test=
177 za 10 array-find -1 test= 3 test=
187 za 81 array-find -1 test= 6 test=
197 za 12 array-find 0 test= 4 test=
207 za 8 array-find 0 test= 3 test=
217 za 100 array-find 0 test= 7 test=
227 za 1 array-find 0 test= 0 test=
23
2410 new-array
251 swap 0 5 array-insert
262 swap 1 7 array-insert
273 swap 3 12 array-insert
284 swap 4 15 array-insert
295 swap 5 20 array-insert
30
31dup 0 cells + @ 5 test=
32dup 1 cells + @ 7 test=
33dup 2 cells + @ 10 test=
34dup 3 cells + @ 12 test=
35dup 4 cells + @ 15 test=
36dup 5 cells + @ 20 test=
37
38
59038a10
C
39\ Protocol tests
40
41mal-nil
4242 MalInt. mal-nil conj
4310 MalInt. mal-nil conj conj
4420 MalInt. swap conj
4523 MalInt. mal-nil conj conj conj
46pr-str s" (nil (20 (42) 10) 23)" str= -1 test=
9da223a3 47
c05d35e8
C
481500 MalInt. 1500 MalInt. test=
49
50\ MalList tests
69972a83 51
c05d35e8 52here 1 MalInt. , 2 MalInt. , 3 MalInt. , here>MalList
69972a83
C
534 MalInt. swap conj
545 MalInt. swap conj
55pr-str s" (5 4 1 2 3)" str= -1 test=
56
9da223a3
C
57\ map tests
58
69972a83
C
59s" one" MalString. s" one" MalString. test=
60s" one" MalString. s" x" MalString. m= 0 test=
61
62MalMap/Empty
631000 MalInt. 1100 rot assoc
642000 MalInt. 2100 rot assoc
653000 MalInt. 3100 rot assoc
66
67dup 99 2000 MalInt. rot get 2100 test=
68dup 99 4000 MalInt. rot get 99 test=
69drop
9da223a3
C
70
71MalMap/Empty
72s" one" MalString. s" first" MalString. rot assoc
73s" two" MalString. s" second" MalString. rot assoc
74s" three" MalString. s" third" MalString. rot assoc
75
69972a83 76dup 99 s" two" MalString. rot get s" second" MalString. test=
9da223a3
C
77dup 99 s" none" MalString. rot get 99 test=
78drop
79
69972a83
C
8099 MalInt. 10 MalInt. MalMap/Empty get 99 MalInt. test=
81
9da223a3
C
82\ eval tests
83
84require step2_eval.fs
85
86mal-nil
87 1 MalInt. swap conj
88 2 MalInt. swap conj
89 3 MalInt. swap conj
9da223a3 90mal-eval
9da223a3
C
91
92bye