1
;; Filename : test-srfi2.scm
2
;; About : unit test for the SRFI-2 'and-let*'
4
;; Copyright (C) 2005-2006 Kazuki Ohta <mover AT hct.zaq.ne.jp>
5
;; Copyright (c) 2007-2008 SigScheme Project <uim-en AT googlegroups.com>
7
;; All rights reserved.
9
;; Redistribution and use in source and binary forms, with or without
10
;; modification, are permitted provided that the following conditions
13
;; 1. Redistributions of source code must retain the above copyright
14
;; notice, this list of conditions and the following disclaimer.
15
;; 2. Redistributions in binary form must reproduce the above copyright
16
;; notice, this list of conditions and the following disclaimer in the
17
;; documentation and/or other materials provided with the distribution.
18
;; 3. Neither the name of authors nor the names of its contributors
19
;; may be used to endorse or promote products derived from this software
20
;; without specific prior written permission.
22
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
23
;; IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24
;; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25
;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
26
;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
;; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
;; See also oleg-srfi2.scm
36
(require-extension (unittest))
38
(require-extension (srfi 2))
40
(if (not (provided? "srfi-2"))
41
(test-skip "SRFI-2 is not enabled"))
45
;; (and-let* <claws> <body>)
47
;; <claws> ::= '() | (cons <claw> <claws>)
48
;; <claw> ::= (<variable> <expression>) | (<expression>)
54
(tn "and-let* invalid forms")
55
(assert-error (tn) (lambda () (and-let*)))
56
(assert-error (tn) (lambda () (and-let* #t #t)))
57
(assert-error (tn) (lambda () (and-let* ((#t) . #t) #t)))
58
(assert-error (tn) (lambda () (and-let* ((foo #t) . #t) #t)))
59
(assert-error (tn) (lambda () (and-let* ((foo . #t)) #t)))
60
(assert-error (tn) (lambda () (and-let* ((foo #t . #t)) #t)))
61
(assert-error (tn) (lambda () (and-let* (1) #t)))
63
(tn "and-let* misc normal forms")
64
(assert-eq? (tn) #t (and-let* ()))
65
(assert-eq? (tn) 'ok (and-let* ((foo 'ok)) foo))
66
(assert-eq? (tn) #t (and-let* () #t))
67
(assert-eq? (tn) #t (and-let* () #t #t))
68
(assert-eq? (tn) #t (and-let* () #t #t #t))
69
(assert-false (tn) (and-let* () #f))
70
(assert-false (tn) (and-let* () #t #f))
71
(assert-false (tn) (and-let* () #t #t #f))
72
(assert-eq? (tn) #t (and-let* () #t #f #t))
74
(tn "and-let* (<variable> <expression>) style claw")
75
(assert-false (tn) (and-let* ((false (< 2 1)))
77
(assert-false (tn) (and-let* ((true (< 1 2))
80
(assert-true (tn) (and-let* ((one 1)
84
(assert-false (tn) (and-let* ((one 1)
95
(tn "and-let* <bound-variable> style claw")
96
(assert-eq? (tn) 'ok (and-let* (true)
98
(assert-eq? (tn) #t (and-let* (true)))
99
(assert-eq? (tn) 'ok (and-let* (even?)
101
(assert-equal? (tn) even? (and-let* (even?)))
102
(assert-false (tn) (and-let* (false)
104
(assert-false (tn) (and-let* (false)))
105
(assert-eq? (tn) 'ok (and-let* (even?
108
(assert-eq? (tn) #t (and-let* (even?
110
(assert-false (tn) (and-let* (even?
114
(assert-false (tn) (and-let* (even?
118
(tn "and-let* (<expression>) style claw")
119
(assert-eq? (tn) 'ok (and-let* (('ok))))
120
(assert-eq? (tn) 'okok (and-let* (('ok)) 'okok))
121
(assert-equal? (tn) 1 (and-let* ((1))))
122
(assert-equal? (tn) 'ok (and-let* ((1)) 'ok))
123
(assert-equal? (tn) "ok" (and-let* (("ok"))))
124
(assert-equal? (tn) 'ok (and-let* (("ok")) 'ok))
125
(assert-eq? (tn) 'ok (and-let* ((#t))
127
(assert-false (tn) (and-let* ((#f))
129
(assert-eq? (tn) 'ok (and-let* (((integer? 1)))
131
(assert-false (tn) (and-let* (((integer? #t)))
133
(assert-eq? (tn) 'ok (and-let* (((integer? 1))
136
(assert-false (tn) (and-let* (((integer? 1))
141
(tn "and-let* combined forms")
142
(assert-eq? (tn) 'ok (and-let* (true
146
(assert-eq? (tn) 'ok (and-let* (true
153
(assert-false (tn) (and-let* (true
160
(assert-false (tn) (and-let* (true
169
(tn "and-let* internal definitions")
176
(assert-equal? (tn) 1 foo)
186
(assert-equal? (tn) 1 foo)
187
(assert-equal? (tn) 2 bar)
195
(assert-equal? (tn) 1 foo)
203
(assert-equal? (tn) 3 foo)