1 ;;;; srfi-39.test --- -*- scheme -*-
3 ;;;; Copyright (C) 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
5 ;;;; This program is free software; you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation; either version 2, or (at your option)
8 ;;;; any later version.
10 ;;;; This program is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with this software; see the file COPYING. If not, write to
17 ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 ;;;; Boston, MA 02110-1301 USA
20 (define-module (test-srfi-39)
21 #:use-module (test-suite lib)
22 #:use-module (srfi srfi-34)
23 #:use-module (srfi srfi-39)
24 #:duplicates (last) ;; avoid warning about srfi-34 replacing `raise'
27 (define a (make-parameter 3))
28 (define b (make-parameter 4))
30 (define (check a b a-val b-val)
31 (and (eqv? (a) a-val)) (eqv? (b) b-val))
33 (define c (make-parameter 2 (lambda (x) (if (< x 10) x 10))))
34 (define d (make-parameter 15 (lambda (x) (if (< x 10) x 10))))
36 (with-test-prefix "SRFI-39"
42 (parameterize ((a 2) (b 1))
54 (parameterize ((a 0) (b 1) (c 98) (d 9))
57 (parameterize ((c (a)) (d (b)))
62 (let ((inside? (make-parameter #f)))
63 (call/cc (lambda (return)
64 (with-exception-handler
66 ;; This handler should be called in the dynamic
67 ;; environment installed by `parameterize'.
70 (parameterize ((inside? #t))
71 (raise 'some-exception)))))))))
74 (define (test-ports param new-port new-port-2)
75 (let ((old-port (param)))
78 (parameterize ((param new-port))
79 (eq? (param) new-port)))
82 (parameterize ((param old-port))
84 (eq? (param) new-port)))
86 (pass-if "old restored"
87 (parameterize ((param new-port))
89 (eq? (param) old-port))
94 (parameterize ((param new-port))
97 (eq? (param) old-port))
99 (pass-if "call/cc re-enter"
104 (parameterize ((param new-port))
105 (call/cc (lambda (k) (set! cont k)))
106 (set! count (1+ count))
108 (if (= 1 count) (param new-port-2)))
109 (set! good (and good (eq? (param) old-port)))
112 (set! good (and good (eq? port new-port)))
113 ;; re-entering should give new-port-2 left there last time
116 (set! good (and good (eq? port new-port-2)))))
119 (pass-if "original unchanged"
120 (eq? (param) old-port))))
122 (with-test-prefix "current-input-port"
123 (test-ports current-input-port
124 (open-input-string "xyz") (open-input-string "xyz")))
126 (with-test-prefix "current-output-port"
127 (test-ports current-output-port
128 (open-output-string) (open-output-string)))
130 (with-test-prefix "current-error-port"
131 (test-ports current-error-port
132 (open-output-string) (open-output-string))))