-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-script.txt
446 lines (416 loc) · 7.89 KB
/
test-script.txt
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# Syntax:
# =======
# * comments start with hash
# * empty lines ignored
# * TEST {any string} - resets the runtime and sets the "current test" string
# * EXPECT {type} {value} - tests if the last result is of a given type and value
# * Any other line is fed directly to the runtime as a source to be executed
# Basic syntax:
# -------------
TEST Evaluate simple literals
true
EXPECT bool true
false
EXPECT bool false
'a'
EXPECT char a
1
EXPECT int 1
+2
EXPECT int 2
-3
EXPECT int -3
1.0
EXPECT real 1
+2.0
EXPECT real 2
-3.0
EXPECT real -3
""
EXPECT string ""
"str"
EXPECT string "str"
"\t"
EXPECT string " "
TEST Compound evaluation
[ 1.0 \"two\"]
EXPECT FAILURE
[ [ 1.0 ] [ \"two\" ] ]
EXPECT FAILURE
[ \"tic\" \"tack\" ]
EXPECT FAILURE
[ { 1 } { 2 3 } ]
EXPECT FAILURE
[]
EXPECT SUCCESS
[ 1 2 ]
EXPECT SUCCESS
[ [ 1 2 ] [ 3 4 ] ]
EXPECT SUCCESS
[ { 1 2 } { 3 4 } ]
EXPECT SUCCESS
{}
EXPECT SUCCESS
{ 1 2 }
EXPECT SUCCESS
{ 1 [] }
EXPECT SUCCESS
TEST Symbol reference
x
EXPECT FAILURE
(do (bind y 3) y)
EXPECT SUCCESS
EXPECT int 3
# Special forms:
# --------------
TEST Special do
(do)
EXPECT FAILURE
(do 1 2 3)
EXPECT int 3
TEST Special bind basic
(bind)
EXPECT FAILURE
(bind x)
EXPECT FAILURE
(bind "x" 1)
EXPECT FAILURE
(bind {} 1.0)
EXPECT FAILURE
(bind { a [] } 1.0 [ 1 2 ])
EXPECT FAILURE
(bind 1 2)
EXPECT FAILURE
(bind [ 1 2 ] [ 2 1 ])
EXPECT FAILURE
(bind { a } [ 1.0 ])
EXPECT FAILURE
(bind { b } { 1 2 })
EXPECT FAILURE
(bind [ c d ] [ 1 ])
EXPECT FAILURE
(bind x 1.0)
EXPECT real 1
(bind y (+ 1 2))
EXPECT int 3
(bind 1.0 1.0)
EXPECT real 1
(bind [ 2 3 ] [ (+ 1 1) 3 ])
EXPECT SUCCESS
(bind "asd" [ 'a' 's' 'd' ])
EXPECT string "asd"
(bind [ 'a' 's' 'd' ] "asd")
EXPECT string "asd"
(bind { e f } { 1 2 })
EXPECT SUCCESS
(bind [ g ] [ 1.0 ])
EXPECT SUCCESS
(do (bind { s _ } { 1.0 2.0 }) s)
EXPECT real 1
(do (bind { _ t } { 1.0 2.0 }) t)
EXPECT real 2
TEST Special match
(match)
EXPECT FAILURE
(match 1)
EXPECT FAILURE
(match 1 (2 2.0) (3 3.0))
EXPECT FAILURE
(match (+ 2 2) (3 'a') (4 'b'))
EXPECT char b
(match "asd" (3 'a') ("asd" 'c'))
EXPECT char c
(match [ 'a' 's' 'd' ] (3 'a') ("asd" 'd'))
EXPECT char d
(match 1 (2 2.0) (3 3.0) (_ 4.0))
EXPECT real 4
(match 1 (2 2.0) (_ 3.0) (1 4.0))
EXPECT real 3
TEST Special boolean operators
(and)
EXPECT FAILURE
(or)
EXPECT FAILURE
(and true)
EXPECT bool true
(and false)
EXPECT bool false
(or true)
EXPECT bool true
(or false)
EXPECT bool false
(and true true)
EXPECT bool true
(and false true)
EXPECT bool false
(or false true)
EXPECT bool true
(or false false)
EXPECT bool false
TEST Special if
(if)
EXPECT FAILURE
(if a)
EXPECT FAILURE
(if a b)
EXPECT FAILURE
(if true 1.0 2.0)
EXPECT real 1
(if false "a" "b")
EXPECT string b
TEST Special pointers basic
(bind x 1)
(bind x^ (ptr x))
(bind y (peek x^))
(poke x^ 2)
x
EXPECT int 2
y
EXPECT int 1
TEST Special pointers manual iteration
(bind vec [ 1 2 3 ])
(bind x^ (begin vec))
(peek x^)
EXPECT int 1
(bind y^ (succ x^))
(peek y^)
EXPECT int 2
(bind z^ (succ y^))
(peek z^)
EXPECT int 3
TEST Special pointers peeking abd poking
(bind v [ 1 2 3 ])
(bind v^ (ptr v))
(bind x 4.0)
(bind x^ (ptr x))
EXPECT SUCCESS
(poke v^ [ 1 2 ])
EXPECT FAILURE
(poke v^ [ 'a' 'b' 'c' ])
EXPECT FAILURE
(poke v^ 1.0)
EXPECT FAILURE
(poke v^ [ 3 2 1 ])
EXPECT SUCCESS
(peek (begin v))
EXPECT int 3
# Built-in-functions:
# -------------------
TEST Arythmetic
(+ 2 -)
EXPECT FAILURE
(- + 2)
EXPECT FAILURE
(+ 2 2)
EXPECT int 4
(/ 2.0 2.0)
EXPECT real 1
(- 2.0 (* 2.0 2.0))
EXPECT real -2
(* 2.0 (+ 2.0 2.0))
EXPECT real 8
(+ (/ 7 2) (% 7 2))
EXPECT int 4
(+ (/ 7.0 2.0) (% 7.0 2.0))
EXPECT real 4.5
(sqrt (+ (* 3.0 3.0) (* 4.0 4.0)))
EXPECT real 5
(- 2.0 2)
EXPECT real 0
(* 2.0 2)
EXPECT real 4
(floor -3.5)
EXPECT int -4
(ceil -3.5)
EXPECT int -3
(round 3.5)
EXPECT int 4
TEST Comparison operators
(eq 2 2)
EXPECT bool true
(eq 12.0 23.0)
EXPECT bool false
(lt 12.0 23.0)
EXPECT bool true
(lt 2 2)
EXPECT bool false
TEST Logic operators
(xor false true)
EXPECT bool true
(xor true true)
EXPECT bool false
(not false)
EXPECT bool true
(not true)
EXPECT bool false
TEST Push front and back
(eq (push_front [] 3) [ 3 ])
EXPECT bool true
(eq (push_front { 2 3 } 1) { 1 2 3 })
EXPECT bool true
(eq (push_back {} 3) { 3 })
EXPECT bool true
(eq (push_back [ 2 3 ] 1) [ 2 3 1 ])
EXPECT bool true
(eq (push_back "" 'a') "a")
EXPECT bool true
(eq (push_back "as" 'd') "asd")
EXPECT bool true
TEST Concatenation
(cat 1 2)
EXPECT FAILURE
(cat [ 1 ] 2)
EXPECT FAILURE
(cat 1 [ 2 ])
EXPECT FAILURE
(cat [ 1.0 ] [ 2 ])
EXPECT FAILURE
(cat [ 1 ] { 2 })
EXPECT FAILURE
(cat { 1 } [ 2 ])
EXPECT FAILURE
(cat [ 1 ] { 2.0 })
EXPECT FAILURE
(eq (cat [] []) [])
EXPECT bool true
(eq (cat {} {}) {})
EXPECT bool true
(eq (cat "" "") "")
EXPECT bool true
(eq (cat [ "" ] []) [ "" ])
EXPECT bool true
(eq (cat { "" } {}) { "" })
EXPECT bool true
(eq (cat "asdf" "") "asdf")
EXPECT bool true
(eq (cat [ 'a' ] [ 'b' 'c' ]) [ 'a' 'b' 'c' ])
EXPECT bool true
(eq (cat { 1 } { 2.0 "three" }) { 1 2.0 "three" })
EXPECT bool true
(eq (cat "a" "sd") "asd")
EXPECT bool true
TEST Length check
(length [])
EXPECT int 0
(length [ 'a' 'b' 'c' ])
EXPECT int 3
(length {})
EXPECT int 0
(length { 1 2.0 "three" })
EXPECT int 3
(length "")
EXPECT int 0
(length 'x')
EXPECT FAILURE
TEST Accessing specific collection element
(at [ 1 ] 0 0)
EXPECT FAILURE
(at {} 1.0)
EXPECT FAILURE
(at 1.0 1)
EXPECT FAILURE
(at [ "alpha" "beta" "gamma" ] -1)
EXPECT FAILURE
(at { "alpha" "beta" "gamma" } 3)
EXPECT FAILURE
(at [ "alpha" "beta" "gamma" ] 300)
EXPECT FAILURE
(at [ 1 2 3 ] 0)
EXPECT int 1
(at { 1 2.0 "three" } 1)
EXPECT real 2
(at "asd" 1)
EXPECT char s
TEST Collection slice
(slice [ 1 2 3 ] -1 0)
EXPECT FAILURE
(slice { 1 2 3 } 1 0)
EXPECT FAILURE
(slice [ 1 2 3 ] 1 4)
EXPECT FAILURE
(eq (slice [ 1 2 3 ] 1 3) [ 2 3 ])
EXPECT bool true
(eq (slice [ 1 2 3 ] 2 2) [])
EXPECT bool true
(eq (slice { 1 2.0 "three"} 1 3) { 2.0 "three" })
EXPECT bool true
(eq (slice "asdf" 1 3) "sd")
EXPECT bool true
(eq (slice { 1 2.0 "three" } 2 2) {})
EXPECT bool true
TEST String formatting
(format "%d%f" { 1 })
EXPECT FAILURE
(format "%d" { 1.0 })
EXPECT FAILURE
(format "%d" { 1 1.0 })
EXPECT FAILURE
(format "%s, %s!" { "Hello" "World" } )
EXPECT string "Hello, World!"
(format "%d%d" { 1 2 })
EXPECT string "12"
TEST Parsing and stringifying
(do (bind { x _ } (parse "2.0")) x)
EXPECT bool true
(do (bind { _ y } (parse "2.0")) y)
EXPECT real 2
(eq { true false } (parse (to_string false)))
EXPECT bool true
(eq { true 1 } (parse (to_string 1)))
EXPECT bool true
(eq { true 2.0 } (parse (to_string 2.0)))
EXPECT bool true
(eq { true '3' } (parse (to_string '3')))
EXPECT bool true
(eq { true { 1 2.0 [ true ] } } (parse (to_string { 1 2.0 [ true ] })))
EXPECT bool true
(eq { true [ { 1 2 } { 3 4 } ] } (parse (to_string [ { 1 2 } { 3 4 } ])))
EXPECT bool true
(do (bind { z _ } (parse "[ { 1 2 } { 3 } ]")) z)
EXPECT bool false
(do (bind { s _ } (parse "[ 1 2 asdf ]")) s)
EXPECT bool false
TEST Simple functions
(bind x 1.0)
(x)
EXPECT FAILURE
(bind sqr (func (x) (* x x)))
(bind select (func (cond x y) (if cond (sqr x) (sqr y))))
(select true 2 3)
EXPECT int 4
(select false 2 3)
EXPECT int 9
TEST Recursive functions
(bind gcd (func (x y) (if (eq y 0) x (gcd y (% x y)) ) ))
(bind lcm (func (x y) (* (/ x (gcd x y)) y ) ))
(gcd 54 24)
EXPECT int 6
(lcm 21 6)
EXPECT int 42
TEST Function with capture
(bind mkmul (func (x) (do (bind lhs x)(func (rhs) (* lhs rhs)))))
(bind doubler (mkmul 2))
(bind tripler (mkmul 3))
(doubler 4)
EXPECT int 8
(tripler 4)
EXPECT int 12
TEST Nested currying
(bind point (func (f g x) (g (f x))))
(bind times2 (* 2))
(bind times4 (point times2 times2))
(bind times8 (point times2 times4))
(times8 3)
EXPECT int 24
TEST Complex call expression
(bind x ((+ 2) 2))
(bind custom_mul (func (x y z) (* (* x y) z)))
(bind y (((custom_mul 1.0) 2.0 ) 3.0))
x
EXPECT int 4
y
EXPECT real 6
TEST Scope stacking
(bind foo (func (x y) (do (bind bar (func (x y z) (if (eq y 0) z (bar x (- y 1) (push_back z (x)))))) (bar x y []))))
(foo (func () (rand_ur 0.0 100.0)) 1)
EXPECT SUCCESS