Merge branch 'ossau-gds-dev'
[bpt/guile.git] / test-suite / tests / srfi-9.test
1 ;;;; srfi-9.test --- Test suite for Guile's SRFI-9 functions. -*- scheme -*-
2 ;;;; Martin Grabmueller, 2001-05-10
3 ;;;;
4 ;;;; Copyright (C) 2001, 2006, 2007 Free Software Foundation, Inc.
5 ;;;;
6 ;;;; This library is free software; you can redistribute it and/or
7 ;;;; modify it under the terms of the GNU Lesser General Public
8 ;;;; License as published by the Free Software Foundation; either
9 ;;;; version 3 of the License, or (at your option) any later version.
10 ;;;;
11 ;;;; This library 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 GNU
14 ;;;; Lesser General Public License for more details.
15 ;;;;
16 ;;;; You should have received a copy of the GNU Lesser General Public
17 ;;;; License along with this library; if not, write to the Free Software
18 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 (define-module (test-suite test-numbers)
21 #:use-module (test-suite lib)
22 #:use-module (srfi srfi-9))
23
24
25 (define-record-type :foo (make-foo x) foo?
26 (x get-x) (y get-y set-y!))
27
28 (define-record-type :bar (make-bar i j) bar?
29 (i get-i) (i get-j set-j!))
30
31 (define f (make-foo 1))
32 (set-y! f 2)
33
34 (define b (make-bar 123 456))
35
36 (with-test-prefix "constructor"
37
38 (pass-if-exception "foo 0 args" exception:wrong-num-args
39 (make-foo))
40 (pass-if-exception "foo 2 args" exception:wrong-num-args
41 (make-foo 1 2)))
42
43 (with-test-prefix "predicate"
44
45 (pass-if "pass"
46 (foo? f))
47 (pass-if "fail wrong record type"
48 (eq? #f (foo? b)))
49 (pass-if "fail number"
50 (eq? #f (foo? 123))))
51
52 (with-test-prefix "accessor"
53
54 (pass-if "get-x"
55 (= 1 (get-x f)))
56 (pass-if "get-y"
57 (= 2 (get-y f)))
58
59 (pass-if-exception "get-x on number" exception:wrong-type-arg
60 (get-x 999))
61 (pass-if-exception "get-y on number" exception:wrong-type-arg
62 (get-y 999))
63
64 ;; prior to guile 1.6.9 and 1.8.1 this wan't enforced
65 (pass-if-exception "get-x on bar" exception:wrong-type-arg
66 (get-x b))
67 (pass-if-exception "get-y on bar" exception:wrong-type-arg
68 (get-y b)))
69
70 (with-test-prefix "modifier"
71
72 (pass-if "set-y!"
73 (set-y! f #t)
74 (eq? #t (get-y f)))
75
76 (pass-if-exception "set-y! on number" exception:wrong-type-arg
77 (set-y! 999 #t))
78
79 ;; prior to guile 1.6.9 and 1.8.1 this wan't enforced
80 (pass-if-exception "set-y! on bar" exception:wrong-type-arg
81 (set-y! b 99)))