Commit | Line | Data |
---|---|---|
3514320f MV |
1 | ;;;; srfi-39.test --- -*- scheme -*- |
2 | ;;;; | |
6e7d5622 | 3 | ;;;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. |
3514320f MV |
4 | ;;;; |
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. | |
9 | ;;;; | |
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. | |
14 | ;;;; | |
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 | |
92205699 MV |
17 | ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | ;;;; Boston, MA 02110-1301 USA | |
3514320f | 19 | |
1352a755 KR |
20 | (define-module (test-srfi-39) |
21 | #:use-module (test-suite lib) | |
22 | #:use-module (srfi srfi-39)) | |
3514320f MV |
23 | |
24 | (define a (make-parameter 3)) | |
25 | (define b (make-parameter 4)) | |
26 | ||
27 | (define (check a b a-val b-val) | |
28 | (and (eqv? (a) a-val)) (eqv? (b) b-val)) | |
29 | ||
30 | (define c (make-parameter 2 (lambda (x) (if (< x 10) x 10)))) | |
31 | (define d (make-parameter 15 (lambda (x) (if (< x 10) x 10)))) | |
32 | ||
33 | (with-test-prefix "SRFI-39" | |
34 | ||
35 | (pass-if "test 1" | |
36 | (check a b 3 4)) | |
37 | ||
38 | (pass-if "test 2" | |
39 | (parameterize ((a 2) (b 1)) | |
40 | (and (check a b 2 1) | |
41 | (parameterize ((b 8)) | |
42 | (check a b 2 8))))) | |
43 | ||
44 | (pass-if "test 3" | |
45 | (check a b 3 4)) | |
46 | ||
47 | (pass-if "test 4" | |
48 | (check c d 2 10)) | |
49 | ||
50 | (pass-if "test 5" | |
51 | (parameterize ((a 0) (b 1) (c 98) (d 9)) | |
52 | (and (check a b 0 1) | |
53 | (check c d 10 9) | |
54 | (parameterize ((c (a)) (d (b))) | |
55 | (and (check a b 0 1) | |
56 | (check c d 0 1))))))) | |
b85bb56c KR |
57 | |
58 | (let () | |
59 | (define (test-ports param new-port new-port-2) | |
60 | (let ((old-port (param))) | |
61 | ||
62 | (pass-if "new value" | |
63 | (parameterize ((param new-port)) | |
64 | (eq? (param) new-port))) | |
65 | ||
66 | (pass-if "set value" | |
67 | (parameterize ((param old-port)) | |
68 | (param new-port) | |
69 | (eq? (param) new-port))) | |
70 | ||
71 | (pass-if "old restored" | |
72 | (parameterize ((param new-port)) | |
73 | #f) | |
74 | (eq? (param) old-port)) | |
75 | ||
76 | (pass-if "throw exit" | |
77 | (catch 'bail | |
78 | (lambda () | |
79 | (parameterize ((param new-port)) | |
80 | (throw 'bail))) | |
81 | (lambda args #f)) | |
82 | (eq? (param) old-port)) | |
83 | ||
84 | (pass-if "call/cc re-enter" | |
85 | (let ((cont #f) | |
86 | (count 0) | |
87 | (port #f) | |
88 | (good #t)) | |
89 | (parameterize ((param new-port)) | |
90 | (call/cc (lambda (k) (set! cont k))) | |
91 | (set! count (1+ count)) | |
92 | (set! port (param)) | |
93 | (if (= 1 count) (param new-port-2))) | |
94 | (set! good (and good (eq? (param) old-port))) | |
95 | (case count | |
96 | ((1) | |
97 | (set! good (and good (eq? port new-port))) | |
98 | ;; re-entering should give new-port-2 left there last time | |
99 | (cont)) | |
100 | ((2) | |
101 | (set! good (and good (eq? port new-port-2))))) | |
102 | good)) | |
103 | ||
104 | (pass-if "original unchanged" | |
105 | (eq? (param) old-port)))) | |
106 | ||
107 | (with-test-prefix "current-input-port" | |
108 | (test-ports current-input-port | |
109 | (open-input-string "xyz") (open-input-string "xyz"))) | |
110 | ||
111 | (with-test-prefix "current-output-port" | |
112 | (test-ports current-output-port | |
113 | (open-output-string) (open-output-string))) | |
114 | ||
115 | (with-test-prefix "current-error-port" | |
116 | (test-ports current-error-port | |
117 | (open-output-string) (open-output-string)))) |