nendo 0.6.8 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,496 +0,0 @@
1
- ;;-*- mode: nendo; syntax: scheme -*-;;
2
- ;; test for nendo's core utility
3
-
4
- (use nendo.test)
5
-
6
- (test-start "nendo's core utility")
7
-
8
- ;;-------------------------------------------------------------------
9
- (test-section "disasm")
10
-
11
- (define (dummy-function arg1)
12
- (let1 var (+ arg1 1)
13
- var))
14
-
15
- (test* "disasm info"
16
- " file: ./test/nendo-util-test.nnd
17
- lineno: 11
18
- source:
19
- (define
20
- (dummy-function arg1)
21
- (let1 var
22
- (+ arg1 1) var))
23
- expanded:
24
- (define dummy-function
25
- (lambda
26
- (arg1)
27
- (%let
28
- ((var
29
- (+ arg1 1))) var)))
30
- " (disasm 'dummy-function 'info))
31
- (test* "disasm source "
32
- '(define (dummy-function arg1) (let1 var (+ arg1 1) var))
33
- (disasm 'dummy-function 'source))
34
- (test* "disasm expanded"
35
- '(define dummy-function (lambda (arg1) (%let ((var (+ arg1 1))) var)))
36
- (disasm 'dummy-function 'expanded))
37
- (test* "disasm ruby-code"
38
- "
39
- trampCall(
40
- begin
41
- def self._dummy_MIMARKfunction_METHOD( origname, pred, args ) lispMethodEntry( origname, true ) ; ret = callProcedure( '_dummy_MIMARKfunction', origname, pred, args ) ; lispMethodExit( origname, true ) ; return ret end
42
- @global_lisp_binding['_dummy_MIMARKfunction'] = self.method( :_dummy_MIMARKfunction_METHOD )
43
- @_dummy_MIMARKfunction =
44
- trampCall(
45
- Proc.new { |_arg1|
46
- begin
47
- ___lambda = lambda { |_var|
48
- begin
49
- trampCall(_var)
50
- rescue => __e ; __e.set_backtrace( [\"./test/nendo-util-test.nnd:13\"] + __e.backtrace ) ; raise __e
51
- end
52
- } ; ___lambda.call(
53
- begin
54
- embedBacktraceInfo( \"./test/nendo-util-test.nnd\", 12 );
55
- __PLMARK_ARGS2(
56
- begin
57
- trampCall(_arg1)
58
- rescue => __e ; __e.set_backtrace( [\"./test/nendo-util-test.nnd:12\"] + __e.backtrace ) ; raise __e
59
- end ,
60
- 1
61
- )
62
- end
63
- )
64
- end
65
- }
66
- )
67
- end
68
- )"
69
- (disasm 'dummy-function))
70
-
71
-
72
- ;;===================================================================
73
- (test-section "pretty-print-to-string")
74
- (define test-sexp1 '(a (b (c))))
75
- (define test-sexp2 '(define (function1 a b c) (+ a b c)))
76
-
77
- (test* "pretty-print-to-string"
78
- (string-join
79
- '("(a\n"
80
- " (b\n"
81
- " (c)))\n"))
82
- (pretty-print-to-string test-sexp1))
83
-
84
- (test* "pretty-print-to-string"
85
- (string-join
86
- '("(define\n"
87
- " (function1 a b c)\n"
88
- " (+ a b c))\n"))
89
- (pretty-print-to-string test-sexp2))
90
-
91
-
92
- (define (wrap-str str)
93
- (+ "[" str "]"))
94
-
95
-
96
- ;;-------------------------------------------------------------------
97
- (test-section "map for Enumerable")
98
-
99
- (test* "map-pable? no"
100
- #f
101
- (%%map-able?
102
- (lambda (x) x)
103
- ' (1 2)))
104
-
105
- (test* "map-pable? yes"
106
- #t
107
- (%%map-able?
108
- (lambda (x) x)
109
- '#(1 2)))
110
-
111
- (test* "map-pable? yes"
112
- #t
113
- (%%map-able?
114
- (lambda (x) x)
115
- (Range.new 0 100)))
116
-
117
- (test* "map-pable? yes"
118
- #t
119
- (%%map-able?
120
- (lambda (x) x)
121
- (hash-table eq? '("a" 1) '("b" 2))))
122
-
123
- (test* "%%map"
124
- '#("[a]" "[b]" "[C]")
125
- (%%map
126
- wrap-str
127
- '#("a" "b" "C")))
128
-
129
- (test* "%map (for vector)"
130
- '#("[a]" "[b]" "[C]")
131
- (%map
132
- wrap-str
133
- '#("a" "b" "C")))
134
-
135
- (test* "map (for vector)"
136
- '#("[a]" "[b]" "[C]")
137
- (map
138
- wrap-str
139
- '#("a" "b" "C")))
140
-
141
- (test* "map (for list)"
142
- '("[a]" "[b]" "[C]")
143
- (map
144
- wrap-str
145
- '("a" "b" "C")))
146
-
147
- (test* "map (for lists)"
148
- '("[1:3:5]" "[2:4:6]")
149
- (map
150
- (lambda (x y z) (+ "[" x ":" y ":" z "]"))
151
- '("1" "2")
152
- '("3" "4")
153
- '("5" "6")))
154
-
155
- ;;-------------------------------------------------------------------
156
- (test-section "for-each for Enumerable")
157
-
158
- (test* "for-each-pable? no"
159
- #f
160
- (%%for-each-able?
161
- (lambda (x) x)
162
- ' (1 2)))
163
-
164
- (test* "for-each-pable? yes"
165
- #t
166
- (%%for-each-able?
167
- (lambda (x) x)
168
- '#(1 2)))
169
-
170
- (test* "for-each-pable? yes"
171
- #t
172
- (%%for-each-able?
173
- (lambda (x) x)
174
- (Range.new 0 100)))
175
-
176
- (test* "for-each-pable? yes"
177
- #t
178
- (%%for-each-able?
179
- (lambda (x) x)
180
- (hash-table eq? '("a" 1) '("b" 2))))
181
-
182
- (test* "%%for-each"
183
- '("[a]" "[b]" "[C]")
184
- (let1 result '()
185
- (%%for-each
186
- (lambda (x) (set! result
187
- (cons (wrap-str x) result)))
188
- '#("a" "b" "C"))
189
- (reverse result)))
190
-
191
- (test* "%for-each (for vector)"
192
- '("[a]" "[b]" "[C]")
193
- (let1 result '()
194
- (%for-each
195
- (lambda (x) (set! result
196
- (cons (wrap-str x) result)))
197
- '#("a" "b" "C"))
198
- (reverse result)))
199
-
200
- (test* "for-each (for vector)"
201
- '("[a]" "[b]" "[C]")
202
- (let1 result '()
203
- (for-each
204
- (lambda (x) (set! result
205
- (cons (wrap-str x) result)))
206
- '#("a" "b" "C"))
207
- (reverse result)))
208
-
209
- (test* "for-each (for list)"
210
- '("[a]" "[b]" "[C]")
211
- (let1 result '()
212
- (for-each
213
- (lambda (x) (set! result
214
- (cons (wrap-str x) result)))
215
- '("a" "b" "C"))
216
- (reverse result)))
217
-
218
- (test* "for-each (for lists)"
219
- '("[1:3:5]" "[2:4:6]")
220
- (let1 result '()
221
- (for-each
222
- (lambda (x y z)
223
- (set! result
224
- (cons
225
- (+ "[" x ":" y ":" z "]")
226
- result)))
227
-
228
- '("1" "2")
229
- '("3" "4")
230
- '("5" "6"))
231
- (reverse result)))
232
-
233
-
234
- ;;-------------------------------------------------------------------
235
- (test-section "filter for Enumerable")
236
-
237
- (test* "filter-pable? no"
238
- #f
239
- (%%filter-able?
240
- (lambda (x) x)
241
- ' (1 2)))
242
-
243
- (test* "filter-pable? yes"
244
- #t
245
- (%%filter-able?
246
- (lambda (x) x)
247
- '#(1 2)))
248
-
249
- (test* "filter-pable? yes"
250
- #t
251
- (%%filter-able?
252
- (lambda (x) x)
253
- (Range.new 0 100)))
254
-
255
- (test* "filter-pable? yes"
256
- #t
257
- (%%filter-able?
258
- (lambda (x) x)
259
- (hash-table eq? '("a" 1) '("b" 2))))
260
-
261
- (test* "%%filter"
262
- '#("b")
263
- (%%filter
264
- (lambda (x) (= "b" x))
265
- '#("a" "b" "C")))
266
-
267
- (test* "%filter (for vector)"
268
- '#("b")
269
- (%filter
270
- (lambda (x) (= "b" x))
271
- '#("a" "b" "C")))
272
-
273
- (test* "filter (for vector1)"
274
- '#("b")
275
- (filter
276
- (lambda (x) (= "b" x))
277
- '#("a" "b" "C")))
278
-
279
- (test* "filter (for vector2)"
280
- '#("a" "C")
281
- (filter
282
- (lambda (x) (not (= "b" x)))
283
- '#("a" "b" "C")))
284
-
285
- (test* "filter (for list)"
286
- '("C")
287
- (filter
288
- (lambda (x) (= "C" x))
289
- '("a" "b" "C")))
290
-
291
-
292
- ;;-------------------------------------------------------------------
293
- (test-section "Enumerable on srfi-1")
294
- (use srfi-1)
295
-
296
- (test* "map (for vector)"
297
- '#("[a]" "[b]" "[C]")
298
- (map
299
- wrap-str
300
- '#("a" "b" "C")))
301
-
302
- (test* "map (for Range)"
303
- '#(10 11 12)
304
- (map
305
- (lambda (x) x)
306
- (Range.new 10 12)))
307
-
308
- (test* "map (for Enumerator)"
309
- '#("[one]" "[two]" "[three]")
310
- (map
311
- wrap-str
312
- (Enumerator.new
313
- (&block (v)
314
- (v.yield "one")
315
- (v.yield "two")
316
- (v.yield "three")))))
317
-
318
-
319
- (test* "for-each (for vector)"
320
- '("[a]" "[b]" "[C]")
321
- (let1 result '()
322
- (for-each
323
- (lambda (x) (set! result
324
- (cons (wrap-str x) result)))
325
- '#("a" "b" "C"))
326
- (reverse result)))
327
-
328
- (test* "for-each (for Range)"
329
- '(10 11 12)
330
- (let1 result '()
331
- (for-each
332
- (lambda (x) (set! result
333
- (cons x result)))
334
- (Range.new 10 12))
335
- (reverse result)))
336
-
337
- (test* "for-each (for Enumerable)"
338
- '("[one]" "[two]" "[three]")
339
- (let1 result '()
340
- (for-each
341
- (lambda (x) (set! result
342
- (cons (wrap-str x) result)))
343
- (Enumerator.new
344
- (&block (v)
345
- (v.yield "one")
346
- (v.yield "two")
347
- (v.yield "three"))))
348
- (reverse result)))
349
-
350
- (test* "filter (for vector)"
351
- '#("b")
352
- (filter
353
- (lambda (x) (= "b" x))
354
- '#("a" "b" "C")))
355
-
356
- (test* "filter (for Range)"
357
- '#(11)
358
- (filter
359
- (lambda (x) (= 11 x))
360
- (Range.new 10 1000)))
361
-
362
- (test* "filter (for Enumerable)"
363
- '#("one" "three")
364
- (filter
365
- (lambda (x) (not (= "two" x)))
366
- (Enumerator.new
367
- (&block (v)
368
- (v.yield "one")
369
- (v.yield "two")
370
- (v.yield "three")))))
371
-
372
-
373
- (test* "fold (for vector)"
374
- 120
375
- (fold
376
- (lambda (item result) (* item result))
377
- 1
378
- '#(1 2 3 4 5)))
379
-
380
- (test* "fold (for Range)"
381
- 5050
382
- (fold
383
- (lambda (item result) (+ item result))
384
- 1
385
- (Range.new 2 100)))
386
-
387
- (test* "fold (for string vector)"
388
- "a/b/c/d/e/f/g/h"
389
- (fold
390
- (lambda (item result) (+ result "/" item))
391
- "a"
392
- (. "bcdefgh" split "")))
393
-
394
- (test* "fold (for Enumerable)"
395
- "one:two:three:four"
396
- (fold
397
- (lambda (item result) (+ result ":" item))
398
- "one"
399
- (Enumerator.new
400
- (&block (v)
401
- (v.yield "two")
402
- (v.yield "three")
403
- (v.yield "four")
404
- ))))
405
-
406
-
407
- ;;-------------------------------------------------------------------
408
- (test-section "ruby-lazy for Enumerable")
409
-
410
- (let1 arr '#(1 2 3)
411
- (test* "ruby-lazy is a kind of vector? (1)"
412
- #t
413
- (vector? arr))
414
- (test* "ruby-lazy is a kind of vector? (2)"
415
- #t
416
- (vector? (ruby-lazy arr)))
417
- (test* "ruby-lazy is a kind of vector? (3)"
418
- #t
419
- (vector? (ruby-lazy (ruby-lazy arr)))))
420
-
421
- (if (ruby-lazy-enabled-platform?)
422
- ;; Ruby 2.0
423
- (let ((arr '#(1 2 3))
424
- (vec (ruby-lazy '#( 1 2 3 4 5 6 7 8 9 10 ))))
425
-
426
- (test* "ruby-lazy? (for Ruby-2.0)"
427
- #f
428
- (ruby-lazy? arr))
429
- (test* "ruby-lazy? (for Ruby-2.0)"
430
- #t
431
- (ruby-lazy? (ruby-lazy arr)))
432
- (test* "ruby-lazy? (for Ruby-2.0)"
433
- #t
434
- (ruby-lazy? (ruby-lazy (ruby-lazy arr))))
435
- (test* "ruby-lazy? (for Ruby-2.0)"
436
- #f
437
- (ruby-lazy? STDIN))
438
- (test* "ruby-lazy? (for Ruby-2.0)"
439
- #t
440
- (ruby-lazy? (ruby-lazy STDIN)))
441
- (test* "size of ruby-lazy (for Ruby-2.0)"
442
- 10
443
- (vec.size))
444
- (test* "size of ruby-lazy (for Ruby-2.0)"
445
- 10
446
- (vector-length vec))
447
- (test* "index of ruby-lazy"
448
- (test-error NoMethodError)
449
- (vector-ref vec 2))
450
- (test* "ruby-lazy to list"
451
- '(1 2 3 4 5 6 7 8 9 10)
452
- (vector->list vec))
453
- (test* "size of ruby-lazy"
454
- 10
455
- (length (vector->list vec)))
456
- (test* "index of ruby-lazy"
457
- 3
458
- (vector-ref (list->vector (vector->list vec)) 2))
459
- (test* "vector-equal?"
460
- (test-error NoMethodError)
461
- (vector-equal? vec (list->vector (range 10 1))))
462
- (test* "vector-equal?"
463
- #t
464
- (vector-equal? (list->vector (vector->list vec)) (list->vector (range 10 1))))
465
- (test* "vector-length"
466
- (test-error TypeError)
467
- (length (ruby-lazy (make-vector 100))))
468
- (test* "vector-length"
469
- 100
470
- (length (vector->list (ruby-lazy (make-vector 100)))))
471
- )
472
-
473
- ;; Ruby 1.9.x
474
- (let1 arr '#(1 2 3)
475
- (test* "ruby-lazy? (for Ruby 1.9.x)"
476
- #f
477
- (ruby-lazy? arr))
478
- (test* "ruby-lazy? (for Ruby 1.9.x)"
479
- #f
480
- (ruby-lazy? (ruby-lazy arr)))
481
- (test* "ruby-lazy? (for Ruby 1.9.x)"
482
- #f
483
- (ruby-lazy? (ruby-lazy (ruby-lazy arr))))
484
- (test* "ruby-lazy? (for Ruby 1.9.x)"
485
- #f
486
- (ruby-lazy? STDIN))
487
- (test* "ruby-lazy? (for Ruby 1.9.x)"
488
- #f
489
- (ruby-lazy? (ruby-lazy STDIN)))
490
- ))
491
-
492
-
493
-
494
-
495
- ;;===================================================================
496
- (test-end)