Commit | Line | Data |
---|---|---|
59038a10 C |
1 | require printer.fs |
2 | ||
3 | \ === basic testing util === / | |
4 | : test= | |
5 | 2dup = if | |
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 | |
13 | create za 2 , 6 , 7 , 10 , 15 , 80 , 81 , | |
14 | ||
15 | 7 za 2 array-find -1 test= 0 test= | |
16 | 7 za 6 array-find -1 test= 1 test= | |
17 | 7 za 10 array-find -1 test= 3 test= | |
18 | 7 za 81 array-find -1 test= 6 test= | |
19 | 7 za 12 array-find 0 test= 4 test= | |
20 | 7 za 8 array-find 0 test= 3 test= | |
21 | 7 za 100 array-find 0 test= 7 test= | |
22 | 7 za 1 array-find 0 test= 0 test= | |
23 | ||
24 | 10 new-array | |
25 | 1 swap 0 5 array-insert | |
26 | 2 swap 1 7 array-insert | |
27 | 3 swap 3 12 array-insert | |
28 | 4 swap 4 15 array-insert | |
29 | 5 swap 5 20 array-insert | |
30 | ||
31 | dup 0 cells + @ 5 test= | |
32 | dup 1 cells + @ 7 test= | |
33 | dup 2 cells + @ 10 test= | |
34 | dup 3 cells + @ 12 test= | |
35 | dup 4 cells + @ 15 test= | |
36 | dup 5 cells + @ 20 test= | |
37 | ||
38 | ||
39 | \ MalType tests | |
40 | ||
41 | MalList new MalList new = 0 test= | |
42 | ||
43 | MalList new dup MalList/car 5 swap ! MalList/car @ 5 test= | |
44 | ||
45 | ||
46 | \ Protocol tests | |
47 | ||
48 | mal-nil | |
49 | 42 MalInt. mal-nil conj | |
50 | 10 MalInt. mal-nil conj conj | |
51 | 20 MalInt. swap conj | |
52 | 23 MalInt. mal-nil conj conj conj | |
53 | pr-str s" (nil (20 (42) 10) 23)" str= -1 test= |