| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
(define (vowel? c) |
| 9 |
(member c '(#\a #\e #\i #\o #\u))) |
| 10 |
|
| 11 |
(define-test-suite srfi-14-tests) |
| 12 |
|
| 13 |
(define-test-case char-set? srfi-14-tests |
| 14 |
(check (not (char-set? 5))) |
| 15 |
(check (char-set? (char-set #\a #\e #\i #\o #\u)))) |
| 16 |
|
| 17 |
(define-test-case char-set= srfi-14-tests |
| 18 |
(check (char-set=)) |
| 19 |
(check (char-set= (char-set))) |
| 20 |
(check (string->char-set "ioeauaiii") |
| 21 |
(=> char-set=) |
| 22 |
(char-set #\a #\e #\i #\o #\u)) |
| 23 |
(check (not (char-set= (string->char-set "ioeauaiii") |
| 24 |
(char-set #\e #\i #\o #\u))))) |
| 25 |
|
| 26 |
(define-test-case char-set<= srfi-14-tests |
| 27 |
(check (char-set<=)) |
| 28 |
(check (char-set<= (char-set))) |
| 29 |
(check (char-set<= (char-set #\a #\e #\i #\o #\u) |
| 30 |
(string->char-set "ioeauaiii"))) |
| 31 |
(check (char-set<= (char-set #\e #\i #\o #\u) |
| 32 |
(string->char-set "ioeauaiii")))) |
| 33 |
|
| 34 |
(define-test-case char-set-hash srfi-14-tests |
| 35 |
(check-that (char-set-hash char-set:graphic 100) |
| 36 |
(all-of (is (lambda (x) (>= x 0))) |
| 37 |
(is (lambda (x) (<= x 99)))))) |
| 38 |
|
| 39 |
(define-test-case char-set-fold srfi-14-tests |
| 40 |
(check (char-set-fold (lambda (c i) (+ i 1)) 0 |
| 41 |
(char-set #\e #\i #\o #\u #\e #\e)) |
| 42 |
=> 4)) |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
(define-test-case char-set-unfold srfi-14-tests |
| 50 |
(check-that (char-set-unfold null? car cdr '(#\a #\e #\i #\o #\u) |
| 51 |
(string->char-set "0123456789")) |
| 52 |
(is char-set= |
| 53 |
(string->char-set "eiaou246801357999")))) |
| 54 |
|
| 55 |
(define-test-case char-set-unfold! srfi-14-tests |
| 56 |
(check-that (char-set-unfold! null? car cdr '(#\a #\e #\i #\o #\u) |
| 57 |
(string->char-set "0123456789")) |
| 58 |
(opposite (is char-set= |
| 59 |
(string->char-set "eiaou246801357"))))) |
| 60 |
|
| 61 |
(define-test-case char-set-for-each srfi-14-tests |
| 62 |
(let ((cs (string->char-set "0123456789"))) |
| 63 |
(char-set-for-each (lambda (c) (set! cs (char-set-delete cs c))) |
| 64 |
(string->char-set "02468000")) |
| 65 |
(check-that cs (is char-set= (string->char-set "97531")))) |
| 66 |
|
| 67 |
(let ((cs (string->char-set "0123456789"))) |
| 68 |
(char-set-for-each (lambda (c) (set! cs (char-set-delete cs c))) |
| 69 |
(string->char-set "02468")) |
| 70 |
(check-that cs (opposite (is char-set= (string->char-set "7531")))))) |
| 71 |
|
| 72 |
(define-test-case char-set-map srfi-14-tests |
| 73 |
(check-that (char-set-map char-upcase (string->char-set "aeiou")) |
| 74 |
(is char-set= |
| 75 |
(string->char-set "IOUAEEEE"))) |
| 76 |
(check-that (char-set-map char-upcase (string->char-set "aeiou")) |
| 77 |
(opposite (is char-set= |
| 78 |
(string->char-set "OUAEEEE"))))) |
| 79 |
|
| 80 |
(define-test-case char-set-copy srfi-14-tests |
| 81 |
(check-that (char-set-copy (string->char-set "aeiou")) |
| 82 |
(is char-set= (string->char-set "aeiou")))) |
| 83 |
|
| 84 |
(define-test-case char-set srfi-14-tests |
| 85 |
(check-that (char-set #\x #\y) (is char-set= (string->char-set "xy"))) |
| 86 |
(check-that (char-set #\x #\y #\z) (opposite (is char-set= (string->char-set "xy"))))) |
| 87 |
|
| 88 |
(define-test-case list->char-set srfi-14-tests |
| 89 |
(check-that (list->char-set '(#\x #\y)) (is char-set= (string->char-set "xy"))) |
| 90 |
(check-that (list->char-set '(#\x #\y)) (opposite (is char-set= (string->char-set "axy")))) |
| 91 |
(check-that (list->char-set '(#\x #\y) (string->char-set "12345")) |
| 92 |
(is char-set= (string->char-set "xy12345"))) |
| 93 |
(check-that (list->char-set '(#\x #\y) (string->char-set "12345")) |
| 94 |
(opposite (is char-set= (string->char-set "y12345"))))) |
| 95 |
|
| 96 |
(define-test-case list->char-set! srfi-14-tests |
| 97 |
(check-that (list->char-set! '(#\x #\y) (string->char-set "12345")) |
| 98 |
(is char-set= (string->char-set "xy12345"))) |
| 99 |
(check-that (list->char-set! '(#\x #\y) (string->char-set "12345")) |
| 100 |
(opposite (is char-set= (string->char-set "y12345"))))) |
| 101 |
|
| 102 |
(define-test-case char-set-filter srfi-14-tests |
| 103 |
(check-that (char-set-filter vowel? char-set:ascii (string->char-set "12345")) |
| 104 |
(is char-set= (string->char-set "aeiou12345"))) |
| 105 |
(check-that (char-set-filter vowel? char-set:ascii (string->char-set "12345")) |
| 106 |
(opposite (is char-set= (string->char-set "aeou12345"))))) |
| 107 |
|
| 108 |
(define-test-case char-set-filter! srfi-14-tests |
| 109 |
(check-that (char-set-filter! vowel? char-set:ascii (string->char-set "12345")) |
| 110 |
(is char-set= (string->char-set "aeiou12345"))) |
| 111 |
(check-that (char-set-filter! vowel? char-set:ascii (string->char-set "12345")) |
| 112 |
(opposite (is char-set= (string->char-set "aeou12345"))))) |
| 113 |
|
| 114 |
(define-test-case ucs-range->char-set srfi-14-tests |
| 115 |
(check-that (ucs-range->char-set 97 103 #t (string->char-set "12345")) |
| 116 |
(is char-set= (string->char-set "abcdef12345"))) |
| 117 |
(check-that (ucs-range->char-set 97 103 #t (string->char-set "12345")) |
| 118 |
(opposite (is char-set= (string->char-set "abcef12345"))))) |
| 119 |
|
| 120 |
(define-test-case ucs-range_>char-set! srfi-14-tests |
| 121 |
(check-that (ucs-range->char-set! 97 103 #t (string->char-set "12345")) |
| 122 |
(is char-set= (string->char-set "abcdef12345"))) |
| 123 |
(check-that (ucs-range->char-set! 97 103 #t (string->char-set "12345")) |
| 124 |
(opposite (is char-set= (string->char-set "abcef12345"))))) |
| 125 |
|
| 126 |
(define-test-case x->char-set srfi-14-tests |
| 127 |
(check-that (x->char-set #\x) (is char-set= (x->char-set "x"))) |
| 128 |
(check-that (x->char-set #\x) (is char-set= (x->char-set (char-set #\x)))) |
| 129 |
(check-that (x->char-set "y") |
| 130 |
(opposite (is char-set= (x->char-set #\x))))) |
| 131 |
|
| 132 |
(define-test-case char-set-size srfi-14-tests |
| 133 |
(check (char-set-size (char-set-intersection char-set:ascii char-set:digit)) |
| 134 |
=> 10)) |
| 135 |
|
| 136 |
(define-test-case char-set-count srfi-14-tests |
| 137 |
(check (char-set-count vowel? char-set:ascii) |
| 138 |
=> 5)) |
| 139 |
|
| 140 |
(define-test-case char-set->list srfi-14-tests |
| 141 |
(check (char-set->list (char-set #\x)) => '(#\x)) |
| 142 |
(check-that (char-set->list (char-set #\x)) (opposite (is '(#\X))))) |
| 143 |
|
| 144 |
(define-test-case char-set->string srfi-14-tests |
| 145 |
(check (char-set->string (char-set #\x)) => "x") |
| 146 |
(check-that (char-set->string (char-set #\x)) (opposite (is "X" )))) |
| 147 |
|
| 148 |
(define-test-case char-set-contains? srfi-14-tests |
| 149 |
(check (char-set-contains? (x->char-set "xyz") #\x)) |
| 150 |
(check (not (char-set-contains? (x->char-set "xyz") #\a)))) |
| 151 |
|
| 152 |
(define-test-case char-set-every srfi-14-tests |
| 153 |
(check (char-set-every char-lower-case? (x->char-set "abcd"))) |
| 154 |
(check-that (char-set-every char-lower-case? (x->char-set "abcD")) (is-false))) |
| 155 |
|
| 156 |
(define-test-case char-set-any srfi-14-tests |
| 157 |
(check (char-set-any char-lower-case? (x->char-set "abcd"))) |
| 158 |
(check-that (char-set-any char-lower-case? (x->char-set "ABCD")) (is-false))) |
| 159 |
|
| 160 |
(define-test-case cursors srfi-14-tests |
| 161 |
(check-that |
| 162 |
(let ((cs (x->char-set "abcd"))) |
| 163 |
(let lp ((cur (char-set-cursor cs)) (ans '())) |
| 164 |
(if (end-of-char-set? cur) (list->char-set ans) |
| 165 |
(lp (char-set-cursor-next cs cur) |
| 166 |
(cons (char-upcase (char-set-ref cs cur)) ans))))) |
| 167 |
(is char-set= |
| 168 |
(x->char-set "ABCD")))) |
| 169 |
|
| 170 |
(define-test-case char-set-adjoin srfi-14-tests |
| 171 |
(check-that (char-set-adjoin (x->char-set "123") #\x #\a) |
| 172 |
(is char-set= (x->char-set "123xa"))) |
| 173 |
(check-that (x->char-set "123x") |
| 174 |
(opposite (is char-set= (char-set-adjoin (x->char-set "123") #\x #\a))))) |
| 175 |
|
| 176 |
(define-test-case char-set-adjoin! srfi-14-tests |
| 177 |
(check-that (char-set-adjoin! (x->char-set "123") #\x #\a) |
| 178 |
(is char-set= (x->char-set "123xa"))) |
| 179 |
(check-that (x->char-set "123x") |
| 180 |
(opposite (is char-set= (char-set-adjoin! (x->char-set "123") #\x #\a))))) |
| 181 |
|
| 182 |
(define-test-case char-set-delete srfi-14-tests |
| 183 |
(check-that (char-set-delete (x->char-set "123") #\2 #\a #\2) |
| 184 |
(is char-set= (x->char-set "13"))) |
| 185 |
(check-that (char-set-delete (x->char-set "123") #\2 #\a #\2) |
| 186 |
(opposite (is char-set= (x->char-set "13a"))))) |
| 187 |
|
| 188 |
(define-test-case char-set-delete! srfi-14-tests |
| 189 |
(check-that (char-set-delete! (x->char-set "123") #\2 #\a #\2) |
| 190 |
(is char-set= (x->char-set "13"))) |
| 191 |
(check-that (char-set-delete! (x->char-set "123") #\2 #\a #\2) |
| 192 |
(opposite (is char-set= (x->char-set "13a"))))) |
| 193 |
|
| 194 |
(define-test-case char-set-intersection srfi-14-tests |
| 195 |
(check-that |
| 196 |
(char-set-intersection char-set:hex-digit (char-set-complement char-set:digit)) |
| 197 |
(is char-set= |
| 198 |
(x->char-set "abcdefABCDEF")))) |
| 199 |
|
| 200 |
(define-test-case char-set-intersection! srfi-14-tests |
| 201 |
(check-that |
| 202 |
(char-set-intersection! (char-set-complement! (x->char-set "0123456789")) |
| 203 |
char-set:hex-digit) |
| 204 |
(is char-set= |
| 205 |
(x->char-set "abcdefABCDEF")))) |
| 206 |
|
| 207 |
(define-test-case char-set-union srfi-14-tests |
| 208 |
(check-that |
| 209 |
(char-set-union char-set:hex-digit |
| 210 |
(x->char-set "abcdefghijkl")) |
| 211 |
(is char-set= |
| 212 |
(x->char-set "abcdefABCDEFghijkl0123456789")))) |
| 213 |
|
| 214 |
(define-test-case char-set-union! srfi-14-tests |
| 215 |
(check-that |
| 216 |
(char-set-union! (x->char-set "abcdefghijkl") |
| 217 |
char-set:hex-digit) |
| 218 |
(is char-set= |
| 219 |
(x->char-set "abcdefABCDEFghijkl0123456789")))) |
| 220 |
|
| 221 |
(define-test-case char-set-difference srfi-14-tests |
| 222 |
(check-that |
| 223 |
(char-set-difference (x->char-set "abcdefghijklmn") |
| 224 |
char-set:hex-digit) |
| 225 |
(is char-set= |
| 226 |
(x->char-set "ghijklmn")))) |
| 227 |
|
| 228 |
(define-test-case char-set-difference! srfi-14-tests |
| 229 |
(check-that |
| 230 |
(char-set-difference! (x->char-set "abcdefghijklmn") |
| 231 |
char-set:hex-digit) |
| 232 |
(is char-set= |
| 233 |
(x->char-set "ghijklmn")))) |
| 234 |
|
| 235 |
(define-test-case char-set-xor srfi-14-tests |
| 236 |
(check-that |
| 237 |
(char-set-xor (x->char-set "0123456789") |
| 238 |
char-set:hex-digit) |
| 239 |
(is char-set= |
| 240 |
(x->char-set "abcdefABCDEF")))) |
| 241 |
|
| 242 |
(define-test-case char-set-xor! srfi-14-tests char-set= |
| 243 |
(check-that (char-set-xor! (x->char-set "0123456789") |
| 244 |
char-set:hex-digit) |
| 245 |
(is char-set= (x->char-set "abcdefABCDEF")))) |
| 246 |
|
| 247 |
(define-test-case char-set-diff+intersection srfi-14-tests |
| 248 |
(call-with-values (lambda () |
| 249 |
(char-set-diff+intersection char-set:hex-digit |
| 250 |
char-set:letter)) |
| 251 |
(lambda (d i) |
| 252 |
(check-that d (is char-set= (x->char-set "0123456789"))) |
| 253 |
(check-that i (is char-set= (x->char-set "abcdefABCDEF"))))) |
| 254 |
(call-with-values (lambda () |
| 255 |
(char-set-diff+intersection (char-set-union char-set:letter |
| 256 |
char-set:digit) |
| 257 |
char-set:letter)) |
| 258 |
(lambda (d i) |
| 259 |
(check-that d (is char-set= char-set:digit)) |
| 260 |
(check-that i (is char-set= char-set:letter))))) |
| 261 |
|
| 262 |
(define-test-case char-set-diff+intersection! srfi-14-tests |
| 263 |
(call-with-values (lambda () |
| 264 |
(char-set-diff+intersection! (char-set-copy char-set:hex-digit) |
| 265 |
(char-set-copy char-set:letter))) |
| 266 |
(lambda (d i) |
| 267 |
(check-that d (is char-set= (x->char-set "0123456789"))) |
| 268 |
(check-that i (is char-set= (x->char-set "abcdefABCDEF"))))) |
| 269 |
(call-with-values (lambda () |
| 270 |
(char-set-diff+intersection! (char-set-union char-set:letter |
| 271 |
char-set:digit) |
| 272 |
(char-set-copy char-set:letter))) |
| 273 |
(lambda (d i) |
| 274 |
(check-that d (is char-set= char-set:digit)) |
| 275 |
(check-that i (is char-set= char-set:letter))))) |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
(define-test-case char-set:lower-case srfi-14-tests |
| 281 |
(check (char-set-contains? char-set:lower-case #\a)) |
| 282 |
(check (not (char-set-contains? char-set:lower-case #\A))) |
| 283 |
(check (char-set-contains? char-set:lower-case (scalar-value->char #x00E0))) |
| 284 |
(check (not (char-set-contains? char-set:lower-case (scalar-value->char #x00C2)))) |
| 285 |
(check (char-set-contains? char-set:lower-case (scalar-value->char #x00B5)))) |
| 286 |
|
| 287 |
(define-test-case char-set:upper-case srfi-14-tests |
| 288 |
(check (char-set-contains? char-set:upper-case #\A)) |
| 289 |
(check (not (char-set-contains? char-set:upper-case #\a))) |
| 290 |
(check (char-set-contains? char-set:upper-case (scalar-value->char #x00C2))) |
| 291 |
(check (not (char-set-contains? char-set:upper-case (scalar-value->char #x00E0))))) |
| 292 |
|
| 293 |
(define-test-case char-set:title-case srfi-14-tests |
| 294 |
(check (char-set-contains? char-set:title-case (scalar-value->char #x01C5))) |
| 295 |
(check (char-set-contains? char-set:title-case (scalar-value->char #x1FA8))) |
| 296 |
(check (not (char-set-contains? char-set:title-case #\a))) |
| 297 |
(check (not (char-set-contains? char-set:title-case #\A)))) |
| 298 |
|
| 299 |
(define-test-case char-set:letter srfi-14-tests |
| 300 |
(check (char-set-contains? char-set:letter #\a)) |
| 301 |
(check (char-set-contains? char-set:letter #\A)) |
| 302 |
(check (not (char-set-contains? char-set:letter #\1))) |
| 303 |
(check (char-set-contains? char-set:letter (scalar-value->char #x00AA))) |
| 304 |
(check (char-set-contains? char-set:letter (scalar-value->char #x00BA)))) |
| 305 |
|
| 306 |
(define-test-case char-set:lower-case/2 srfi-14-tests |
| 307 |
(check (not (char-set-every (lambda (c) (char-set-contains? char-set:lower-case c)) char-set:letter))) |
| 308 |
(check (char-set-any (lambda (c) (char-set-contains? char-set:lower-case c)) char-set:letter))) |
| 309 |
|
| 310 |
(define-test-case char-set:upper-case/2 srfi-14-tests |
| 311 |
(check (not (char-set-every (lambda (c) (char-set-contains? char-set:upper-case c)) char-set:letter))) |
| 312 |
(check (char-set-any (lambda (c) (char-set-contains? char-set:upper-case c)) char-set:letter))) |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
(define-test-case char-set:digit srfi-14-tests |
| 318 |
(check (char-set-contains? char-set:digit #\1)) |
| 319 |
(check (not (char-set-contains? char-set:digit #\a)))) |
| 320 |
|
| 321 |
(define-test-case char-set:hex-digit srfi-14-tests |
| 322 |
(check (char-set-contains? char-set:hex-digit #\1)) |
| 323 |
(check (char-set-contains? char-set:hex-digit #\a)) |
| 324 |
(check (char-set-contains? char-set:hex-digit #\A)) |
| 325 |
(check (not (char-set-contains? char-set:hex-digit #\g)))) |
| 326 |
|
| 327 |
(define-test-case char-set:letter+digit srfi-14-tests equal? |
| 328 |
(check (char-set-contains? char-set:letter+digit #\1)) |
| 329 |
(check (char-set-contains? char-set:letter+digit #\a)) |
| 330 |
(check (char-set-contains? char-set:letter+digit #\z)) |
| 331 |
(check (char-set-contains? char-set:letter+digit #\A)) |
| 332 |
(check (char-set-contains? char-set:letter+digit #\Z))) |
| 333 |
|
| 334 |
(define-test-case char-set:letter/size srfi-14-tests |
| 335 |
(check (char-set-size char-set:letter) => 92496)) |
| 336 |
|
| 337 |
(define-test-case char-set:letter/2 srfi-14-tests |
| 338 |
(check-that (char-set-union char-set:letter char-set:digit) |
| 339 |
(is char-set= |
| 340 |
char-set:letter+digit)) |
| 341 |
(check (not (char-set-every (lambda (c) (char-set-contains? char-set:letter c)) char-set:letter+digit))) |
| 342 |
(check (not (char-set-every (lambda (c) (char-set-contains? char-set:digit c)) char-set:letter+digit))) |
| 343 |
(check (char-set-any (lambda (c) (char-set-contains? char-set:letter c)) char-set:letter+digit))) |
| 344 |
|
| 345 |
(define-test-case char-set:letter+digit/2 srfi-14-tests |
| 346 |
(check (char-set-every (lambda (c) (char-set-contains? char-set:letter+digit c)) char-set:letter)) |
| 347 |
(check (char-set-every (lambda (c) (char-set-contains? char-set:letter+digit c)) char-set:digit))) |
| 348 |
|
| 349 |
(define char-set:latin-1 (ucs-range->char-set 0 256)) |
| 350 |
|
| 351 |
(define-test-case char-set:latin-1 srfi-14-tests |
| 352 |
(check-that |
| 353 |
(char-set-intersection (char-set-union char-set:letter char-set:digit char-set:punctuation char-set:symbol) |
| 354 |
char-set:latin-1) |
| 355 |
(is char-set= |
| 356 |
(char-set-intersection char-set:graphic char-set:latin-1)))) |
| 357 |
|
| 358 |
(define-test-case char-set:printing srfi-14-tests |
| 359 |
(check-that (char-set-union char-set:graphic char-set:whitespace) |
| 360 |
(is char-set= char-set:printing))) |
| 361 |
|
| 362 |
(define-test-case char-set:whitespace srfi-14-tests |
| 363 |
(check (char-set-contains? char-set:whitespace (scalar-value->char #x0009))) |
| 364 |
(check (char-set-contains? char-set:whitespace (scalar-value->char #x000D))) |
| 365 |
(check (not (char-set-contains? char-set:whitespace #\a)))) |
| 366 |
|
| 367 |
(define-test-case char-set:iso-control srfi-14-tests |
| 368 |
(check-that (char-set-union (ucs-range->char-set #x0000 #x0020) |
| 369 |
(ucs-range->char-set #x007F #x00A0)) |
| 370 |
(is char-set= |
| 371 |
char-set:iso-control))) |
| 372 |
|
| 373 |
(define-test-case char-set:punctuation srfi-14-tests |
| 374 |
(check (char-set-contains? char-set:punctuation #\!)) |
| 375 |
(check (char-set-contains? char-set:punctuation (scalar-value->char #x00A1))) |
| 376 |
(check (not (char-set-contains? char-set:punctuation #\a)))) |
| 377 |
|
| 378 |
(define-test-case char-set:symbol srfi-14-tests |
| 379 |
(check (char-set-contains? char-set:symbol #\$)) |
| 380 |
(check (char-set-contains? char-set:symbol (scalar-value->char #x00A2))) |
| 381 |
(check (not (char-set-contains? char-set:symbol #\a)))) |
| 382 |
|
| 383 |
(define-test-case char-set:blank srfi-14-tests |
| 384 |
(check (char-set-contains? char-set:blank #\space)) |
| 385 |
(check (char-set-contains? char-set:blank (scalar-value->char #x3000))) |
| 386 |
(check (not (char-set-contains? char-set:blank #\a)))) |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
(define-test-case char-set=/2 srfi-14-tests |
| 391 |
(check (char-set= char-set:letter char-set:letter char-set:letter)) |
| 392 |
(check (not (char-set= char-set:letter char-set:digit))) |
| 393 |
(check (not (char-set= char-set:letter char-set:letter char-set:digit))) |
| 394 |
(check (not (char-set= char-set:letter char-set:digit char-set:letter)))) |
| 395 |
|
| 396 |
(define-test-case char-set<=/2 srfi-14-tests |
| 397 |
(check (char-set<= char-set:graphic char-set:printing)) |
| 398 |
(check (not (char-set<= char-set:printing char-set:graphic))) |
| 399 |
(check (char-set<= char-set:graphic char-set:printing char-set:full)) |
| 400 |
(check (not (char-set<= char-set:graphic char-set:full char-set:printing)))) |
| 401 |
|
| 402 |
(define-test-case char-set-hash/2 srfi-14-tests |
| 403 |
(check (char-set-hash char-set:graphic) |
| 404 |
=> |
| 405 |
(char-set-hash char-set:graphic))) |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
(define-test-case char-set-size/2 srfi-14-tests |
| 411 |
(check (char-set-size char-set:digit) |
| 412 |
=> 290)) |
| 413 |
|
| 414 |
(define-test-case cursors/2 srfi-14-tests |
| 415 |
(check-that (list->char-set |
| 416 |
(let loop ((c (char-set-cursor char-set:digit)) (l '())) |
| 417 |
(if (end-of-char-set? c) |
| 418 |
l |
| 419 |
(loop (char-set-cursor-next char-set:digit c) |
| 420 |
(cons (char-set-ref char-set:digit c) |
| 421 |
l))))) |
| 422 |
(is char-set= char-set:digit))) |
| 423 |
|
| 424 |
(define (add1 x) (+ 1 x)) |
| 425 |
|
| 426 |
(define-test-case char-set-unfold/2 srfi-14-tests |
| 427 |
(check-that |
| 428 |
(char-set-unfold (lambda (x) (= x 20)) scalar-value->char add1 10) |
| 429 |
(is char-set= (ucs-range->char-set 10 20))) |
| 430 |
(check-that |
| 431 |
(char-set-unfold (lambda (x) (= x 20)) scalar-value->char add1 10 (char-set (scalar-value->char #x14))) |
| 432 |
(is char-set= |
| 433 |
(ucs-range->char-set 10 21)))) |
| 434 |
|
| 435 |
(define-test-case char-set-unfold!/2 srfi-14-tests |
| 436 |
(check-that |
| 437 |
(char-set-unfold! (lambda (x) (= x 20)) scalar-value->char add1 10 |
| 438 |
(char-set-copy char-set:empty)) |
| 439 |
(is char-set= (ucs-range->char-set 10 20)))) |
| 440 |
|
| 441 |
(define-test-case char-set-for-each/2 srfi-14-tests |
| 442 |
(check-that |
| 443 |
(let ((cs char-set:empty)) |
| 444 |
(char-set-for-each |
| 445 |
(lambda (c) |
| 446 |
(set! cs (char-set-adjoin cs c))) |
| 447 |
char-set:digit) |
| 448 |
cs) |
| 449 |
(is char-set= char-set:digit))) |
| 450 |
|
| 451 |
(define-test-case char-set-map/2 srfi-14-tests equal? |
| 452 |
(check-that (char-set-map |
| 453 |
(lambda (c) c) |
| 454 |
char-set:digit) |
| 455 |
(is char-set= char-set:digit)) |
| 456 |
(check-that (char-set-map |
| 457 |
(lambda (c) c) |
| 458 |
char-set:digit) |
| 459 |
(is char-set= char-set:digit)) |
| 460 |
(check-that (char-set-union |
| 461 |
(char-set-map |
| 462 |
(lambda (c) c) |
| 463 |
char-set:digit) |
| 464 |
(char-set #\A)) |
| 465 |
(is char-set= (char-set-adjoin char-set:digit #\A)))) |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
(define-test-case char-set-copy/2 srfi-14-tests |
| 470 |
(check-that (char-set-copy char-set:digit) |
| 471 |
(is char-set= char-set:digit))) |
| 472 |
|
| 473 |
(define-test-case abc srfi-14-tests |
| 474 |
(let ((abc (char-set #\a #\b #\c))) |
| 475 |
(check-that (char-set #\c #\a #\b) |
| 476 |
(is char-set= |
| 477 |
abc)) |
| 478 |
(check-that (string->char-set "cba") (is char-set= abc)) |
| 479 |
(check-that (string->char-set! "cba" (char-set-copy char-set:empty)) (is char-set= abc)) |
| 480 |
(check-that (string->char-set "cb" (char-set #\a)) (is char-set= abc)) |
| 481 |
(check-that (char-set-filter (lambda (c) (char=? c #\b)) abc) (is char-set= (char-set #\b))) |
| 482 |
(check-that (char-set-filter (lambda (c) (char=? c #\b)) abc char-set:empty) (is char-set= (char-set #\b))) |
| 483 |
(check-that (char-set-filter! (lambda (c) (char=? c #\b)) (char-set-copy abc) (char-set-copy char-set:empty)) |
| 484 |
(is char-set= (char-set #\b))) |
| 485 |
|
| 486 |
(check-that (x->char-set "abc") (is char-set= abc)) |
| 487 |
(check-that (x->char-set abc) (is char-set= abc)) |
| 488 |
(check-that (x->char-set #\a) (is char-set= (char-set #\a))))) |
| 489 |
|
| 490 |
(define-test-case ucs-range->char/2 srfi-14-tests |
| 491 |
(check-that |
| 492 |
(char-set-union (ucs-range->char-set 0 #xD800) |
| 493 |
(ucs-range->char-set #xE000 #x20000)) |
| 494 |
(is char-set= (ucs-range->char-set 0 #x20000))) |
| 495 |
(check-that |
| 496 |
(ucs-range->char-set 0 #xD800) |
| 497 |
(is char-set= (ucs-range->char-set 0 #xD801))) |
| 498 |
(check-that |
| 499 |
(ucs-range->char-set 0 #xD800) |
| 500 |
(is char-set= (ucs-range->char-set 0 #xDFFF))) |
| 501 |
(check-that |
| 502 |
char-set:empty |
| 503 |
(is char-set= (ucs-range->char-set #xD800 #xD810))) |
| 504 |
(check-that |
| 505 |
char-set:empty |
| 506 |
(is char-set= (ucs-range->char-set #xD810 #xE000))) |
| 507 |
(check-that |
| 508 |
(ucs-range->char-set #xD810 #xE001) |
| 509 |
(is char-set= (ucs-range->char-set #xE000 #xE001))) |
| 510 |
(check-that |
| 511 |
(char-set (scalar-value->char #xD7FF) (scalar-value->char #xE000)) |
| 512 |
(is char-set= (ucs-range->char-set #xD7FF #xE001)))) |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
(define-test-case char-set-count/2 srfi-14-tests |
| 517 |
(check |
| 518 |
(char-set-count (lambda (x) |
| 519 |
(and (char<=? #\0 x) |
| 520 |
(char<=? x #\2))) |
| 521 |
char-set:digit) |
| 522 |
=> 3)) |
| 523 |
|
| 524 |
(define-test-case list->char-set/2 srfi-14-tests |
| 525 |
(check-that (list->char-set (char-set->list char-set:digit)) |
| 526 |
(is char-set= char-set:digit)) |
| 527 |
(check-that (list->char-set (char-set->list char-set:digit) char-set:empty) |
| 528 |
(is char-set= char-set:digit)) |
| 529 |
(check-that (list->char-set! (char-set->list char-set:digit) (char-set-copy char-set:empty)) |
| 530 |
(is char-set= char-set:digit)) |
| 531 |
(check-that (string->char-set (char-set->string char-set:digit)) |
| 532 |
(is char-set= char-set:digit))) |
| 533 |
|
| 534 |
|