This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
/
032check.test
206 lines (153 loc) · 3.66 KB
/
032check.test
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
(test "if handles 0 args"
:valueof (if)
:should be nil)
(test "if handles 1 arg"
:valueof if.3
:should be 3)
(test "if handles 2 args"
:valueof (if 3 4)
:should be 4)
(test "if handles then branch"
:valueof (if 3 4 5)
:should be 4)
(test "if handles else branch"
:valueof (if nil 4 5)
:should be 5)
(test "if handles 3 args"
:valueof (if nil 4 5)
:should be 5)
(test "if handles 4 args"
:valueof (if nil 4 5 6)
:should be 6)
(test "if handles 5 args"
:valueof (if nil 4 nil 6 7)
:should be 7)
(test "if handles :else"
:valueof (if nil 4 :else 6)
:should be 6)
(test "if handles lexical scope"
:valueof (let x 34 (if x))
:should be 34)
(test "if handles dynamic scope"
:valueof (do (= x 34)
(if x 35))
:should be 35)
(test "or handles 0 args"
:valueof or.
:should be nil)
(test "or handles nil arg"
:valueof or.nil
:should be nil)
(test "or handles non-nil arg"
:valueof or.3
:should be 3)
(test "or handles 2 args"
:valueof (or nil 3)
:should be 3)
(test "or handles multiple non-nil args"
:valueof (or 3 4)
:should be 3)
(test "or short-circuits on first non-nil arg"
:valueof (let x nil
(or 3 (= x 4))
x)
:should be nil)
(test "or evals each arg at most once"
:valueof (let x 0
(or (do (= x (+ x 1))
3)
(do (= x (+ x 1))
4))
x)
:should be 1)
(test "or handles lexical scope"
:valueof (do (= x 35)
(let x 3
(or nil x)))
:should be 3)
(test "and handles 0 args"
:valueof and.
:should ~be nil)
(test "and handles nil arg"
:valueof and.nil
:should be nil)
(test "and handles non-nil arg"
:valueof and.3
:should be 3)
(test "and handles 2 args"
:valueof (and nil 3)
:should be nil)
(test "and handles 2 non-nil args"
:valueof (and 3 4)
:should be 4)
(test "and handles lexical scope"
:valueof ((fn(x) (and 3 x 4)) nil)
:should be nil)
(test "and short-circuits"
:valueof (let x 0
(and (= x 3)
nil
(= x 4))
x)
:should be 3)
(test "and handles dynamic scope"
:valueof (do (= x 35)
(and x 36))
:should be 36)
(test "iso handles nils"
:valueof (iso nil 3)
:should be nil)
(test "iso compares nils"
:valueof (iso nil nil)
:should ~be nil)
(test "iso handles ints"
:valueof (iso 3 4)
:should be nil)
(test "iso handles ints - 2"
:valueof (iso 3 3)
:should ~be nil)
(test "iso handles strings"
:valueof (iso "a" "b")
:should be nil)
(test "iso handles strings - 2"
:valueof (iso "a" "a")
:should ~be nil)
(test "iso handles lists"
:valueof (iso list.1 list.2)
:should be nil)
(test "iso handles lists - 2"
:valueof (iso list.1 list.1)
:should ~be nil)
(test "iso handles user-defined types"
:valueof (iso '(type foo 3) '(type foo 3))
:should ~be nil)
(test "match - atom positive"
:valueof (match 3 3)
:should ~be nil)
(test "match - atom negative"
:valueof (match 3 4)
:should be nil)
(test "match - list positive"
:valueof (match '(1 (2 3)) '(1 (2 3)))
:should ~be nil)
(test "match - list negative"
:valueof (match '(2 (2 3)) '(1 (2 3)))
:should be nil)
(test "match treats _ as atom wildcard"
:valueof (match '_ 3)
:should ~be nil)
(test "match - _ positive"
:valueof (match '(1 (_ 3 4)) '(1 (2 3 4)))
:should ~be nil)
(test "match - _ negative"
:valueof (match '(2 (_ 3 4)) '(1 (2 3 4)))
:should be nil)
(test "match - _ matches lists"
:valueof (match '_ '(3))
:should ~be nil)
(test "match - _ matches lists when dotted"
:valueof (match '(1 . _) '(1 2 3))
:should ~be nil)
(test "match treats any sym beginning with _ as wildcard"
:valueof (match '(1 . _x) '(1 2 3))
:should ~be nil)