Commit | Line | Data |
---|---|---|
025f75b4 MV |
1 | ;;;; optargs.test --- test suite for optional arg processing -*- scheme -*- |
2 | ;;;; Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> --- June 2001 | |
3 | ;;;; | |
4 | ;;;; Copyright (C) 2001 Free Software Foundation, Inc. | |
5 | ;;;; | |
6 | ;;;; This program is free software; you can redistribute it and/or modify | |
7 | ;;;; it under the terms of the GNU General Public License as published by | |
8 | ;;;; the Free Software Foundation; either version 2, or (at your option) | |
9 | ;;;; any later version. | |
10 | ;;;; | |
11 | ;;;; This program is distributed in the hope that it will be useful, | |
12 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;;; GNU General Public License for more details. | |
15 | ;;;; | |
16 | ;;;; You should have received a copy of the GNU General Public License | |
17 | ;;;; along with this software; see the file COPYING. If not, write to | |
92205699 MV |
18 | ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | ;;;; Boston, MA 02110-1301 USA | |
025f75b4 | 20 | |
560434b3 DH |
21 | (define-module (test-suite test-optargs) |
22 | :use-module (test-suite lib) | |
23 | :use-module (ice-9 optargs)) | |
025f75b4 MV |
24 | |
25 | (with-test-prefix "optional argument processing" | |
025f75b4 | 26 | (pass-if "local defines work with optional arguments" |
560434b3 DH |
27 | (eval '(begin |
28 | (define* (test-1 #:optional (x 0)) | |
29 | (define d 1) ; local define | |
30 | #t) | |
31 | (false-if-exception (test-1))) | |
32 | (interaction-environment)))) | |
927a122d KR |
33 | |
34 | ;;; | |
35 | ;;; let-keywords | |
36 | ;;; | |
37 | ||
38 | (with-test-prefix "let-keywords" | |
39 | ||
40 | ;; in guile 1.6.4 and earlier, an empty binding list only used `begin', | |
41 | ;; which caused apparently internal defines to "leak" out into the | |
42 | ;; encompasing environment | |
43 | (pass-if-exception "empty bindings internal defines leaking out" | |
44 | exception:unbound-var | |
45 | (let ((rest '())) | |
46 | (let-keywords rest #f () | |
47 | (define localvar #f) | |
48 | #f) | |
49 | localvar)) | |
50 | ||
51 | (pass-if "one key" | |
52 | (let-keywords '(#:foo 123) #f (foo) | |
53 | (= foo 123)))) | |
54 | ||
55 | ;;; | |
56 | ;;; let-keywords* | |
57 | ;;; | |
58 | ||
59 | (with-test-prefix "let-keywords*" | |
60 | ||
61 | ;; in guile 1.6.4 and earlier, an empty binding list only used `begin', | |
62 | ;; which caused apparently internal defines to "leak" out into the | |
63 | ;; encompasing environment | |
64 | (pass-if-exception "empty bindings internal defines leaking out" | |
65 | exception:unbound-var | |
66 | (let ((rest '())) | |
67 | (let-keywords* rest #f () | |
68 | (define localvar #f) | |
69 | #f) | |
70 | localvar)) | |
71 | ||
72 | (pass-if "one key" | |
73 | (let-keywords* '(#:foo 123) #f (foo) | |
74 | (= foo 123)))) | |
75 | ||
76 | ;;; | |
77 | ;;; let-optional | |
78 | ;;; | |
79 | ||
80 | (with-test-prefix "let-optional" | |
81 | ||
82 | ;; in guile 1.6.4 and earlier, an empty binding list only used `begin', | |
83 | ;; which caused apparently internal defines to "leak" out into the | |
84 | ;; encompasing environment | |
85 | (pass-if-exception "empty bindings internal defines leaking out" | |
86 | exception:unbound-var | |
87 | (let ((rest '())) | |
88 | (let-optional rest () | |
89 | (define localvar #f) | |
90 | #f) | |
91 | localvar)) | |
92 | ||
93 | (pass-if "one var" | |
94 | (let ((rest '(123))) | |
95 | (let-optional rest ((foo 999)) | |
96 | (= foo 123))))) | |
97 | ||
98 | ;;; | |
99 | ;;; let-optional* | |
100 | ;;; | |
101 | ||
102 | (with-test-prefix "let-optional*" | |
103 | ||
104 | ;; in guile 1.6.4 and earlier, an empty binding list only used `begin', | |
105 | ;; which caused apparently internal defines to "leak" out into the | |
106 | ;; encompasing environment | |
107 | (pass-if-exception "empty bindings internal defines leaking out" | |
108 | exception:unbound-var | |
109 | (let ((rest '())) | |
110 | (let-optional* rest () | |
111 | (define localvar #f) | |
112 | #f) | |
113 | localvar)) | |
114 | ||
115 | (pass-if "one var" | |
116 | (let ((rest '(123))) | |
117 | (let-optional* rest ((foo 999)) | |
118 | (= foo 123))))) |