1
;; Filename : test-continuation.scm
2
;; About : unit test for continuation
4
;; Copyright (C) 2005-2006 Kazuki Ohta <mover AT hct.zaq.ne.jp>
5
;; Copyright (c) 2007 SigScheme Project <uim AT freedesktop.org>
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
(load "./test/unittest.scm")
36
(if (not (symbol-bound? 'call-with-current-continuation))
37
(test-skip "R5RS continuation is not enabled"))
40
(define call/cc call-with-current-continuation)
42
(tn "call/cc invalid forms")
44
(assert-error (tn) (lambda ()
45
(call-with-current-continuation)))
47
(assert-error (tn) (lambda ()
48
(call-with-current-continuation #t)))
50
(assert-error (tn) (lambda ()
51
(call-with-current-continuation procedure? #t)))
55
(assert-error (tn) (lambda ()
56
(call-with-current-continuation +)))
60
(call-with-current-continuation
70
(call-with-current-continuation
74
(cond ((null? obj1) 0)
76
(+ (re (cdr obj1)) 1))
81
(assert-equal? (tn) 4 (list-length '(1 2 3 4)))
82
(assert-equal? (tn) #f (list-length '(a b . c)))
84
;; function written in C as proc
85
(assert-true (tn) (call/cc procedure?))
87
;; another continuation as proc
88
(assert-true (tn) (procedure? (call/cc (lambda (c) (call/cc c)))))
90
(assert-equal? (tn) 'ret-call/cc
91
(call-with-current-continuation
95
(assert-equal? (tn) 'ret-call/cc
96
(call-with-current-continuation
100
;; Call an expired continuation. Current SigScheme cause an error due to its
101
;; setjmp/longjmp implementation.
104
(let ((res (call-with-current-continuation
111
;; "6.4 Control features" of R5RS:
112
;; The escape procedure accepts the same number of arguments as the
113
;; continuation to the original call to call-with-current-continuation.
114
;; Except for continuations created by the `call-with-values' procedure, all
115
;; continuations take exactly one value.
118
(call-with-current-continuation
124
(call-with-current-continuation
131
(call-with-current-continuation
135
(tn "call/cc SigScheme-specific behavior")
136
(if (and (provided? "sigscheme")
137
(provided? "nested-continuation-only"))
138
;; expired continuation
139
(assert-error (tn) (lambda ()
140
((call/cc (lambda (c) c))
142
(assert-true (tn) ((call/cc (lambda (c) c))