1
;; FileName : test-continuation.scm
2
;; About : unit test for continuation
4
;; Copyright (C) 2005-2006 Kazuki Ohta <mover AT hct.zaq.ne.jp>
6
;; All rights reserved.
8
;; Redistribution and use in source and binary forms, with or without
9
;; modification, are permitted provided that the following conditions
12
;; 1. Redistributions of source code must retain the above copyright
13
;; notice, this list of conditions and the following disclaimer.
14
;; 2. Redistributions in binary form must reproduce the above copyright
15
;; notice, this list of conditions and the following disclaimer in the
16
;; documentation and/or other materials provided with the distribution.
17
;; 3. Neither the name of authors nor the names of its contributors
18
;; may be used to endorse or promote products derived from this software
19
;; without specific prior written permission.
21
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
22
;; IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
;; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
25
;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
;; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
(load "./test/unittest.scm")
35
(define call/cc call-with-current-continuation)
37
(assert-equal? "call/cc #1" -3 (call-with-current-continuation
47
(call-with-current-continuation
51
(cond ((null? obj1) 0)
53
(+ (re (cdr obj1)) 1))
58
(assert-equal? "call/cc #2" 4 (list-length '(1 2 3 4)))
59
(assert-equal? "call/cc #3" #f (list-length '(a b . c)))
61
;; function written in C as proc
62
(assert-true "call/cc #4" (call/cc procedure?))
64
;; another continuation as proc
65
(assert-true "call/cc #5" (procedure? (call/cc (lambda (c) (call/cc c)))))
67
(assert-equal? "call/cc #6" 'ret-call/cc
68
(call-with-current-continuation
72
(assert-equal? "call/cc #7" 'ret-call/cc
73
(call-with-current-continuation
77
;; Call an expired continuation. Current SigScheme cause an error due to its
78
;; setjmp/longjmp implementation.
79
(assert-error "call/cc #8"
81
(let ((res (call-with-current-continuation
88
;; "6.4 Control features" of R5RS:
89
;; The escape procedure accepts the same number of arguments as the
90
;; continuation to the original call to call-with-current-continuation.
91
;; Except for continuations created by the `call-with-values' procedure, all
92
;; continuations take exactly one value.
93
(assert-error "call/cc #9"
95
(call-with-current-continuation
99
(assert-error "call/cc #10"
101
(call-with-current-continuation
106
(assert-equal? "call/cc #11"
108
(call-with-current-continuation