The FSF has a new address.
[bpt/guile.git] / test-suite / tests / srfi-14.test
CommitLineData
072ad0fe
MG
1;;;; srfi-14.test --- Test suite for Guile's SRFI-14 functions. -*- scheme -*-
2;;;; Martin Grabmueller, 2001-07-16
3;;;;
4;;;; Copyright (C) 2001 Free Software Foundation, Inc.
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
072ad0fe
MG
20
21(use-modules (srfi srfi-14))
22
23(define exception:invalid-char-set-cursor
24 (cons 'misc-error "^invalid character set cursor"))
25
26(define exception:non-char-return
27 (cons 'misc-error "returned non-char"))
28
29(with-test-prefix "char-set?"
30
31 (pass-if "success on empty set"
32 (char-set? (char-set)))
33
34 (pass-if "success on non-empty set"
35 (char-set? char-set:printing))
36
37 (pass-if "failure on empty set"
38 (not (char-set? #t))))
39
40
41(with-test-prefix "char-set="
42 (pass-if "success, no arg"
43 (char-set=))
44
45 (pass-if "success, one arg"
46 (char-set= char-set:lower-case))
47
48 (pass-if "success, two args"
49 (char-set= char-set:upper-case char-set:upper-case))
50
51 (pass-if "failure, first empty"
52 (not (char-set= (char-set) (char-set #\a))))
53
54 (pass-if "failure, second empty"
55 (not (char-set= (char-set #\a) (char-set))))
56
57 (pass-if "success, more args"
58 (char-set= char-set:blank char-set:blank char-set:blank)))
59
60(with-test-prefix "char-set<="
61 (pass-if "success, no arg"
62 (char-set<=))
63
64 (pass-if "success, one arg"
65 (char-set<= char-set:lower-case))
66
67 (pass-if "success, two args"
68 (char-set<= char-set:upper-case char-set:upper-case))
69
70 (pass-if "success, first empty"
71 (char-set<= (char-set) (char-set #\a)))
72
73 (pass-if "failure, second empty"
74 (not (char-set<= (char-set #\a) (char-set))))
75
76 (pass-if "success, more args, equal"
77 (char-set<= char-set:blank char-set:blank char-set:blank))
78
79 (pass-if "success, more args, not equal"
80 (char-set<= char-set:blank
81 (char-set-adjoin char-set:blank #\F)
82 (char-set-adjoin char-set:blank #\F #\o))))
83
84(with-test-prefix "char-set-hash"
85 (pass-if "empty set, bound"
86 (let ((h (char-set-hash char-set:empty 31)))
87 (and h (number? h) (exact? h) (>= h 0) (< h 31))))
88
89 (pass-if "empty set, no bound"
90 (let ((h (char-set-hash char-set:empty)))
91 (and h (number? h) (exact? h) (>= h 0))))
92
93 (pass-if "full set, bound"
94 (let ((h (char-set-hash char-set:full 31)))
95 (and h (number? h) (exact? h) (>= h 0) (< h 31))))
96
97 (pass-if "full set, no bound"
98 (let ((h (char-set-hash char-set:full)))
99 (and h (number? h) (exact? h) (>= h 0))))
100
101 (pass-if "other set, bound"
102 (let ((h (char-set-hash (char-set #\f #\o #\b #\a #\r) 31)))
103 (and h (number? h) (exact? h) (>= h 0) (< h 31))))
104
105 (pass-if "other set, no bound"
106 (let ((h (char-set-hash (char-set #\f #\o #\b #\a #\r))))
107 (and h (number? h) (exact? h) (>= h 0)))))
108
109
110(with-test-prefix "char-set cursor"
111
112 (pass-if-exception "invalid character cursor"
113 exception:invalid-char-set-cursor
114 (let* ((cs (char-set #\B #\r #\a #\z))
115 (cc (char-set-cursor cs)))
116 (char-set-ref cs 1000)))
117
118 (pass-if "success"
119 (let* ((cs (char-set #\B #\r #\a #\z))
120 (cc (char-set-cursor cs)))
121 (char? (char-set-ref cs cc))))
122
123 (pass-if "end of set fails"
124 (let* ((cs (char-set #\a))
125 (cc (char-set-cursor cs)))
126 (not (end-of-char-set? cc))))
127
128 (pass-if "end of set succeeds, empty set"
129 (let* ((cs (char-set))
130 (cc (char-set-cursor cs)))
131 (end-of-char-set? cc)))
132
133 (pass-if "end of set succeeds, non-empty set"
134 (let* ((cs (char-set #\a))
135 (cc (char-set-cursor cs))
136 (cc (char-set-cursor-next cs cc)))
137 (end-of-char-set? cc))))
138
139(with-test-prefix "char-set-fold"
140
141 (pass-if "count members"
142 (= (char-set-fold (lambda (c n) (+ n 1)) 0 (char-set #\a #\b)) 2))
143
144 (pass-if "copy set"
145 (= (char-set-size (char-set-fold (lambda (c cs) (char-set-adjoin cs c))
146 (char-set) (char-set #\a #\b))) 2)))
147
148(with-test-prefix "char-set-unfold"
149
150 (pass-if "create char set"
151 (char-set= char-set:full
152 (char-set-unfold (lambda (s) (= s 256)) integer->char
153 (lambda (s) (+ s 1)) 0)))
154 (pass-if "create char set (base set)"
155 (char-set= char-set:full
156 (char-set-unfold (lambda (s) (= s 256)) integer->char
157 (lambda (s) (+ s 1)) 0 char-set:empty))))
158
159(with-test-prefix "char-set-unfold!"
160
161 (pass-if "create char set"
162 (char-set= char-set:full
163 (char-set-unfold! (lambda (s) (= s 256)) integer->char
164 (lambda (s) (+ s 1)) 0
165 (char-set-copy char-set:empty))))
166
167 (pass-if "create char set"
168 (char-set= char-set:full
169 (char-set-unfold! (lambda (s) (= s 32)) integer->char
170 (lambda (s) (+ s 1)) 0
171 (char-set-copy char-set:full)))))
172
173
174(with-test-prefix "char-set-for-each"
175
176 (pass-if "copy char set"
177 (= (char-set-size (let ((cs (char-set)))
178 (char-set-for-each
179 (lambda (c) (char-set-adjoin! cs c))
180 (char-set #\a #\b))
181 cs))
182 2)))
183
184(with-test-prefix "char-set-map"
185
186 (pass-if "upper case char set"
187 (char-set= (char-set-map char-upcase char-set:lower-case)
188 char-set:upper-case)))