Debian Codegraph @

lab/SRFI-2.tests.ss

raw
1 #!/usr/bin/env ikarus --r6rs-script
2 (import (SRFI-2)
3 (only (ikarus) error parameterize error-handler eval
4 environment)
5 (r6rs))
6
7 (define-syntax expect
8 (syntax-rules ()
9 [(_ e0 e1)
10 (let ([v0 e0] [v1 e1])
11 (if (equal? v0 v1)
12 'ok
13 (error #f "failed in ~s" '(expect e0 e1))))]))
14
15 (define-syntax must-be-a-syntax-error
16 (syntax-rules ()
17 [(_ form)
18 ((call/cc
19 (lambda (k)
20 (parameterize ([error-handler
21 (lambda args
22 (k (lambda ()
23 (display "failed as expected\n"))))])
24 (eval 'form (environment '(r6rs) '(SRFI-2)))
25 (lambda ()
26 (error #f "did not fail"))))))]))
27
28
29
30
31 (display "loaded!\n")
32
33
34
35 (expect (land* () 1) 1)
36 (expect (land* () 1 2) 2)
37 (expect (land* () ) #t)
38
39 (expect (let ((x #f)) (land* (x))) #f)
40 (expect (let ((x 1)) (land* (x))) 1)
41 (expect (land* ((x #f)) ) #f)
42 (expect (land* ((x 1)) ) 1)
43 (must-be-a-syntax-error (land* ( #f (x 1))) )
44 (expect (land* ( (#f) (x 1)) ) #f)
45 (must-be-a-syntax-error (land* (2 (x 1))) )
46 (expect (land* ( (2) (x 1)) ) 1)
47 (expect (land* ( (x 1) (2)) ) 2)
48 (expect (let ((x #f)) (land* (x) x)) #f)
49 (expect (let ((x "")) (land* (x) x)) "")
50 (expect (let ((x "")) (land* (x) )) "")
51 (expect (let ((x 1)) (land* (x) (+ x 1))) 2)
52 (expect (let ((x #f)) (land* (x) (+ x 1))) #f)
53 (expect (let ((x 1)) (land* (((positive? x))) (+ x 1))) 2)
54 (expect (let ((x 1)) (land* (((positive? x))) )) #t)
55 (expect (let ((x 0)) (land* (((positive? x))) (+ x 1))) #f)
56 (expect (let ((x 1)) (land* (((positive? x)) (x (+ x 1))) (+ x 1))) 3)
57 ; this is wrong
58 ; the srfi says:
59 ; ``As usual, all VARIABLEs must be unique (like in let*) ''
60 ; but the variables in let* need not be unique; so, it must be
61 ; a mistake
62
63 ;(must-be-a-syntax-error
64 ; (let ((x 1))
65 ; (land* (((positive? x))
66 ; (x (+ x 1))
67 ; (x (+ x 1)))
68 ; (+ x 1))))
69
70 (expect (let ((x 1)) (land* (x ((positive? x))) (+ x 1))) 2)
71 (expect (let ((x 1)) (land* ( ((begin x)) ((positive? x))) (+ x 1))) 2)
72 (expect (let ((x 0)) (land* (x ((positive? x))) (+ x 1))) #f)
73 (expect (let ((x #f)) (land* (x ((positive? x))) (+ x 1))) #f)
74 (expect (let ((x #f)) (land* ( ((begin x)) ((positive? x))) (+ x 1))) #f)
75
76 ;(expect (let ((x 1)) (land* (x (y (- x 1)) ((positive? y))) (/ x y))) #f)
77 ;(expect (let ((x 0)) (land* (x (y (- x 1)) ((positive? y))) (/ x y))) #f)
78 ;(expect (let ((x #f)) (land* (x (y (- x 1)) ((positive? y))) (/ x y))) #f)
79 ;(expect (let ((x 3)) (land* (x (y (- x 1)) ((positive? y))) (/ x y))) 3/2)
80
81 (display "All tests passed\n")
82
83