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 "bindings"
168 (pass-if "(let* ((x 1) (x 2)) ...)"
172 (pass-if "(let* ((x 1) (x x)) ...)"
176 (with-test-prefix "bad body"
178 (pass-if-exception "(let* ())"
182 (pass-if-exception "(let* ((x 1)))"
186 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
187 ;; Hmm, the body is bad as well, isn't it?
188 (pass-if-exception "(let*)"
192 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
193 ;; Hmm, the body is bad as well, isn't it?
194 (pass-if-exception "(let* 1)"
198 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
199 ;; Hmm, the body is bad as well, isn't it?
200 (pass-if-exception "(let* (x))"
204 (with-test-prefix "bad bindings"
206 (pass-if-exception "(let* (x) 1)"
207 exception:bad-bindings
210 (pass-if-exception "(let* ((x)) 3)"
211 exception:bad-bindings
214 (pass-if-exception "(let* ((x 1) y) x)"
215 exception:bad-bindings
218 (pass-if-exception "(let* x ())"
219 exception:bad-bindings
222 (pass-if-exception "(let* x (y))"
223 exception:bad-bindings
226 (pass-if-exception "(let* ((1 2)) 3)"
230 (with-test-prefix "letrec"
232 (with-test-prefix "bindings"
234 (pass-if-exception "initial bindings are undefined"
235 exception:unbound-var
237 (letrec ((x 1) (y x)) y))))
239 (with-test-prefix "bad body"
241 (pass-if-exception "(letrec ())"
245 (pass-if-exception "(letrec ((x 1)))"
249 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
250 ;; Hmm, the body is bad as well, isn't it?
251 (pass-if-exception "(letrec)"
255 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
256 ;; Hmm, the body is bad as well, isn't it?
257 (pass-if-exception "(letrec 1)"
261 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
262 ;; Hmm, the body is bad as well, isn't it?
263 (pass-if-exception "(letrec (x))"
267 (with-test-prefix "bad bindings"
269 (pass-if-exception "(letrec (x) 1)"
270 exception:bad-bindings
273 (pass-if-exception "(letrec ((x)) 3)"
274 exception:bad-bindings
277 (pass-if-exception "(letrec ((x 1) y) x)"
278 exception:bad-bindings
279 (letrec ((x 1) y) x))
281 (pass-if-exception "(letrec x ())"
282 exception:bad-bindings
285 (pass-if-exception "(letrec x (y))"
286 exception:bad-bindings
289 (pass-if-exception "(letrec ((1 2)) 3)"
293 (with-test-prefix "duplicate bindings"
295 (pass-if-exception "(letrec ((x 1) (x 2)) x)"
296 exception:duplicate-bindings
297 (letrec ((x 1) (x 2)) x))))
299 (with-test-prefix "if"
301 (with-test-prefix "missing or extra expressions"
303 (pass-if-exception "(if)"
304 exception:missing/extra-expr
307 (pass-if-exception "(if 1 2 3 4)"
308 exception:missing/extra-expr
311 (with-test-prefix "cond"
313 (with-test-prefix "bad or missing clauses"
315 (pass-if-exception "(cond)"
316 exception:bad/missing-clauses
319 (pass-if-exception "(cond #t)"
320 exception:bad/missing-clauses
323 (pass-if-exception "(cond 1)"
324 exception:bad/missing-clauses
327 (pass-if-exception "(cond 1 2)"
328 exception:bad/missing-clauses
331 (pass-if-exception "(cond 1 2 3)"
332 exception:bad/missing-clauses
335 (pass-if-exception "(cond 1 2 3 4)"
336 exception:bad/missing-clauses
339 (pass-if-exception "(cond ())"
340 exception:bad/missing-clauses
343 (pass-if-exception "(cond () 1)"
344 exception:bad/missing-clauses
347 (pass-if-exception "(cond (1) 1)"
348 exception:bad/missing-clauses
351 (with-test-prefix "cond =>"
353 (with-test-prefix "bad formals"
355 (pass-if-exception "=> (lambda (x 1) 2)"
356 exception:bad-formals
357 (cond (1 => (lambda (x 1) 2))))))
359 (with-test-prefix "case"
361 (with-test-prefix "bad or missing clauses"
363 (pass-if-exception "(case)"
364 exception:bad/missing-clauses
367 ;; FIXME: Wouldn't one rather expect a 'bad or missing clauses' error?
368 (pass-if-exception "(case . \"foo\")"
369 exception:wrong-type-arg
372 (pass-if-exception "(case 1)"
373 exception:bad/missing-clauses
376 ;; FIXME: Wouldn't one rather expect a 'bad or missing clauses' error?
377 (pass-if-exception "(case 1 . \"foo\")"
378 exception:wrong-type-arg
381 (pass-if-exception "(case 1 \"foo\")"
382 exception:bad/missing-clauses
385 (pass-if-exception "(case 1 ())"
386 exception:bad/missing-clauses
389 (pass-if-exception "(case 1 (\"foo\"))"
390 exception:bad/missing-clauses
393 (pass-if-exception "(case 1 (\"foo\" \"bar\"))"
394 exception:bad/missing-clauses
395 (case 1 ("foo" "bar")))
397 ;; According to R5RS, the following one is syntactically correct.
398 ;; (pass-if-exception "(case 1 (() \"bar\"))"
399 ;; exception:bad/missing-clauses
400 ;; (case 1 (() "bar")))
402 ;; FIXME: Wouldn't one rather expect a 'bad or missing clauses' error?
403 (pass-if-exception "(case 1 ((2) \"bar\") . \"foo\")"
404 exception:wrong-type-arg
405 (case 1 ((2) "bar") . "foo"))
407 (pass-if-exception "(case 1 (else #f) ((1) #t))"
408 exception:bad/missing-clauses
409 (case 1 ((2) "bar") (else)))
411 ;; FIXME: Wouldn't one rather expect a 'bad or missing clauses' error?
412 (pass-if-exception "(case 1 (else #f) . \"foo\")"
413 exception:wrong-type-arg
414 (case 1 (else #f) . "foo"))
416 (pass-if-exception "(case 1 (else #f) ((1) #t))"
417 exception:bad/missing-clauses
418 (case 1 (else #f) ((1) #t)))))
420 (with-test-prefix "define"
422 (with-test-prefix "missing or extra expressions"
424 (pass-if-exception "(define)"
425 exception:missing/extra-expr
428 (with-test-prefix "set!"
430 (with-test-prefix "missing or extra expressions"
432 (pass-if-exception "(set!)"
433 exception:missing/extra-expr
436 (pass-if-exception "(set! 1)"
437 exception:missing/extra-expr
440 (pass-if-exception "(set! 1 2 3)"
441 exception:missing/extra-expr
444 (with-test-prefix "bad variable"
446 (pass-if-exception "(set! \"\" #t)"
450 (pass-if-exception "(set! 1 #t)"
454 (pass-if-exception "(set! #t #f)"
458 (pass-if-exception "(set! #f #t)"
462 (pass-if-exception "(set! #\space #f)"
466 (with-test-prefix "generalized set! (SRFI 17)"
468 (with-test-prefix "target is not procedure with setter"
470 (pass-if-exception "(set! (symbol->string 'x) 1)"
471 exception:wrong-type-arg
472 (set! (symbol->string 'x) 1))
474 (pass-if-exception "(set! '#f 1)"
475 exception:wrong-type-arg
478 (with-test-prefix "quote"
480 (with-test-prefix "missing or extra expression"
482 (pass-if-exception "(quote)"
483 exception:missing/extra-expr
486 (pass-if-exception "(quote a b)"
487 exception:missing/extra-expr