1 ;;;; syntax.test --- test suite for Guile's syntactic forms -*- scheme -*-
3 ;;;; Copyright (C) 2001 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., 59 Temple Place, Suite 330,
18 ;;;; Boston, MA 02111-1307 USA
21 (define exception:bad-bindings
22 (cons 'misc-error "^bad bindings"))
23 (define exception:duplicate-bindings
24 (cons 'misc-error "^duplicate bindings"))
25 (define exception:bad-body
26 (cons 'misc-error "^bad body"))
27 (define exception:bad-formals
28 (cons 'misc-error "^bad formals"))
29 (define exception:duplicate-formals
30 (cons 'misc-error "^duplicate formals"))
31 (define exception:bad-var
32 (cons 'misc-error "^bad variable"))
33 (define exception:bad/missing-clauses
34 (cons 'misc-error "^bad or missing clauses"))
35 (define exception:missing/extra-expr
36 (cons 'misc-error "^missing or extra expression"))
39 (with-test-prefix "expressions"
41 (with-test-prefix "missing or extra expression"
44 ;; *Note:* In many dialects of Lisp, the empty combination, (),
45 ;; is a legitimate expression. In Scheme, combinations must
46 ;; have at least one subexpression, so () is not a syntactically
50 (pass-if-exception "empty parentheses \"()\""
51 exception:missing/extra-expr
54 (with-test-prefix "lambda"
56 (with-test-prefix "bad formals"
58 (pass-if-exception "(lambda (x 1) 2)"
62 (pass-if-exception "(lambda (1 x) 2)"
66 (pass-if-exception "(lambda (x \"a\") 2)"
70 (pass-if-exception "(lambda (\"a\" x) 2)"
74 (with-test-prefix "duplicate formals"
77 (pass-if-exception "(lambda (x x) 1)"
78 exception:duplicate-formals
82 (pass-if-exception "(lambda (x x x) 1)"
83 exception:duplicate-formals
86 (with-test-prefix "let"
88 (with-test-prefix "bindings"
90 (pass-if-exception "late binding"
92 (let ((x 1) (y x)) y)))
94 (with-test-prefix "bad body"
96 (pass-if-exception "(let ())"
100 (pass-if-exception "(let ((x 1)))"
104 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
105 ;; Hmm, the body is bad as well, isn't it?
106 (pass-if-exception "(let)"
110 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
111 ;; Hmm, the body is bad as well, isn't it?
112 (pass-if-exception "(let 1)"
116 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
117 ;; Hmm, the body is bad as well, isn't it?
118 (pass-if-exception "(let (x))"
122 (with-test-prefix "bad bindings"
124 (pass-if-exception "(let (x) 1)"
125 exception:bad-bindings
128 (pass-if-exception "(let ((x)) 3)"
129 exception:bad-bindings
132 (pass-if-exception "(let ((x 1) y) x)"
133 exception:bad-bindings
136 (pass-if-exception "(let ((1 2)) 3)"
140 (with-test-prefix "duplicate bindings"
142 (pass-if-exception "(let ((x 1) (x 2)) x)"
143 exception:duplicate-bindings
144 (let ((x 1) (x 2)) x))))
146 (with-test-prefix "named let"
148 (with-test-prefix "bad body"
150 (pass-if-exception "(let x ())"
154 (pass-if-exception "(let x ((y 1)))"
158 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
159 ;; Hmm, the body is bad as well, isn't it?
160 (pass-if-exception "(let x (y))"
164 (with-test-prefix "let*"
166 (with-test-prefix "bad body"
168 (pass-if-exception "(let* ())"
172 (pass-if-exception "(let* ((x 1)))"
176 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
177 ;; Hmm, the body is bad as well, isn't it?
178 (pass-if-exception "(let*)"
182 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
183 ;; Hmm, the body is bad as well, isn't it?
184 (pass-if-exception "(let* 1)"
188 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
189 ;; Hmm, the body is bad as well, isn't it?
190 (pass-if-exception "(let* (x))"
194 (with-test-prefix "bad bindings"
196 (pass-if-exception "(let* (x) 1)"
197 exception:bad-bindings
200 (pass-if-exception "(let* ((x)) 3)"
201 exception:bad-bindings
204 (pass-if-exception "(let* ((x 1) y) x)"
205 exception:bad-bindings
208 (pass-if-exception "(let* x ())"
209 exception:bad-bindings
212 (pass-if-exception "(let* x (y))"
213 exception:bad-bindings
216 (pass-if-exception "(let* ((1 2)) 3)"
220 (with-test-prefix "duplicate bindings"
222 (pass-if-exception "(let* ((x 1) (x 2)) x)"
223 exception:duplicate-bindings
224 (let* ((x 1) (x 2)) x))))
226 (with-test-prefix "letrec"
228 (with-test-prefix "bindings"
230 (pass-if-exception "initial bindings are undefined"
231 exception:unbound-var
233 (letrec ((x 1) (y x)) y))))
235 (with-test-prefix "bad body"
237 (pass-if-exception "(letrec ())"
241 (pass-if-exception "(letrec ((x 1)))"
245 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
246 ;; Hmm, the body is bad as well, isn't it?
247 (pass-if-exception "(letrec)"
251 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
252 ;; Hmm, the body is bad as well, isn't it?
253 (pass-if-exception "(letrec 1)"
257 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
258 ;; Hmm, the body is bad as well, isn't it?
259 (pass-if-exception "(letrec (x))"
263 (with-test-prefix "bad bindings"
265 (pass-if-exception "(letrec (x) 1)"
266 exception:bad-bindings
269 (pass-if-exception "(letrec ((x)) 3)"
270 exception:bad-bindings
273 (pass-if-exception "(letrec ((x 1) y) x)"
274 exception:bad-bindings
275 (letrec ((x 1) y) x))
277 (pass-if-exception "(letrec x ())"
278 exception:bad-bindings
281 (pass-if-exception "(letrec x (y))"
282 exception:bad-bindings
285 (pass-if-exception "(letrec ((1 2)) 3)"
289 (with-test-prefix "duplicate bindings"
291 (pass-if-exception "(letrec ((x 1) (x 2)) x)"
292 exception:duplicate-bindings
293 (letrec ((x 1) (x 2)) x))))
295 (with-test-prefix "if"
297 (with-test-prefix "missing or extra expressions"
299 (pass-if-exception "(if)"
300 exception:missing/extra-expr
303 (pass-if-exception "(if 1 2 3 4)"
304 exception:missing/extra-expr
307 (with-test-prefix "cond"
309 (with-test-prefix "bad or missing clauses"
311 (pass-if-exception "(cond)"
312 exception:bad/missing-clauses
315 (pass-if-exception "(cond #t)"
316 exception:bad/missing-clauses
319 (pass-if-exception "(cond 1)"
320 exception:bad/missing-clauses
323 (pass-if-exception "(cond 1 2)"
324 exception:bad/missing-clauses
327 (pass-if-exception "(cond 1 2 3)"
328 exception:bad/missing-clauses
331 (pass-if-exception "(cond 1 2 3 4)"
332 exception:bad/missing-clauses
335 (pass-if-exception "(cond ())"
336 exception:bad/missing-clauses
339 (pass-if-exception "(cond () 1)"
340 exception:bad/missing-clauses
343 (pass-if-exception "(cond (1) 1)"
344 exception:bad/missing-clauses
347 (with-test-prefix "cond =>"
349 (with-test-prefix "bad formals"
351 (pass-if-exception "=> (lambda (x 1) 2)"
352 exception:bad-formals
353 (cond (1 => (lambda (x 1) 2))))))
355 (with-test-prefix "define"
357 (with-test-prefix "missing or extra expressions"
359 (pass-if-exception "(define)"
360 exception:missing/extra-expr
363 (with-test-prefix "set!"
365 (with-test-prefix "missing or extra expressions"
367 (pass-if-exception "(set!)"
368 exception:missing/extra-expr
371 (pass-if-exception "(set! 1)"
372 exception:missing/extra-expr
375 (pass-if-exception "(set! 1 2 3)"
376 exception:missing/extra-expr
379 (with-test-prefix "bad variable"
381 (pass-if-exception "(set! \"\" #t)"
385 (pass-if-exception "(set! 1 #t)"
389 (pass-if-exception "(set! #t #f)"
393 (pass-if-exception "(set! #f #t)"
397 (pass-if-exception "(set! #\space #f)"
401 (with-test-prefix "generalized set! (SRFI 17)"
403 (with-test-prefix "target is not procedure with setter"
405 (pass-if-exception "(set! (symbol->string 'x) 1)"
406 exception:wrong-type-arg
407 (set! (symbol->string 'x) 1))
409 (pass-if-exception "(set! '#f 1)"
410 exception:wrong-type-arg
413 (with-test-prefix "quote"
415 (with-test-prefix "missing or extra expression"
417 (pass-if-exception "(quote)"
418 exception:missing/extra-expr
421 (pass-if-exception "(quote a b)"
422 exception:missing/extra-expr