Update README on using libraries in non-standard locations
[bpt/guile.git] / test-suite / tests / srfi-9.test
CommitLineData
f764e6d1
MG
1;;;; srfi-9.test --- Test suite for Guile's SRFI-9 functions. -*- scheme -*-
2;;;; Martin Grabmueller, 2001-05-10
3;;;;
3ba9acb1 4;;;; Copyright (C) 2001, 2006, 2007 Free Software Foundation, Inc.
f764e6d1
MG
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
f764e6d1 20
8ab3d8a0
KR
21(define-module (test-suite test-numbers)
22 #:use-module (test-suite lib)
23 #:use-module (srfi srfi-9))
24
25
f764e6d1
MG
26(define-record-type :foo (make-foo x) foo?
27 (x get-x) (y get-y set-y!))
28
8ab3d8a0
KR
29(define-record-type :bar (make-bar i j) bar?
30 (i get-i) (i get-j set-j!))
31
f764e6d1
MG
32(define f (make-foo 1))
33(set-y! f 2)
34
8ab3d8a0
KR
35(define b (make-bar 123 456))
36
37(with-test-prefix "constructor"
38
39 (pass-if-exception "foo 0 args" exception:wrong-num-args
40 (make-foo))
41 (pass-if-exception "foo 2 args" exception:wrong-num-args
42 (make-foo 1 2)))
43
44(with-test-prefix "predicate"
f764e6d1 45
8ab3d8a0 46 (pass-if "pass"
f764e6d1 47 (foo? f))
8ab3d8a0
KR
48 (pass-if "fail wrong record type"
49 (eq? #f (foo? b)))
50 (pass-if "fail number"
51 (eq? #f (foo? 123))))
f764e6d1 52
8ab3d8a0 53(with-test-prefix "accessor"
f764e6d1 54
8ab3d8a0
KR
55 (pass-if "get-x"
56 (= 1 (get-x f)))
57 (pass-if "get-y"
f764e6d1
MG
58 (= 2 (get-y f)))
59
3ba9acb1 60 (pass-if-exception "get-x on number" exception:wrong-type-arg
8ab3d8a0 61 (get-x 999))
3ba9acb1 62 (pass-if-exception "get-y on number" exception:wrong-type-arg
8ab3d8a0
KR
63 (get-y 999))
64
65 ;; prior to guile 1.6.9 and 1.8.1 this wan't enforced
66 (pass-if-exception "get-x on bar" exception:wrong-type-arg
67 (get-x b))
68 (pass-if-exception "get-y on bar" exception:wrong-type-arg
69 (get-y b)))
70
71(with-test-prefix "modifier"
72
73 (pass-if "set-y!"
f764e6d1 74 (set-y! f #t)
8ab3d8a0
KR
75 (eq? #t (get-y f)))
76
3ba9acb1 77 (pass-if-exception "set-y! on number" exception:wrong-type-arg
8ab3d8a0
KR
78 (set-y! 999 #t))
79
80 ;; prior to guile 1.6.9 and 1.8.1 this wan't enforced
81 (pass-if-exception "set-y! on bar" exception:wrong-type-arg
82 (set-y! b 99)))