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:bad-body
24 (cons 'misc-error "^bad body"))
25 (define exception:bad-formals
26 (cons 'misc-error "^bad formals"))
27 (define exception:bad-var
28 (cons 'misc-error "^bad variable"))
29 (define exception:bad/missing-clauses
30 (cons 'misc-error "^bad or missing clauses"))
31 (define exception:missing/extra-expr
32 (cons 'misc-error "^missing or extra expression"))
35 (with-test-prefix "expressions"
37 (with-test-prefix "missing or extra expression"
40 ;; *Note:* In many dialects of Lisp, the empty combination, (),
41 ;; is a legitimate expression. In Scheme, combinations must
42 ;; have at least one subexpression, so () is not a syntactically
44 (expect-fail-exception "empty parentheses \"()\""
45 exception:missing/extra-expr
48 (with-test-prefix "lambda"
50 (with-test-prefix "bad formals"
52 (pass-if-exception "(lambda (x 1) 2)"
56 (pass-if-exception "(lambda (1 x) 2)"
60 (pass-if-exception "(lambda (x \"a\") 2)"
64 (pass-if-exception "(lambda (\"a\" x) 2)"
68 (expect-fail-exception "(lambda (x x) 1)"
72 (expect-fail-exception "(lambda (x x x) 1)"
76 (with-test-prefix "let"
78 (with-test-prefix "bindings"
80 (pass-if-exception "late binding"
82 (let ((x 1) (y x)) y)))
84 (with-test-prefix "bad body"
86 (pass-if-exception "(let ())"
90 (pass-if-exception "(let ((x 1)))"
94 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
95 (pass-if-exception "(let)"
99 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
100 (pass-if-exception "(let 1)"
104 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
105 (pass-if-exception "(let (x))"
109 (with-test-prefix "bad bindings"
111 (pass-if-exception "(let (x) 1)"
112 exception:bad-bindings
115 (pass-if-exception "(let ((x)) 3)"
116 exception:bad-bindings
119 (pass-if-exception "(let ((x 1) y) x)"
120 exception:bad-bindings
123 (pass-if-exception "(let ((1 2)) 3)"
127 (expect-fail-exception "(let ((x 1) (x 2)) x)"
128 exception:bad-bindings
129 (let ((x 1) (x 2)) x))))
131 (with-test-prefix "named let"
133 (with-test-prefix "bad body"
135 (pass-if-exception "(let x ())"
139 (pass-if-exception "(let x ((y 1)))"
143 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
144 (pass-if-exception "(let x (y))"
148 (with-test-prefix "let*"
150 (with-test-prefix "bad body"
152 (pass-if-exception "(let* ())"
156 (pass-if-exception "(let* ((x 1)))"
160 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
161 (pass-if-exception "(let*)"
165 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
166 (pass-if-exception "(let* 1)"
170 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
171 (pass-if-exception "(let* (x))"
175 (with-test-prefix "bad bindings"
177 (pass-if-exception "(let* (x) 1)"
178 exception:bad-bindings
181 (pass-if-exception "(let* ((x)) 3)"
182 exception:bad-bindings
185 (pass-if-exception "(let* ((x 1) y) x)"
186 exception:bad-bindings
189 (pass-if-exception "(let* x ())"
190 exception:bad-bindings
193 (pass-if-exception "(let* x (y))"
194 exception:bad-bindings
197 (pass-if-exception "(let* ((1 2)) 3)"
201 (expect-fail-exception "(let* ((x 1) (x 2)) x)"
202 exception:bad-bindings
203 (let* ((x 1) (x 2)) x))))
205 (with-test-prefix "letrec"
207 (with-test-prefix "bindings"
209 (pass-if-exception "initial bindings are undefined"
210 exception:unbound-var
212 (letrec ((x 1) (y x)) y))))
214 (with-test-prefix "bad body"
216 (pass-if-exception "(letrec ())"
220 (pass-if-exception "(letrec ((x 1)))"
224 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
225 (pass-if-exception "(letrec)"
229 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
230 (pass-if-exception "(letrec 1)"
234 ;; FIXME: Wouldn't one rather expect a 'bad bindings' error?
235 (pass-if-exception "(letrec (x))"
239 (with-test-prefix "bad bindings"
241 (pass-if-exception "(letrec (x) 1)"
242 exception:bad-bindings
245 (pass-if-exception "(letrec ((x)) 3)"
246 exception:bad-bindings
249 (pass-if-exception "(letrec ((x 1) y) x)"
250 exception:bad-bindings
251 (letrec ((x 1) y) x))
253 (pass-if-exception "(letrec x ())"
254 exception:bad-bindings
257 (pass-if-exception "(letrec x (y))"
258 exception:bad-bindings
261 (pass-if-exception "(letrec ((1 2)) 3)"
265 (expect-fail-exception "(letrec ((x 1) (x 2)) x)"
266 exception:bad-bindings
267 (letrec ((x 1) (x 2)) x))))
269 (with-test-prefix "if"
271 (with-test-prefix "missing or extra expressions"
273 (pass-if-exception "(if)"
274 exception:missing/extra-expr
277 (pass-if-exception "(if 1 2 3 4)"
278 exception:missing/extra-expr
281 (with-test-prefix "cond"
283 (with-test-prefix "bad or missing clauses"
285 (pass-if-exception "(cond)"
286 exception:bad/missing-clauses
289 (pass-if-exception "(cond #t)"
290 exception:bad/missing-clauses
293 (pass-if-exception "(cond 1)"
294 exception:bad/missing-clauses
297 (pass-if-exception "(cond 1 2)"
298 exception:bad/missing-clauses
301 (pass-if-exception "(cond 1 2 3)"
302 exception:bad/missing-clauses
305 (pass-if-exception "(cond 1 2 3 4)"
306 exception:bad/missing-clauses
309 (pass-if-exception "(cond ())"
310 exception:bad/missing-clauses
313 (pass-if-exception "(cond () 1)"
314 exception:bad/missing-clauses
317 (pass-if-exception "(cond (1) 1)"
318 exception:bad/missing-clauses
321 (with-test-prefix "cond =>"
323 (with-test-prefix "bad formals"
325 (pass-if-exception "=> (lambda (x 1) 2)"
326 exception:bad-formals
327 (cond (1 => (lambda (x 1) 2))))))
329 (with-test-prefix "define"
331 (with-test-prefix "missing or extra expressions"
333 (pass-if-exception "(define)"
334 exception:missing/extra-expr
337 (with-test-prefix "set!"
339 (with-test-prefix "missing or extra expressions"
341 (pass-if-exception "(set!)"
342 exception:missing/extra-expr
345 (pass-if-exception "(set! 1)"
346 exception:missing/extra-expr
349 (pass-if-exception "(set! 1 2 3)"
350 exception:missing/extra-expr
353 (with-test-prefix "bad variable"
355 (pass-if-exception "(set! \"\" #t)"
359 (pass-if-exception "(set! 1 #t)"
363 (pass-if-exception "(set! #t #f)"
367 (pass-if-exception "(set! #f #t)"
371 (pass-if-exception "(set! #\space #f)"
375 (with-test-prefix "generalized set! (SRFI 17)"
377 (with-test-prefix "target is not procedure with setter"
379 (pass-if-exception "(set! (symbol->string 'x) 1)"
380 exception:wrong-type-arg
381 (set! (symbol->string 'x) 1))
383 (pass-if-exception "(set! '#f 1)"
384 exception:wrong-type-arg
387 (with-test-prefix "quote"
389 (with-test-prefix "missing or extra expression"
391 (pass-if-exception "(quote)"
392 exception:missing/extra-expr
395 (pass-if-exception "(quote a b)"
396 exception:missing/extra-expr