Commit | Line | Data |
---|---|---|
f764e6d1 MG |
1 | ;;;; srfi-9.test --- Test suite for Guile's SRFI-9 functions. -*- scheme -*- |
2 | ;;;; Martin Grabmueller, 2001-05-10 | |
3 | ;;;; | |
30a700c8 | 4 | ;;;; Copyright (C) 2001, 2006, 2007, 2010 Free Software Foundation, Inc. |
f764e6d1 | 5 | ;;;; |
53befeb7 NJ |
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. | |
f764e6d1 | 10 | ;;;; |
53befeb7 | 11 | ;;;; This library is distributed in the hope that it will be useful, |
f764e6d1 | 12 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
53befeb7 NJ |
13 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | ;;;; Lesser General Public License for more details. | |
f764e6d1 | 15 | ;;;; |
53befeb7 NJ |
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 | |
f764e6d1 | 19 | |
8ab3d8a0 KR |
20 | (define-module (test-suite test-numbers) |
21 | #:use-module (test-suite lib) | |
30a700c8 | 22 | #:use-module ((system base compile) #:select (compile)) |
8ab3d8a0 KR |
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 | ||
30a700c8 LC |
39 | ;; Constructors are defined using `define-integrable', meaning that direct |
40 | ;; calls as in `(make-foo)' lead to a compile-time psyntax error, hence the | |
41 | ;; distinction below. | |
42 | ||
43 | (pass-if-exception "foo 0 args (inline)" exception:syntax-pattern-unmatched | |
44 | (compile '(make-foo) #:env (current-module))) | |
45 | (pass-if-exception "foo 2 args (inline)" exception:syntax-pattern-unmatched | |
46 | (compile '(make-foo 1 2) #:env (current-module))) | |
47 | ||
8ab3d8a0 | 48 | (pass-if-exception "foo 0 args" exception:wrong-num-args |
30a700c8 LC |
49 | (let ((make-foo make-foo)) |
50 | (make-foo))) | |
8ab3d8a0 | 51 | (pass-if-exception "foo 2 args" exception:wrong-num-args |
30a700c8 LC |
52 | (let ((make-foo make-foo)) |
53 | (make-foo 1 2)))) | |
8ab3d8a0 KR |
54 | |
55 | (with-test-prefix "predicate" | |
f764e6d1 | 56 | |
8ab3d8a0 | 57 | (pass-if "pass" |
f764e6d1 | 58 | (foo? f)) |
8ab3d8a0 KR |
59 | (pass-if "fail wrong record type" |
60 | (eq? #f (foo? b))) | |
61 | (pass-if "fail number" | |
62 | (eq? #f (foo? 123)))) | |
f764e6d1 | 63 | |
8ab3d8a0 | 64 | (with-test-prefix "accessor" |
f764e6d1 | 65 | |
8ab3d8a0 KR |
66 | (pass-if "get-x" |
67 | (= 1 (get-x f))) | |
68 | (pass-if "get-y" | |
f764e6d1 MG |
69 | (= 2 (get-y f))) |
70 | ||
3ba9acb1 | 71 | (pass-if-exception "get-x on number" exception:wrong-type-arg |
8ab3d8a0 | 72 | (get-x 999)) |
3ba9acb1 | 73 | (pass-if-exception "get-y on number" exception:wrong-type-arg |
8ab3d8a0 KR |
74 | (get-y 999)) |
75 | ||
76 | ;; prior to guile 1.6.9 and 1.8.1 this wan't enforced | |
77 | (pass-if-exception "get-x on bar" exception:wrong-type-arg | |
78 | (get-x b)) | |
79 | (pass-if-exception "get-y on bar" exception:wrong-type-arg | |
80 | (get-y b))) | |
81 | ||
82 | (with-test-prefix "modifier" | |
83 | ||
84 | (pass-if "set-y!" | |
f764e6d1 | 85 | (set-y! f #t) |
8ab3d8a0 KR |
86 | (eq? #t (get-y f))) |
87 | ||
3ba9acb1 | 88 | (pass-if-exception "set-y! on number" exception:wrong-type-arg |
8ab3d8a0 KR |
89 | (set-y! 999 #t)) |
90 | ||
91 | ;; prior to guile 1.6.9 and 1.8.1 this wan't enforced | |
92 | (pass-if-exception "set-y! on bar" exception:wrong-type-arg | |
93 | (set-y! b 99))) |