This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
045check.test
282 lines (214 loc) · 5.31 KB
/
045check.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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
(test "if handles 0 args"
:valueof (if)
:should be_false)
(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 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_false)
(test "or handles nil arg"
:valueof or.nil
:should be_false)
(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_false)
(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 "or works with splice"
:valueof (or @'(nil 1))
:should be 1)
(test "or always returns false on failure"
:valueof (or false nil)
:should be false) # might be worth fixing
(test "and handles 0 args"
:valueof (and)
:should be_true)
(test "and handles nil arg"
:valueof and.nil
:should be_false)
(test "and handles non-nil arg"
:valueof and.3
:should be 3)
(test "and handles 2 args"
:valueof (and nil 3)
:should be_false)
(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_false)
(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 "and works with splice"
:valueof (and @'(1 2))
:should be 2)
(test "equality handles nils"
:valueof (nil = 3)
:should be_false)
(test "equality compares nils"
:valueof (nil = nil)
:should be_true)
(test "equality handles ints"
:valueof (3 = 4)
:should be_false)
(test "equality handles ints - 2"
:valueof (3 = 3)
:should be_true)
(test "equality handles strings"
:valueof ("a" = "b")
:should be_false)
(test "equality handles strings - 2"
:valueof ("a" = "a")
:should be_true)
(test "equality handles lists"
:valueof (list.1 = list.2)
:should be_false)
(test "equality handles lists - 2"
:valueof (list.1 = list.1)
:should be_true)
(test "equality handles user-defined types"
:valueof ('(type foo 3) = '(type foo 3))
:should be_true)
(test "equality handles keyword syms"
:valueof (let x :a # also a keyword arg for '=
(x = x))
:should be_true)
(test "default works"
:valueof (ret x nil
(default x 3))
:should be 3)
(test "default shortcuts unnecessary evals"
:valueof (with (x 3 y nil)
(default x :to (y <- 235))
(list x y))
:should be '(3 nil))
(test "default returns assigned value"
:valueof (let x nil
(default x :to 4))
:should be 4)
(test "default returns old value on failure"
:valueof (let x 3
(default x :to 4))
:should be 3)
(test "match? - atom positive"
:valueof (match? 3 3)
:should be_true)
(test "match? - atom negative"
:valueof (match? 3 4)
:should be_false)
(test "match? - list positive"
:valueof (match? '(1 (2 3)) '(1 (2 3)))
:should be_true)
(test "match? - list negative"
:valueof (match? '(2 (2 3)) '(1 (2 3)))
:should be_false)
(test "match? treats _ as atom wildcard"
:valueof (match? '_ 3)
:should be_true)
(test "match? - _ positive"
:valueof (match? '(1 (_ 3 4)) '(1 (2 3 4)))
:should be_true)
(test "match? - _ negative"
:valueof (match? '(2 (_ 3 4)) '(1 (2 3 4)))
:should be_false)
(test "match? - _ matches lists"
:valueof (match? '_ '(3))
:should be_true)
(test "match? - _ matches lists when dotted"
:valueof (match? '(1 ... _) '(1 2 3))
:should be_true)
(test "match? - _ matches nil when dotted"
:valueof (match? '(1 ... _) '(1))
:should be_true)
(test "caselet works"
:valueof (caselet x 'b
'a
1
'b
2
3)
:should be 2)
(test "case works"
:valueof (with (x 1 y 2 z 3 w 2)
(case w
x
34
y
35
z
36))
:should be 35)
(test "case uses predicate"
:valueof (let x '(3)
(case x
cons?
34
(fn(_) 1)
36))
:should be 34)
(test "case recognizes keyword :else"
:valueof (let x '(3)
(case x
~cons?
34
:else
35))
:should be 35)