1 ;;;; srfi-39.test --- -*- scheme -*-
3 ;;;; Copyright (C) 2004, 2005, 2006, 2008, 2011 Free Software Foundation, Inc.
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 3 of the License, or (at your option) any later version.
10 ;;;; This library 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 GNU
13 ;;;; Lesser General Public License for more details.
15 ;;;; You should have received a copy of the GNU Lesser General Public
16 ;;;; License along with this library; if not, write to the Free Software
17 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 ;; Testing the parameters implementation in boot-9.
21 (define-module (test-parameters)
22 #:use-module (srfi srfi-34)
23 #:use-module (test-suite lib))
25 (define a (make-parameter 3))
26 (define b (make-parameter 4))
28 (define (check a b a-val b-val)
29 (and (eqv? (a) a-val)) (eqv? (b) b-val))
31 (define c (make-parameter 2 (lambda (x) (if (< x 10) x 10))))
32 (define d (make-parameter 15 (lambda (x) (if (< x 10) x 10))))
34 (with-test-prefix "parameters"
40 (parameterize ((a 2) (b 1))
52 (parameterize ((a 0) (b 1) (c 98) (d 9))
55 (parameterize ((c (a)) (d (b)))
60 (let ((inside? (make-parameter #f)))
61 (call/cc (lambda (return)
62 (with-exception-handler
64 ;; This handler should be called in the dynamic
65 ;; environment installed by `parameterize'.
68 (parameterize ((inside? #t))
69 (raise 'some-exception)))))))))
72 (define (test-ports param new-port new-port-2)
73 (let ((old-port (param)))
76 (parameterize ((param new-port))
77 (eq? (param) new-port)))
80 (parameterize ((param old-port))
82 (eq? (param) new-port)))
84 (pass-if "old restored"
85 (parameterize ((param new-port))
87 (eq? (param) old-port))
92 (parameterize ((param new-port))
95 (eq? (param) old-port))
97 (pass-if "call/cc re-enter"
102 (parameterize ((param new-port))
103 (call/cc (lambda (k) (set! cont k)))
104 (set! count (1+ count))
106 (if (= 1 count) (param new-port-2)))
107 (set! good (and good (eq? (param) old-port)))
110 (set! good (and good (eq? port new-port)))
111 ;; re-entering should give new-port-2 left there last time
114 (set! good (and good (eq? port new-port-2)))))
117 (pass-if "original unchanged"
118 (eq? (param) old-port))))
120 (with-test-prefix "current-input-port"
121 (test-ports current-input-port
122 (open-input-string "xyz") (open-input-string "xyz")))
124 (with-test-prefix "current-output-port"
125 (test-ports current-output-port
126 (open-output-string) (open-output-string)))
128 (with-test-prefix "current-error-port"
129 (test-ports current-error-port
130 (open-output-string) (open-output-string))))