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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
include tests/common.mk
include types.mk
# treat an expression as a statement
do = $(eval __tmp := $(1))
$(info Testing foreach as a let form)
$(call assert_eq,XbX,$(foreach local_var,b,X$(local_var)X),\
Using foreach as 'let' failed)
$(info Testing type function)
$(call assert_eq,make,$(call _obj_type,xyz),\
(type xyz) is not 'make')
$(call assert_eq,nil,$(call _obj_type,$(__nil)),\
(type $$(__nil)) is not 'nil')
$(call assert_eq,true,$(call _obj_type,$(__true)),\
(type $$(__true)) is not 'true')
$(call assert_eq,false,$(call _obj_type,$(__false)),\
(type $$(__false)) is not 'false')
$(info Testing number? function)
$(call assert_eq,number,$(call _obj_type,$(call number,1)))
$(call assert_eq,number,$(call _obj_type,$(call number,10)))
$(call assert_eq,number,$(call _obj_type,$(call number,12345)))
$(info Testing symbols)
$(call assert_eq,symbol,$(call _obj_type,$(call symbol,abc)),\
(type (symbol abc)) is not 'symbol')
SYM1 := $(call symbol,a sym value)
$(call assert_eq,a sym value,$($(SYM1)_value))
$(call assert_eq,$(__true),$(call symbol?,$(SYM1)))
$(info Testing strings)
$(call assert_eq,string,$(call _obj_type,$(call string,abc)),\
(type (string abc)) is not string)
STR1 := $(call string,a string value)
$(call assert_eq,a string value,$(call str_decode,$($(STR1)_value)))
$(call assert_eq,$(__true),$(call string?,$(STR1)))
$(call assert_eq,14,$(call _count,$(STR1)))
STR2 := $(call string,a string (with parens))
$(call assert_eq,a string (with parens),$(call str_decode,$($(STR2)_value)))
$(call assert_eq,$(__true),$(call string?,$(STR2)))
$(call assert_eq,22,$(call _count,$(STR2)))
$(info Testing strings (subs))
$(call assert_eq,a string (with parens),$(call str_decode,$($(call subs,$(STR2),$(call number,2))_value)))
$(call assert_eq,a string,$(call str_decode,$($(call subs,$(STR2),$(call number,0),$(call number,8))_value)))
$(info Testing strings (str))
$(call assert_eq,a string value - a string (with parens),$(call str_decode,$($(call str,$(STR1) $(call string, - ) $(STR2))_value)))
$(info Testing function objects)
$(call assert_eq,function,$(call _obj_type,$(call _function,abc)),\
(type (function abc)) is not 'function')
FN1 := $(call _function,arg1:'$$(word 1,$$(1))' arg2:'$$(word 2,$$(1))')
$(call assert_eq,$(__true),$(call function?,$(FN1)))
$(call assert_eq,arg1:'A' arg2:'B',$(call apply,$(FN1),$(call list,A B)))
$(info Testing lists)
$(call assert_eq,list,$(call _obj_type,$(call list)),\
(type (list)) is not 'list')
$(info Testing lists (cons))
L1 := $(call cons,P $(call list))
L2 := $(call cons,Q $(L1))
$(call assert_eq,$(__true),$(call list?,$(L1)))
$(call assert_eq,$(__true),$(call list?,$(L2)))
$(call assert_eq,P,$(call sfirst,$(L1)))
$(call assert_eq,2,$(call _count,$(L2)))
$(call assert_eq,Q,$(call sfirst,$(L2)))
$(call assert_eq,P,$(call _nth,$(L2),1))
$(call assert_eq,$(__true),$(call equal?,$(L1) $(call srest,$(L2))))
$(info Testing lists (concat))
L1_2 := $(call concat,$(L1) $(L2))
$(call assert_eq,3,$(call _count,$(L1_2)))
$(call assert_eq,P,$(call sfirst,$(L1_2)))
$(call assert_eq,Q,$(call _nth,$(L1_2),1))
$(call assert_eq,P,$(call _nth,$(L1_2),2))
$(call assert_eq,$(__true),$(call equal?,$(L2) $(call srest,$(L1_2))))
$(info Testing lists (conj))
L3 := $(call _conj!,$(call list),A B)
L4 := $(call _conj!,$(call list),X $(L3))
$(call assert_eq,$(__true),$(call list?,$(L3)),\
(list? $$(L3)))
$(call assert_eq,$(__true),$(call list?,$(L4)),\
(list? $$(L3)))
$(call assert_eq,A,$(call sfirst,$(L3)),\
(sfirst $$(L3)) is not 'A')
$(call assert_eq,X,$(call sfirst,$(L4)),\
(sfirst $$(L4)) is not 'X')
$(call assert_eq,$(__true),$(call list?,$(call _nth,$(L4),1)),\
(_nth $$(L4),1) is not a list)
$(call assert_eq,A,$(call sfirst,$(call _nth,$(L4),1)),\
(first (_nth $$(L4),1)) is not 'A')
$(info Testing hash_maps)
X := $(call _hash_map)
$(call assert_eq,$(__true),$(call hash_map?,$(X)),\
(hash_map? $$(X)))
$(call assert_eq,$(__false),$(call vector?,$(X)),\
(vector? $$(X)))
mykey := $(call _string,a)
$(call assert_not,$(call _get,$(X),a),\
(get $$(X),a))
$(call assert_eq,$(__false),$(call contains?,$(X),$(mykey)),\
(contains? $$(X),a))
$(call do,$(call _assoc!,$(X),a,value of X a))
$(call assert_eq,value of X a,$(call _get,$(X),a),\
(get $$(X),a) is not 'value of Xa')
$(call assert_eq,$(__true),$(call contains?,$(X) $(mykey)),\
(contains? $$(X),a))
Y := $(call _hash_map)
$(call assert_eq,0,$(call _count,$(Y)),\
(_count $$(Y)))
$(call do,$(call _assoc!,$(Y),a,value of Y a))
$(call assert_eq,1,$(call _count,$(Y)),\
(_count $$(Y)))
$(call do,$(call _assoc!,$(Y),b,value of Y b))
$(call assert_eq,2,$(call _count,$(Y)),\
(_count $$(Y)))
$(call assert_eq,value of Y a,$(call _get,$(Y),a),\
(get $$(Y),a) is not 'value of Y a')
$(call assert_eq,value of Y b,$(call _get,$(Y),b),\
(get $$(Y),b) is not 'value of Y b')
$(call assert_eq,value of Y a value of Y b,$(call raw_flat,$(Y),b),\
(raw_flat $(Y)) is not 'value of Y a value of Y b')
$(call do,$(call _assoc!,$(X),b,$(Y)))
$(call assert_eq,2,$(call _count,$(Y),a),\
(_count $$(Y)) should still be 2)
$(call assert_eq,$(__true),$(call hash_map?,$(call _get,$(X),b)),\
(hash_map? (get $$(X),b)))
$(call assert_eq,$(call _get,$(call _get,$(X),b),a),value of Y a,\
(get (get $(X),b),a) is not 'value of Y a')
$(call assert_eq,$(call _get,$(call _get,$(X),b),b),value of Y b,\
(get (get $(X),b),b) is not 'value of Y b')
$(call do,$(call _dissoc!,$(Y),a))
$(call assert_eq,1,$(call _count,$(Y)),\
(_count $$(Y)) should now be 1)
$(call assert_not,$(call _get,$(Y),a),\
(get $$(Y),a))
$(call do,$(call _dissoc!,$(Y),b))
$(call assert_eq,0,$(call _count,$(Y)),\
(_count $$(Y)) should now be 0)
$(call assert_not,$(call _get,$(Y),b),\
(get $$(Y),b))
$(info Testing vectors)
V1 := $(call _conj!,$(call vector),first.vector.value second.vector.value third.vector.value)
$(call assert_eq,$(__true),$(call vector?,$(V1)),\
(vector? $$(V1)))
$(call assert_eq,first.vector.value,$(call _nth,$(V1),0))
$(call assert_eq,second.vector.value,$(call _nth,$(V1),1))
$(call assert_eq,third.vector.value,$(call _nth,$(V1),2))
$(call assert_eq,third.vector.value,$(call slast,$(V1)))
$(call assert_eq,3,$(call _count,$(V1)))
V2 := $(call _conj!,$(call vector),A B C)
$(call assert_eq,3,$(call _count,$(V2)),\
(_count $$(V2)) is not 3)
$(call assert_eq,A B C,$($(V2)_value))
$(call assert_eq,A,$(call sfirst,$(V2)),\
(first $$(V2)) is not 'A')
$(call assert_eq,$(__true),$(call list?,$(call srest,$(V2))),\
(rest $$(V2)) is not a vector)
$(call assert_eq,B C,$($(call srest,$(V2))_value))
$(call assert_eq,B,$(call sfirst,$(call srest,$(V2))),\
(first (rest $$(V2))) is not 'B')
$(call assert_eq,C,$(call sfirst,$(call srest,$(call srest,$(V2)))),\
(first (rest (rest $$(V2)))) is not 'C')
$(call assert_eq,C,$(call _nth,$(V2),2),\
(_nth $$(V2),2) is not 'C')
V2_1 := $(call _conj!,$(V2),$(V1))
$(call assert_eq,4,$(call _count,$(V2_1)),\
(_count $$(V2_1)) is not 4)
$(call assert_eq,C,$(call _nth,$(V2_1),2),\
(_nth $$(V2_1),2) is no longer 'C')
$(call assert_eq,$(__true),$(call vector?,$(call _nth,$(V2_1),3)),\
(_nth $$(V2_1),3) is not a vector)
$(call assert_eq,second.vector.value,$(call _nth,$(call _nth,$(V2_1),3),1),\
(_nth (_nth $$(V2_1),3),1) is not 'second.vector.value')
$(info Testing vectors (rest))
V3 := $(call srest,$(V2_1))
$(call assert_eq,3,$(call _count,$(V3)),\
(_count $$(V3)) is not 3)
$(call assert_eq,B,$(call sfirst,$(V3)),\
(first $$(V3)) is not 'B')
$(call assert_eq,$(__true),$(call vector?,$(call _nth,$(V3),2)),\
(_nth $$(V3),2) is not a vector)
$(call assert_eq,second.vector.value,$(call _nth,$(call _nth,$(V3),2),1),\
(_nth (_nth $$(V3),2),1) is not 'second.vector.value')
$(info Testing vectors (contains?))
$(call assert_eq,$(__true),$(call _contains?,$(V2_1),0),\
(contains? $$(V2_1),0))
$(call assert_eq,,$(call _contains?,$(V2_1),7),\
(contains? $$(V2_1),7))
$(info Testing _apply function)
label_args = $(word 1,$(1))$(word 2,$(1))$(word 3,$(1))$(word 4,$(1))
$(call assert_eq,,$(call _apply,label_args,$(call list)))
$(call assert_eq,A,$(call _apply,label_args,$(call list,A)))
$(call assert_eq,AB,$(call _apply,label_args,$(call list,A B)))
$(call assert_eq,ABCD,$(call _apply,label_args,$(call list,A B C D)))
$(info Testing smap function)
L5 := $(call _conj!,$(call list),$(call number,1) $(call number,2) $(call number,3))
inc = $(call number_plus,$(call number,1) $(1))
$(call assert_eq,(2 3 4),$(call _pr_str,$(call _smap,inc,$(L5))))
inc_func := $(call _function,$$(call number_plus,$$(call number,1) $$(1)))
$(call assert_eq,(2 3 4),$(call _pr_str,$(call smap,$(inc_func) $(L5))))
$(info Testing equal? function)
$(call assert_eq,$(__true),$(call equal?,2 2))
$(call assert_eq,$(__false),$(call equal?,2 3))
$(call assert_eq,$(__false),$(call equal?,2 3))
$(call assert_eq,$(__true),$(call equal?,abc abc))
$(call assert_eq,$(__false),$(call equal?,abc abz))
$(call assert_eq,$(__false),$(call equal?,zbc abc))
$(call assert_eq,$(__true),$(call equal?,$(call string,abc) $(call string,abc)))
$(call assert_eq,$(__false),$(call equal?,$(call string,abc) $(call string,abz)))
$(call assert_eq,$(__false),$(call equal?,$(call string,zbc) $(call string,abc)))
$(call assert_eq,$(__true),$(call equal?,$(call symbol,abc) $(call symbol,abc)))
$(call assert_eq,$(__false),$(call equal?,$(call symbol,abc) $(call symbol,abz)))
$(call assert_eq,$(__false),$(call equal?,$(call symbol,zbc) $(call symbol,abc)))
L6 := $(call _conj!,$(call list),1 2 3)
L7 := $(call _conj!,$(call list),1 2 3)
L8 := $(call _conj!,$(call list),1 2 Z)
L9 := $(call _conj!,$(call list),Z 2 3)
L10 := $(call _conj!,$(call list),1 2)
$(call assert_eq,$(__true),$(call equal?,$(L6) $(L7)))
$(call assert_eq,$(__false),$(call equal?,$(L6) $(L8)))
$(call assert_eq,$(__false),$(call equal?,$(L6) $(L9)))
$(call assert_eq,$(__false),$(call equal?,$(L6) $(L10)))
$(call assert_eq,$(__false),$(call equal?,$(L10) $(L6)))
$(info Testing empty? function)
$(call assert_eq,$(__true),$(call empty?,$(call list)))
$(call assert_eq,$(__false),$(call empty?,$(call list,1)))
$(info Testing ENV (1 level))
env1 := $(call ENV)
$(call assert_eq,,$(call ENV_GET,$(env1),a))
$(call assert_eq,$(env1),$(call ENV_SET,$(env1),a,val_a))
$(call assert_eq,$(env1),$(call ENV_SET,$(env1),b,val_b))
$(call assert_eq,$(env1),$(call ENV_SET,$(env1),=,val_eq))
$(call assert_eq,val_a,$(call ENV_GET,$(env1),a))
$(call assert_eq,val_b,$(call ENV_GET,$(env1),b))
$(call assert_eq,val_eq,$(call ENV_GET,$(env1),=))
$(call assert_eq,hash_map,$(call _obj_type,$(call ENV_FIND,$(env1),a)))
$(call assert_eq,val_a,$(call _get,$(call ENV_FIND,$(env1),a),a))
$(info Testing ENV (2 levels))
env2 := $(call ENV,$(env1))
$(call assert_eq,$(env2),$(call ENV_SET,$(env2),b,val_b2))
$(call assert_eq,$(env2),$(call ENV_SET,$(env2),c,val_c))
$(call assert_eq,$(env1),$(call ENV_FIND,$(env2),a))
$(call assert_eq,$(env2),$(call ENV_FIND,$(env2),b))
$(call assert_eq,$(env2),$(call ENV_FIND,$(env2),c))
$(call assert_eq,val_a,$(call ENV_GET,$(env2),a))
$(call assert_eq,val_b2,$(call ENV_GET,$(env2),b))
$(call assert_eq,val_c,$(call ENV_GET,$(env2),c))
.PHONY: all
all:
@echo "All tests completed"
|