Merge branch 'syncase-in-boot-9'
[bpt/guile.git] / test-suite / tests / srfi-17.test
1 ;;;; srfi-17.test --- test suite for Guile's SRFI-17 functions. -*- scheme -*-
2 ;;;;
3 ;;;; Copyright (C) 2001, 2003, 2005, 2006 Free Software Foundation, Inc.
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
17 ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 ;;;; Boston, MA 02110-1301 USA
19
20 (define-module (test-suite test-srfi-17)
21 :use-module (test-suite lib)
22 :use-module (srfi srfi-17))
23
24
25 (pass-if "cond-expand srfi-17"
26 (cond-expand (srfi-17 #t)
27 (else #f)))
28
29 ;;
30 ;; car
31 ;;
32
33 (with-test-prefix "car"
34
35 ;; this test failed in guile 1.8.1 and 1.6.8 and earlier, since `define'
36 ;; didn't set a name on a procedure-with-setter
37 (pass-if "procedure-name"
38 (if (memq 'procnames (debug-options)) ;; enabled by default
39 (eq? 'car (procedure-name car))
40 (throw 'unsupported)))
41
42 (pass-if "set! (car x)"
43 (let ((lst (list 1)))
44 (set! (car lst) 2)
45 (eqv? 2 (car lst)))))
46
47 ;;
48 ;; set!
49 ;;
50
51 (define %some-variable #f)
52
53 (define exception:bad-quote
54 '(syntax-error . "quote: bad syntax"))
55
56 (with-test-prefix "set!"
57
58 (with-test-prefix "target is not procedure with setter"
59
60 (pass-if-exception "(set! (symbol->string 'x) 1)"
61 exception:wrong-type-arg
62 (set! (symbol->string 'x) 1))
63
64 (pass-if-exception "(set! '#f 1)"
65 exception:bad-quote
66 (eval '(set! '#f 1) (interaction-environment))))
67
68 (with-test-prefix "target uses macro"
69
70 (pass-if "(set! (@@ ...) 1)"
71 (eval '(set! (@@ (test-suite test-srfi-17) %some-variable) 1)
72 (interaction-environment))
73 (equal? %some-variable 1))
74
75 ;; The `(quote x)' below used to be memoized as an infinite list before
76 ;; Guile 1.8.3.
77 (pass-if-exception "(set! 'x 1)"
78 exception:bad-quote
79 (eval '(set! 'x 1) (interaction-environment)))))
80
81 ;;
82 ;; setter
83 ;;
84
85 (with-test-prefix "setter"
86
87 (pass-if-exception "set! (setter x)" (cons 'misc-error ".*")
88 (set! (setter car) noop))
89
90 (pass-if "car"
91 (eq? set-car! (setter car))))