skeem 0.0.23 → 0.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +11 -6
- data/lib/skeem/datum_dsl.rb +139 -0
- data/lib/skeem/element_visitor.rb +91 -0
- data/lib/skeem/grammar.rb +31 -8
- data/lib/skeem/interpreter.rb +1 -1
- data/lib/skeem/primitive/primitive_builder.rb +47 -37
- data/lib/skeem/runtime.rb +28 -4
- data/lib/skeem/s_expr_builder.rb +64 -25
- data/lib/skeem/s_expr_nodes.rb +81 -327
- data/lib/skeem/skm_compound_datum.rb +118 -0
- data/lib/skeem/skm_element.rb +85 -0
- data/lib/skeem/skm_expression.rb +7 -0
- data/lib/skeem/skm_simple_datum.rb +132 -0
- data/lib/skeem/skm_unary_expression.rb +107 -0
- data/lib/skeem/standard/base.skm +3 -3
- data/lib/skeem/tokenizer.rb +8 -1
- data/lib/skeem/version.rb +1 -1
- data/spec/skeem/datum_dsl_spec.rb +191 -0
- data/spec/skeem/element_visitor_spec.rb +170 -0
- data/spec/skeem/interpreter_spec.rb +126 -36
- data/spec/skeem/primitive/primitive_builder_spec.rb +48 -36
- data/spec/skeem/runtime_spec.rb +28 -2
- data/spec/skeem/s_expr_nodes_spec.rb +15 -277
- data/spec/skeem/skm_compound_datum_spec.rb +132 -0
- data/spec/skeem/skm_element_spec.rb +50 -0
- data/spec/skeem/skm_simple_datum_spec.rb +233 -0
- data/spec/skeem/skm_unary_expression_spec.rb +201 -0
- data/spec/skeem/tokenizer_spec.rb +7 -35
- metadata +21 -3
- data/lib/skeem/convertible.rb +0 -23
@@ -39,7 +39,7 @@ module Skeem
|
|
39
39
|
samples.each do |source, predicted|
|
40
40
|
result = subject.run(source)
|
41
41
|
expect(result).to be_kind_of(SkmBoolean)
|
42
|
-
expect(result
|
42
|
+
expect(result).to eq(predicted)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -54,7 +54,7 @@ module Skeem
|
|
54
54
|
samples.each do |source, predicted|
|
55
55
|
result = subject.run(source)
|
56
56
|
expect(result).to be_kind_of(SkmInteger)
|
57
|
-
expect(result
|
57
|
+
expect(result).to eq(predicted)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -69,7 +69,7 @@ module Skeem
|
|
69
69
|
samples.each do |source, predicted|
|
70
70
|
result = subject.run(source)
|
71
71
|
expect(result).to be_kind_of(SkmReal)
|
72
|
-
expect(result
|
72
|
+
expect(result).to eq(predicted)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -80,7 +80,7 @@ module Skeem
|
|
80
80
|
samples.each do |source, predicted|
|
81
81
|
result = subject.run(source)
|
82
82
|
expect(result).to be_kind_of(SkmString)
|
83
|
-
expect(result
|
83
|
+
expect(result).to eq(predicted)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -95,8 +95,8 @@ module Skeem
|
|
95
95
|
[SkmString, 'Sat']
|
96
96
|
]
|
97
97
|
predictions.each_with_index do |(type, value), index|
|
98
|
-
expect(result.
|
99
|
-
expect(result.
|
98
|
+
expect(result.members[index]).to be_kind_of(type)
|
99
|
+
expect(result.members[index]).to eq(value)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end # context
|
@@ -116,7 +116,7 @@ SKEEM
|
|
116
116
|
result = subject.run(source)
|
117
117
|
end_result = result.last
|
118
118
|
expect(end_result).to be_kind_of(SkmInteger)
|
119
|
-
expect(end_result
|
119
|
+
expect(end_result).to eq(28)
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'should implement the simple conditional form' do
|
@@ -126,7 +126,7 @@ SKEEM
|
|
126
126
|
]
|
127
127
|
checks.each do |(skeem_expr, expectation)|
|
128
128
|
result = subject.run(skeem_expr)
|
129
|
-
expect(result
|
129
|
+
expect(result).to eq(expectation)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
@@ -137,7 +137,7 @@ SKEEM
|
|
137
137
|
]
|
138
138
|
checks.each do |(skeem_expr, expectation)|
|
139
139
|
result = subject.run(skeem_expr)
|
140
|
-
expect(result
|
140
|
+
expect(result).to eq(expectation)
|
141
141
|
end
|
142
142
|
source = <<-SKEEM
|
143
143
|
; Example from R7RS section 4.1.5
|
@@ -146,7 +146,7 @@ SKEEM
|
|
146
146
|
(+ 3 2))
|
147
147
|
SKEEM
|
148
148
|
result = subject.run(source)
|
149
|
-
expect(result
|
149
|
+
expect(result).to eq(1)
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'should implement the quotation of constant literals' do
|
@@ -162,7 +162,7 @@ SKEEM
|
|
162
162
|
]
|
163
163
|
checks.each do |(skeem_expr, expectation)|
|
164
164
|
result = subject.run(skeem_expr)
|
165
|
-
expect(result
|
165
|
+
expect(result).to eq(expectation)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -176,8 +176,8 @@ SKEEM
|
|
176
176
|
[SkmIdentifier, 'c']
|
177
177
|
]
|
178
178
|
predictions.each_with_index do |(type, value), index|
|
179
|
-
expect(result.
|
180
|
-
expect(result.
|
179
|
+
expect(result.members[index]).to be_kind_of(type)
|
180
|
+
expect(result.members[index]).to eq(value)
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
@@ -192,13 +192,13 @@ SKEEM
|
|
192
192
|
]
|
193
193
|
predictions.each_with_index do |(type, value), index|
|
194
194
|
expect(result.members[index]).to be_kind_of(type)
|
195
|
-
expect(result.members[index]
|
195
|
+
expect(result.members[index]).to eq(value)
|
196
196
|
end
|
197
|
-
|
197
|
+
|
198
198
|
source = "'()"
|
199
199
|
result = subject.run(source)
|
200
200
|
expect(result).to be_kind_of(SkmList)
|
201
|
-
expect(result).to
|
201
|
+
expect(result).to be_null
|
202
202
|
end
|
203
203
|
|
204
204
|
it 'should implement the lambda function with one arg' do
|
@@ -212,11 +212,11 @@ SKEEM
|
|
212
212
|
procedure = subject.fetch('abs').expression
|
213
213
|
expect(procedure.arity).to eq(1)
|
214
214
|
result = subject.run('(abs -3)')
|
215
|
-
expect(result
|
215
|
+
expect(result).to eq(3)
|
216
216
|
result = subject.run('(abs 0)')
|
217
|
-
expect(result
|
217
|
+
expect(result).to eq(0)
|
218
218
|
result = subject.run('(abs 3)')
|
219
|
-
expect(result
|
219
|
+
expect(result).to eq(3)
|
220
220
|
end
|
221
221
|
|
222
222
|
it 'should implement the lambda function with two args' do
|
@@ -230,11 +230,11 @@ SKEEM
|
|
230
230
|
procedure = subject.fetch('min').expression
|
231
231
|
expect(procedure.arity).to eq(2)
|
232
232
|
result = subject.run('(min 1 2)')
|
233
|
-
expect(result
|
233
|
+
expect(result).to eq(1)
|
234
234
|
result = subject.run('(min 2 1)')
|
235
|
-
expect(result
|
235
|
+
expect(result).to eq(1)
|
236
236
|
result = subject.run('(min 2 2)')
|
237
|
-
expect(result
|
237
|
+
expect(result).to eq(2)
|
238
238
|
end
|
239
239
|
|
240
240
|
it 'should implement recursive functions' do
|
@@ -253,7 +253,7 @@ SKEEM
|
|
253
253
|
it 'should accept calls to anonymous procedures' do
|
254
254
|
source = '((lambda (x) (+ x x)) 4)'
|
255
255
|
result = subject.run(source)
|
256
|
-
expect(result
|
256
|
+
expect(result).to eq(8)
|
257
257
|
end
|
258
258
|
|
259
259
|
it 'should support procedures with variable number of arguments' do
|
@@ -270,8 +270,8 @@ SKEEM
|
|
270
270
|
result = subject.run(source)
|
271
271
|
expect(result).to be_kind_of(SkmList)
|
272
272
|
expect(result.length).to eq(2)
|
273
|
-
expect(result.head
|
274
|
-
expect(result.last
|
273
|
+
expect(result.head).to eq(5)
|
274
|
+
expect(result.last).to eq(6)
|
275
275
|
end
|
276
276
|
|
277
277
|
it 'should implement the compact define + lambda syntax' do
|
@@ -297,17 +297,107 @@ SKEEM
|
|
297
297
|
end
|
298
298
|
end # context
|
299
299
|
|
300
|
+
context 'Quasiquotation:' do
|
301
|
+
it 'should implement the quasiquotation of constant literals' do
|
302
|
+
checks = [
|
303
|
+
['(quasiquote a)', 'a'],
|
304
|
+
['(quasiquote 145932)', 145932],
|
305
|
+
['(quasiquote "abc")', 'abc'],
|
306
|
+
['(quasiquote #t)', true],
|
307
|
+
['`a', 'a'],
|
308
|
+
['`145932', 145932],
|
309
|
+
['`"abc"', 'abc'],
|
310
|
+
['`#t', true]
|
311
|
+
]
|
312
|
+
checks.each do |(skeem_expr, expectation)|
|
313
|
+
result = subject.run(skeem_expr)
|
314
|
+
expect(result).to eq(expectation)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'should implement the quasiquotation of vectors' do
|
319
|
+
source = '(quasiquote #(a b c))'
|
320
|
+
result = subject.run(source)
|
321
|
+
expect(result).to be_kind_of(SkmVector)
|
322
|
+
predictions = [
|
323
|
+
[SkmIdentifier, 'a'],
|
324
|
+
[SkmIdentifier, 'b'],
|
325
|
+
[SkmIdentifier, 'c']
|
326
|
+
]
|
327
|
+
predictions.each_with_index do |(type, value), index|
|
328
|
+
expect(result.members[index]).to be_kind_of(type)
|
329
|
+
expect(result.members[index]).to eq(value)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'should implement the quasiquotation of lists' do
|
334
|
+
source = '(quasiquote (+ 1 2))'
|
335
|
+
result = subject.run(source)
|
336
|
+
expect(result).to be_kind_of(SkmList)
|
337
|
+
predictions = [
|
338
|
+
[SkmIdentifier, '+'],
|
339
|
+
[SkmInteger, 1],
|
340
|
+
[SkmInteger, 2]
|
341
|
+
]
|
342
|
+
predictions.each_with_index do |(type, value), index|
|
343
|
+
expect(result.members[index]).to be_kind_of(type)
|
344
|
+
expect(result.members[index]).to eq(value)
|
345
|
+
end
|
346
|
+
|
347
|
+
source = "`()"
|
348
|
+
result = subject.run(source)
|
349
|
+
expect(result).to be_kind_of(SkmList)
|
350
|
+
expect(result).to be_null
|
351
|
+
end
|
352
|
+
|
353
|
+
it 'should implement the unquote of lists' do
|
354
|
+
source = '`(list ,(+ 1 2) 4)'
|
355
|
+
result = subject.run(source)
|
356
|
+
expect(result).to be_kind_of(SkmList)
|
357
|
+
predictions = [
|
358
|
+
[SkmIdentifier, 'list'],
|
359
|
+
[SkmInteger, 3],
|
360
|
+
[SkmInteger, 4]
|
361
|
+
]
|
362
|
+
predictions.each_with_index do |(type, value), index|
|
363
|
+
expect(result.members[index]).to be_kind_of(type)
|
364
|
+
expect(result.members[index]).to eq(value)
|
365
|
+
end
|
366
|
+
|
367
|
+
source = "`()"
|
368
|
+
result = subject.run(source)
|
369
|
+
expect(result).to be_kind_of(SkmList)
|
370
|
+
expect(result).to be_null
|
371
|
+
end
|
372
|
+
=begin
|
373
|
+
`(+ 2 ,(* 3 4)) (+ 2 12)
|
374
|
+
`(a b (,(+ 2 3) c) d) (a b (5 c) d)
|
375
|
+
`(a b ,(reverse '(c d e)) f g) (a b (e d c) f g)
|
376
|
+
(let ([a 1] [b 2])
|
377
|
+
`(,a . ,b)) (1 . 2)
|
378
|
+
|
379
|
+
`(+ ,@(cdr '(* 2 3))) (+ 2 3)
|
380
|
+
`(a b ,@(reverse '(c d e)) f g) (a b e d c f g)
|
381
|
+
(let ([a 1] [b 2])
|
382
|
+
`(,a ,@b)) (1 . 2)
|
383
|
+
`#(,@(list 1 2 3)) #(1 2 3)
|
384
|
+
|
385
|
+
'`,(cons 'a 'b) `,(cons 'a 'b)
|
386
|
+
`',(cons 'a 'b) '(a . b)
|
387
|
+
=end
|
388
|
+
end # context
|
389
|
+
|
300
390
|
context 'Built-in primitive procedures' do
|
301
391
|
it 'should implement the division of numbers' do
|
302
392
|
result = subject.run('(/ 24 3)')
|
303
393
|
expect(result).to be_kind_of(SkmInteger)
|
304
|
-
expect(result
|
394
|
+
expect(result).to eq(8)
|
305
395
|
end
|
306
396
|
|
307
397
|
it 'should handle arithmetic expressions' do
|
308
398
|
result = subject.run('(+ (* 2 100) (* 1 10))')
|
309
399
|
expect(result).to be_kind_of(SkmInteger)
|
310
|
-
expect(result
|
400
|
+
expect(result).to eq(210)
|
311
401
|
end
|
312
402
|
end # context
|
313
403
|
|
@@ -323,7 +413,7 @@ SKEEM
|
|
323
413
|
]
|
324
414
|
checks.each do |(skeem_expr, expectation)|
|
325
415
|
result = subject.run(skeem_expr)
|
326
|
-
expect(result
|
416
|
+
expect(result).to eq(expectation)
|
327
417
|
end
|
328
418
|
end
|
329
419
|
|
@@ -338,7 +428,7 @@ SKEEM
|
|
338
428
|
]
|
339
429
|
checks.each do |(skeem_expr, expectation)|
|
340
430
|
result = subject.run(skeem_expr)
|
341
|
-
expect(result
|
431
|
+
expect(result).to eq(expectation)
|
342
432
|
end
|
343
433
|
end
|
344
434
|
|
@@ -353,7 +443,7 @@ SKEEM
|
|
353
443
|
]
|
354
444
|
checks.each do |(skeem_expr, expectation)|
|
355
445
|
result = subject.run(skeem_expr)
|
356
|
-
expect(result
|
446
|
+
expect(result).to eq(expectation)
|
357
447
|
end
|
358
448
|
end
|
359
449
|
|
@@ -368,7 +458,7 @@ SKEEM
|
|
368
458
|
]
|
369
459
|
checks.each do |(skeem_expr, expectation)|
|
370
460
|
result = subject.run(skeem_expr)
|
371
|
-
expect(result
|
461
|
+
expect(result).to eq(expectation)
|
372
462
|
end
|
373
463
|
end
|
374
464
|
|
@@ -381,7 +471,7 @@ SKEEM
|
|
381
471
|
]
|
382
472
|
checks.each do |(skeem_expr, expectation)|
|
383
473
|
result = subject.run(skeem_expr)
|
384
|
-
expect(result
|
474
|
+
expect(result).to eq(expectation)
|
385
475
|
end
|
386
476
|
end
|
387
477
|
|
@@ -394,7 +484,7 @@ SKEEM
|
|
394
484
|
]
|
395
485
|
checks.each do |(skeem_expr, expectation)|
|
396
486
|
result = subject.run(skeem_expr)
|
397
|
-
expect(result
|
487
|
+
expect(result).to eq(expectation)
|
398
488
|
end
|
399
489
|
end
|
400
490
|
|
@@ -409,7 +499,7 @@ SKEEM
|
|
409
499
|
]
|
410
500
|
checks.each do |(skeem_expr, expectation)|
|
411
501
|
result = subject.run(skeem_expr)
|
412
|
-
expect(result
|
502
|
+
expect(result).to eq(expectation)
|
413
503
|
end
|
414
504
|
end
|
415
505
|
|
@@ -421,7 +511,7 @@ SKEEM
|
|
421
511
|
]
|
422
512
|
checks.each do |(skeem_expr, expectation)|
|
423
513
|
result = subject.run(skeem_expr)
|
424
|
-
expect(result
|
514
|
+
expect(result).to eq(expectation)
|
425
515
|
end
|
426
516
|
end
|
427
517
|
|
@@ -433,7 +523,7 @@ SKEEM
|
|
433
523
|
]
|
434
524
|
checks.each do |(skeem_expr, expectation)|
|
435
525
|
result = subject.run(skeem_expr)
|
436
|
-
expect(result.members
|
526
|
+
expect(result.members).to eq(expectation)
|
437
527
|
end
|
438
528
|
end
|
439
529
|
end # context
|
@@ -16,7 +16,7 @@ module Skeem
|
|
16
16
|
['(+ 2 2.34)', 4.34]
|
17
17
|
].each do |(expr, predicted)|
|
18
18
|
result = subject.run(expr)
|
19
|
-
expect(result
|
19
|
+
expect(result).to eq(predicted)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -27,7 +27,7 @@ module Skeem
|
|
27
27
|
['(- 3 4 5)', -6] # '-' as variadic operator. Example from section 6.2.6
|
28
28
|
].each do |(expr, predicted)|
|
29
29
|
result = subject.run(expr)
|
30
|
-
expect(result
|
30
|
+
expect(result).to eq(predicted)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -39,7 +39,7 @@ module Skeem
|
|
39
39
|
['(* 2 3 4 5)', 120] # '*' as variadic operator.
|
40
40
|
].each do |(expr, predicted)|
|
41
41
|
result = subject.run(expr)
|
42
|
-
expect(result
|
42
|
+
expect(result).to eq(predicted)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -50,7 +50,7 @@ module Skeem
|
|
50
50
|
['(/ 3 4 5)', 3.0/20] # '/' as variadic operator. Example from section 6.2.6
|
51
51
|
].each do |(expr, predicted)|
|
52
52
|
result = subject.run(expr)
|
53
|
-
expect(result
|
53
|
+
expect(result).to eq(predicted)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -64,7 +64,7 @@ module Skeem
|
|
64
64
|
]
|
65
65
|
checks.each do |(skeem_expr, expectation)|
|
66
66
|
result = subject.run(skeem_expr)
|
67
|
-
expect(result
|
67
|
+
expect(result).to eq(expectation)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end # context
|
@@ -81,7 +81,7 @@ module Skeem
|
|
81
81
|
]
|
82
82
|
checks.each do |(skeem_expr, expectation)|
|
83
83
|
result = subject.run(skeem_expr)
|
84
|
-
expect(result
|
84
|
+
expect(result).to eq(expectation)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -111,7 +111,7 @@ module Skeem
|
|
111
111
|
]
|
112
112
|
checks.each do |(skeem_expr, expectation)|
|
113
113
|
result = subject.run(skeem_expr)
|
114
|
-
expect(result
|
114
|
+
expect(result).to eq(expectation)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -127,7 +127,7 @@ module Skeem
|
|
127
127
|
]
|
128
128
|
checks.each do |(skeem_expr, expectation)|
|
129
129
|
result = subject.run(skeem_expr)
|
130
|
-
expect(result
|
130
|
+
expect(result).to eq(expectation)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -143,7 +143,7 @@ module Skeem
|
|
143
143
|
]
|
144
144
|
checks.each do |(skeem_expr, expectation)|
|
145
145
|
result = subject.run(skeem_expr)
|
146
|
-
expect(result
|
146
|
+
expect(result).to eq(expectation)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end # context
|
@@ -158,7 +158,7 @@ module Skeem
|
|
158
158
|
]
|
159
159
|
checks.each do |(skeem_expr, expectation)|
|
160
160
|
result = subject.run(skeem_expr)
|
161
|
-
expect(result
|
161
|
+
expect(result).to eq(expectation)
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
@@ -171,7 +171,7 @@ module Skeem
|
|
171
171
|
]
|
172
172
|
checks.each do |(skeem_expr, expectation)|
|
173
173
|
result = subject.run(skeem_expr)
|
174
|
-
expect(result
|
174
|
+
expect(result).to eq(expectation)
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
@@ -185,7 +185,7 @@ module Skeem
|
|
185
185
|
]
|
186
186
|
checks.each do |(skeem_expr, expectation)|
|
187
187
|
result = subject.run(skeem_expr)
|
188
|
-
expect(result
|
188
|
+
expect(result).to eq(expectation)
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
@@ -198,7 +198,7 @@ module Skeem
|
|
198
198
|
]
|
199
199
|
checks.each do |(skeem_expr, expectation)|
|
200
200
|
result = subject.run(skeem_expr)
|
201
|
-
expect(result
|
201
|
+
expect(result).to eq(expectation)
|
202
202
|
end
|
203
203
|
end
|
204
204
|
end # context
|
@@ -212,7 +212,7 @@ module Skeem
|
|
212
212
|
]
|
213
213
|
checks.each do |(skeem_expr, expectation)|
|
214
214
|
result = subject.run(skeem_expr)
|
215
|
-
expect(result
|
215
|
+
expect(result).to eq(expectation)
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
@@ -224,7 +224,7 @@ module Skeem
|
|
224
224
|
]
|
225
225
|
checks.each do |(skeem_expr, expectation)|
|
226
226
|
result = subject.run(skeem_expr)
|
227
|
-
expect(result
|
227
|
+
expect(result).to eq(expectation)
|
228
228
|
end
|
229
229
|
|
230
230
|
# If all the expressions evaluate to true values,
|
@@ -232,8 +232,8 @@ module Skeem
|
|
232
232
|
source = "(and 1 2 'c '(f g))"
|
233
233
|
result = subject.run(source)
|
234
234
|
expect(result).to be_kind_of(SkmList)
|
235
|
-
expect(result.head
|
236
|
-
expect(result.last
|
235
|
+
expect(result.head).to eq('f')
|
236
|
+
expect(result.last).to eq('g')
|
237
237
|
end
|
238
238
|
|
239
239
|
it 'should implement the or procedure' do
|
@@ -248,7 +248,7 @@ module Skeem
|
|
248
248
|
]
|
249
249
|
checks.each do |(skeem_expr, expectation)|
|
250
250
|
result = subject.run(skeem_expr)
|
251
|
-
expect(result
|
251
|
+
expect(result).to eq(expectation)
|
252
252
|
end
|
253
253
|
|
254
254
|
# When an expression evaluates to true value,
|
@@ -256,7 +256,7 @@ module Skeem
|
|
256
256
|
source = "(or #f 'a #f)"
|
257
257
|
result = subject.run(source)
|
258
258
|
expect(result).to be_kind_of(SkmIdentifier)
|
259
|
-
expect(result
|
259
|
+
expect(result).to eq('a')
|
260
260
|
end
|
261
261
|
|
262
262
|
it 'should implement the boolean? procedure' do
|
@@ -266,7 +266,7 @@ module Skeem
|
|
266
266
|
]
|
267
267
|
checks.each do |(skeem_expr, expectation)|
|
268
268
|
result = subject.run(skeem_expr)
|
269
|
-
expect(result
|
269
|
+
expect(result).to eq(expectation)
|
270
270
|
end
|
271
271
|
end
|
272
272
|
end # context
|
@@ -280,7 +280,7 @@ module Skeem
|
|
280
280
|
]
|
281
281
|
checks.each do |(skeem_expr, expectation)|
|
282
282
|
result = subject.run(skeem_expr)
|
283
|
-
expect(result
|
283
|
+
expect(result).to eq(expectation)
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
@@ -290,10 +290,10 @@ module Skeem
|
|
290
290
|
]
|
291
291
|
checks.each do |(skeem_expr, expectation)|
|
292
292
|
result = subject.run(skeem_expr)
|
293
|
-
expect(result
|
293
|
+
expect(result).to eq(expectation)
|
294
294
|
end
|
295
295
|
end
|
296
|
-
|
296
|
+
|
297
297
|
it 'should implement the string-append procedure' do
|
298
298
|
checks = [
|
299
299
|
['(string-append)', ''],
|
@@ -302,7 +302,19 @@ module Skeem
|
|
302
302
|
]
|
303
303
|
checks.each do |(skeem_expr, expectation)|
|
304
304
|
result = subject.run(skeem_expr)
|
305
|
-
expect(result
|
305
|
+
expect(result).to eq(expectation)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
it 'should implement the string-length procedure' do
|
310
|
+
checks = [
|
311
|
+
['(string-length "abc")', 3],
|
312
|
+
['(string-length "")', 0],
|
313
|
+
['(string-length "hi there")', 8],
|
314
|
+
]
|
315
|
+
checks.each do |(skeem_expr, expectation)|
|
316
|
+
result = subject.run(skeem_expr)
|
317
|
+
expect(result).to eq(expectation)
|
306
318
|
end
|
307
319
|
end
|
308
320
|
end # context
|
@@ -315,7 +327,7 @@ module Skeem
|
|
315
327
|
]
|
316
328
|
checks.each do |(skeem_expr, expectation)|
|
317
329
|
result = subject.run(skeem_expr)
|
318
|
-
expect(result
|
330
|
+
expect(result).to eq(expectation)
|
319
331
|
end
|
320
332
|
end
|
321
333
|
end # context
|
@@ -323,15 +335,15 @@ module Skeem
|
|
323
335
|
context 'List procedures:' do
|
324
336
|
it 'should implement the list? procedure' do
|
325
337
|
checks = [
|
326
|
-
['(list? #f)', false],
|
327
|
-
['(list? 1)', false],
|
328
|
-
['(list? "bar")', false],
|
329
|
-
['(list? (list 1 2 3))', true],
|
338
|
+
#['(list? #f)', false],
|
339
|
+
#['(list? 1)', false],
|
340
|
+
#['(list? "bar")', false],
|
341
|
+
#['(list? (list 1 2 3))', true],
|
330
342
|
['(list? (list))', true]
|
331
343
|
]
|
332
344
|
checks.each do |(skeem_expr, expectation)|
|
333
345
|
result = subject.run(skeem_expr)
|
334
|
-
expect(result
|
346
|
+
expect(result).to eq(expectation)
|
335
347
|
end
|
336
348
|
end
|
337
349
|
|
@@ -347,7 +359,7 @@ module Skeem
|
|
347
359
|
]
|
348
360
|
checks.each do |(skeem_expr, expectation)|
|
349
361
|
result = subject.run(skeem_expr)
|
350
|
-
expect(result
|
362
|
+
expect(result).to eq(expectation)
|
351
363
|
end
|
352
364
|
end
|
353
365
|
|
@@ -360,7 +372,7 @@ module Skeem
|
|
360
372
|
]
|
361
373
|
checks.each do |(skeem_expr, expectation)|
|
362
374
|
result = subject.run(skeem_expr)
|
363
|
-
expect(result
|
375
|
+
expect(result).to eq(expectation)
|
364
376
|
end
|
365
377
|
end
|
366
378
|
end # context
|
@@ -376,7 +388,7 @@ module Skeem
|
|
376
388
|
]
|
377
389
|
checks.each do |(skeem_expr, expectation)|
|
378
390
|
result = subject.run(skeem_expr)
|
379
|
-
expect(result
|
391
|
+
expect(result).to eq(expectation)
|
380
392
|
end
|
381
393
|
end
|
382
394
|
|
@@ -389,7 +401,7 @@ module Skeem
|
|
389
401
|
source = '(vector 1 2 3)'
|
390
402
|
result = subject.run(source)
|
391
403
|
expect(result).to be_kind_of(SkmVector)
|
392
|
-
expect(result.
|
404
|
+
expect(result.members).to eq([1, 2, 3])
|
393
405
|
end
|
394
406
|
|
395
407
|
it 'should implement the vector-length procedure' do
|
@@ -404,7 +416,7 @@ module Skeem
|
|
404
416
|
]
|
405
417
|
checks.each do |(skeem_expr, expectation)|
|
406
418
|
result = subject.run(skeem_expr)
|
407
|
-
expect(result
|
419
|
+
expect(result).to eq(expectation)
|
408
420
|
end
|
409
421
|
end
|
410
422
|
|
@@ -412,7 +424,7 @@ module Skeem
|
|
412
424
|
source = "(vector-ref '#(1 1 2 3 5 8 13 21) 5)"
|
413
425
|
result = subject.run(source)
|
414
426
|
expect(result).to be_kind_of(SkmInteger)
|
415
|
-
expect(result
|
427
|
+
expect(result).to eq(8)
|
416
428
|
end
|
417
429
|
end # context
|
418
430
|
|
data/spec/skeem/runtime_spec.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require_relative '../spec_helper' # Use the RSpec framework
|
2
|
-
require_relative '../../lib/skeem/
|
2
|
+
require_relative '../../lib/skeem/datum_dsl'
|
3
|
+
require_relative '../../lib/skeem/primitive/primitive_builder'
|
4
|
+
|
3
5
|
require_relative '../../lib/skeem/runtime' # Load the class under test
|
4
6
|
|
5
7
|
module Skeem
|
6
8
|
describe Runtime do
|
9
|
+
include DatumDSL
|
10
|
+
|
7
11
|
let(:some_env) { Environment.new }
|
8
12
|
subject { Runtime.new(some_env) }
|
9
13
|
|
@@ -30,7 +34,29 @@ module Skeem
|
|
30
34
|
subject.define('dummy', entry)
|
31
35
|
expect(subject.include?('dummy')).to be_truthy
|
32
36
|
end
|
33
|
-
|
37
|
+
end # context
|
38
|
+
|
39
|
+
context 'Evaluation:' do
|
40
|
+
include Primitive::PrimitiveBuilder
|
41
|
+
|
42
|
+
it 'should evaluate a given entry' do
|
43
|
+
entry = double('three')
|
44
|
+
result = double('fake-procedure')
|
45
|
+
expect(entry).to receive(:expression).and_return(result)
|
46
|
+
expect(result).to receive(:evaluate).with(subject).and_return(integer(3))
|
47
|
+
subject.define('three', entry)
|
48
|
+
expect(subject.evaluate('three')).to eq(3)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should evaluate a given list' do
|
52
|
+
add_primitives(subject)
|
53
|
+
sum = list([identifier('+'), 3, 4])
|
54
|
+
|
55
|
+
expect(subject.evaluate_form(sum)).to eq(7)
|
56
|
+
end
|
57
|
+
end # context
|
58
|
+
|
59
|
+
context 'Environment nesting' do
|
34
60
|
it 'should add nested environment' do
|
35
61
|
expect(subject.depth).to be_zero
|
36
62
|
env_before = subject.environment
|