1 ;;;; srfi-13.test --- Test suite for Guile's SRFI-13 functions. -*- scheme -*-
2 ;;;; Martin Grabmueller, 2001-05-07
4 ;;;; Copyright (C) 2001, 2004, 2005, 2006 Free Software Foundation, Inc.
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.
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.
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
20 (define-module (test-strings)
21 #:use-module (test-suite lib)
22 #:use-module (srfi srfi-13)
23 #:use-module (srfi srfi-14))
26 (define exception:strict-infix-grammar
27 (cons 'misc-error "^strict-infix"))
29 ;; Create a string from integer char values, eg. (string-ints 65) => "A"
30 (define (string-ints . args)
31 (apply string (map integer->char args)))
34 ;; BMP - Basic Multilingual Plane (codepoints below U+FFFF)
35 ;; SMP - Suplementary Multilingual Plane (codebpoints from U+10000 to U+1FFFF)
41 (with-test-prefix "string-any"
43 (with-test-prefix "bad char_pred"
45 (pass-if-exception "integer" exception:wrong-type-arg
46 (string-any 123 "abcde"))
48 (pass-if-exception "string" exception:wrong-type-arg
49 (string-any "zzz" "abcde")))
51 (with-test-prefix "char"
54 (not (string-any #\C "abcde")))
57 (string-any #\C "abCde"))
59 (pass-if "one match: BMP"
60 (string-any (integer->char #x0100) "ab\u0100de"))
62 (pass-if "one match: SMP"
63 (string-any (integer->char #x010300) "ab\U010300de"))
65 (pass-if "more than one match"
66 (string-any #\X "abXXX"))
68 (pass-if "no match, start index"
69 (not (string-any #\A "Abcde" 1)))
71 (pass-if "one match, start index"
72 (string-any #\C "abCde" 1))
74 (pass-if "more than one match, start index"
75 (string-any #\X "abXXX" 1))
77 (pass-if "no match, start and end index"
78 (not (string-any #\X "XbcdX" 1 4)))
80 (pass-if "one match, start and end index"
81 (string-any #\C "abCde" 1 4))
83 (pass-if "more than one match, start and end index"
84 (string-any #\X "abXXX" 1 4)))
86 (with-test-prefix "charset"
89 (not (string-any char-set:upper-case "abcde")))
92 (string-any char-set:upper-case "abCde"))
94 (pass-if "more than one match"
95 (string-any char-set:upper-case "abCDE"))
97 (pass-if "no match, start index"
98 (not (string-any char-set:upper-case "Abcde" 1)))
100 (pass-if "one match, start index"
101 (string-any char-set:upper-case "abCde" 1))
103 (pass-if "more than one match, start index"
104 (string-any char-set:upper-case "abCDE" 1))
106 (pass-if "no match, start and end index"
107 (not (string-any char-set:upper-case "AbcdE" 1 4)))
109 (pass-if "one match, start and end index"
110 (string-any char-set:upper-case "abCde" 1 4))
112 (pass-if "more than one match, start and end index"
113 (string-any char-set:upper-case "abCDE" 1 4)))
115 (with-test-prefix "pred"
118 (not (string-any char-upper-case? "abcde")))
121 (string-any char-upper-case? "abCde"))
123 (pass-if "more than one match"
124 (string-any char-upper-case? "abCDE"))
126 (pass-if "no match, start index"
127 (not (string-any char-upper-case? "Abcde" 1)))
129 (pass-if "one match, start index"
130 (string-any char-upper-case? "abCde" 1))
132 (pass-if "more than one match, start index"
133 (string-any char-upper-case? "abCDE" 1))
135 (pass-if "no match, start and end index"
136 (not (string-any char-upper-case? "AbcdE" 1 4)))
138 (pass-if "one match, start and end index"
139 (string-any char-upper-case? "abCde" 1 4))
141 (pass-if "more than one match, start and end index"
142 (string-any char-upper-case? "abCDE" 1 4))))
145 ;;; string-append/shared
148 (with-test-prefix "string-append/shared"
151 (string=? "" (string-append/shared)))
153 (with-test-prefix "one arg"
155 (string=? "" (string-append/shared "")))
157 (string=? "xyz" (string-append/shared "xyz"))))
159 (with-test-prefix "two args"
160 (pass-if (string=? "" (string-append/shared "" "")))
161 (pass-if (string=? "xyz" (string-append/shared "xyz" "")))
162 (pass-if (string=? "xyz" (string-append/shared "" "xyz")))
163 (pass-if (string=? "abcxyz" (string-append/shared "abc" "xyz")))
164 (pass-if (string=? "abc\u0100\u0101"
165 (string-append/shared "abc" "\u0100\u0101"))))
167 (with-test-prefix "three args"
168 (pass-if (string=? "" (string-append/shared "" "" "")))
169 (pass-if (string=? "xy" (string-append/shared "xy" "" "")))
170 (pass-if (string=? "xy" (string-append/shared "" "xy" "")))
171 (pass-if (string=? "abxy" (string-append/shared "ab" "xy" "")))
172 (pass-if (string=? "ab" (string-append/shared "" "" "ab")))
173 (pass-if (string=? "xyab" (string-append/shared "xy" "" "ab")))
174 (pass-if (string=? "xyab" (string-append/shared "" "xy" "ab")))
175 (pass-if (string=? "ghxyab" (string-append/shared "gh" "xy" "ab"))))
177 (with-test-prefix "four args"
178 (pass-if (string=? "" (string-append/shared "" "" "" "")))
179 (pass-if (string=? "xy" (string-append/shared "xy" "" "" "")))
180 (pass-if (string=? "xy" (string-append/shared "" "xy" "" "")))
181 (pass-if (string=? "xy" (string-append/shared "" "" "xy" "")))
182 (pass-if (string=? "xy" (string-append/shared "" "" "" "xy")))
184 (pass-if (string=? "abxy" (string-append/shared "ab" "xy" "" "")))
185 (pass-if (string=? "abxy" (string-append/shared "ab" "" "xy" "")))
186 (pass-if (string=? "abxy" (string-append/shared "ab" "" "" "xy")))
187 (pass-if (string=? "abxy" (string-append/shared "" "ab" "" "xy")))
188 (pass-if (string=? "abxy" (string-append/shared "" "" "ab" "xy")))))
191 ;;; string-concatenate
194 (with-test-prefix "string-concatenate"
196 (pass-if-exception "inum" exception:wrong-type-arg
197 (string-concatenate 123))
199 (pass-if-exception "symbol" exception:wrong-type-arg
200 (string-concatenate 'x))
202 (pass-if-exception "improper 1" exception:wrong-type-arg
203 (string-concatenate '("a" . "b")))
205 (pass-if (equal? "abc" (string-concatenate '("a" "b" "c"))))
207 (pass-if "concatenate BMP"
208 (equal? "a\u0100" (string-concatenate '("a" "\u0100")))))
214 (with-test-prefix "string-compare"
216 (pass-if "same as char<?"
217 (eq? (char<? (integer->char 0) (integer->char 255))
218 (string-compare (string-ints 0) (string-ints 255)
219 (lambda (pos) #t) ;; lt
220 (lambda (pos) #f) ;; eq
221 (lambda (pos) #f))))) ;; gt
227 (with-test-prefix "string-compare-ci"
229 (pass-if "same as char-ci<?"
230 (eq? (char-ci<? (integer->char 0) (integer->char 255))
231 (string-compare-ci (string-ints 0) (string-ints 255)
232 (lambda (pos) #t) ;; lt
233 (lambda (pos) #f) ;; eq
234 (lambda (pos) #f))))) ;; gt
237 ;;; string-concatenate/shared
240 (with-test-prefix "string-concatenate/shared"
242 (pass-if-exception "inum" exception:wrong-type-arg
243 (string-concatenate/shared 123))
245 (pass-if-exception "symbol" exception:wrong-type-arg
246 (string-concatenate/shared 'x))
248 (pass-if-exception "improper 1" exception:wrong-type-arg
249 (string-concatenate/shared '("a" . "b")))
251 (pass-if (equal? "abc" (string-concatenate/shared '("a" "b" "c"))))
254 (equal? "a\u0100c" (string-concatenate/shared '("a" "\u0100" "c")))))
260 (with-test-prefix "string-every"
262 (with-test-prefix "bad char_pred"
264 (pass-if-exception "integer" exception:wrong-type-arg
265 (string-every 123 "abcde"))
267 (pass-if-exception "string" exception:wrong-type-arg
268 (string-every "zzz" "abcde")))
270 (with-test-prefix "char"
272 (pass-if "empty string"
273 (string-every #\X ""))
275 (pass-if "empty substring"
276 (string-every #\X "abc" 1 1))
278 (pass-if "no match at all"
279 (not (string-every #\X "abcde")))
281 (pass-if "not all match"
282 (not (string-every #\X "abXXX")))
285 (string-every #\X "XXXXX"))
287 (pass-if "all match BMP"
288 (string-every #\200000 "\U010000\U010000"))
290 (pass-if "no match at all, start index"
291 (not (string-every #\X "Xbcde" 1)))
293 (pass-if "not all match, start index"
294 (not (string-every #\X "XXcde" 1)))
296 (pass-if "all match, start index"
297 (string-every #\X "aXXXX" 1))
299 (pass-if "no match at all, start and end index"
300 (not (string-every #\X "XbcdX" 1 4)))
302 (pass-if "not all match, start and end index"
303 (not (string-every #\X "XXcde" 1 4)))
305 (pass-if "all match, start and end index"
306 (string-every #\X "aXXXe" 1 4)))
308 (with-test-prefix "charset"
310 (pass-if "empty string"
311 (string-every char-set:upper-case ""))
313 (pass-if "empty substring"
314 (string-every char-set:upper-case "abc" 1 1))
316 (pass-if "no match at all"
317 (not (string-every char-set:upper-case "abcde")))
319 (pass-if "not all match"
320 (not (string-every char-set:upper-case "abCDE")))
323 (string-every char-set:upper-case "ABCDE"))
325 (pass-if "no match at all, start index"
326 (not (string-every char-set:upper-case "Abcde" 1)))
328 (pass-if "not all match, start index"
329 (not (string-every char-set:upper-case "ABcde" 1)))
331 (pass-if "all match, start index"
332 (string-every char-set:upper-case "aBCDE" 1))
334 (pass-if "no match at all, start and end index"
335 (not (string-every char-set:upper-case "AbcdE" 1 4)))
337 (pass-if "not all match, start and end index"
338 (not (string-every char-set:upper-case "ABcde" 1 4)))
340 (pass-if "all match, start and end index"
341 (string-every char-set:upper-case "aBCDe" 1 4)))
343 (with-test-prefix "pred"
345 ;; in guile 1.6.4 and earlier string-every incorrectly returned #f on an
347 (pass-if "empty string"
348 (string-every char-upper-case? ""))
349 (pass-if "empty substring"
350 (string-every char-upper-case? "abc" 1 1))
352 (pass-if "no match at all"
353 (not (string-every char-upper-case? "abcde")))
355 (pass-if "not all match"
356 (not (string-every char-upper-case? "abCDE")))
359 (string-every char-upper-case? "ABCDE"))
361 (pass-if "no match at all, start index"
362 (not (string-every char-upper-case? "Abcde" 1)))
364 (pass-if "not all match, start index"
365 (not (string-every char-upper-case? "ABcde" 1)))
367 (pass-if "all match, start index"
368 (string-every char-upper-case? "aBCDE" 1))
370 (pass-if "no match at all, start and end index"
371 (not (string-every char-upper-case? "AbcdE" 1 4)))
373 (pass-if "not all match, start and end index"
374 (not (string-every char-upper-case? "ABcde" 1 4)))
376 (pass-if "all match, start and end index"
377 (string-every char-upper-case? "aBCDe" 1 4))))
379 (with-test-prefix "string-tabulate"
381 (with-test-prefix "bad proc"
383 (pass-if-exception "integer" exception:wrong-type-arg
384 (string-tabulate 123 10))
386 (pass-if-exception "string" exception:wrong-type-arg
387 (string-tabulate "zzz" 10)))
389 (pass-if "static fill-char"
390 (string=? (string-tabulate (lambda (idx) #\!) 10) "!!!!!!!!!!"))
392 (pass-if "variable fill-char"
393 (string=? (string-tabulate
394 (lambda (idx) (integer->char (+ idx 32))) 10) " !\"#$%&'()")))
396 (with-test-prefix "string->list"
399 (zero? (length (string->list ""))))
402 (= (length (string->list "foo")) 3))
404 (pass-if "empty, start index"
405 (zero? (length (string->list "foo" 3 3))))
407 (pass-if "nonempty, start index"
408 (= (length (string->list "foo" 1 3)) 2))
410 (pass-if "nonempty, start index, BMP"
411 (= (length (string->list "\xff\u0100\u0300" 1 3)) 2))
414 (with-test-prefix "reverse-list->string"
417 (string-null? (reverse-list->string '())))
420 (string=? "foo" (reverse-list->string '(#\o #\o #\f))))
422 (pass-if "nonempty, BMP"
423 (string=? "\u0100\u0101\u0102" (reverse-list->string '(#\402 #\401 #\400)))))
425 (with-test-prefix "string-join"
427 (pass-if "empty list, no delimiter, implicit infix, empty 1"
428 (string=? "" (string-join '())))
430 (pass-if "empty string, no delimiter, implicit infix, empty 2"
431 (string=? "" (string-join '(""))))
433 (pass-if "non-empty, no delimiter, implicit infix"
434 (string=? "bla" (string-join '("bla"))))
436 (pass-if "empty list, implicit infix, empty 1"
437 (string=? "" (string-join '() "|delim|")))
439 (pass-if "empty string, implicit infix, empty 2"
440 (string=? "" (string-join '("") "|delim|")))
442 (pass-if "non-empty, implicit infix"
443 (string=? "bla" (string-join '("bla") "|delim|")))
445 (pass-if "non-empty, implicit infix"
446 (string=? "bla" (string-join '("bla") "|delim|")))
448 (pass-if "two strings, implicit infix"
449 (string=? "bla|delim|fasel" (string-join '("bla" "fasel") "|delim|")))
451 (pass-if "empty, explicit infix"
452 (string=? "" (string-join '("") "|delim|" 'infix)))
454 (pass-if "empty list, explicit infix"
455 (string=? "" (string-join '() "|delim|" 'infix)))
457 (pass-if "non-empty, explicit infix"
458 (string=? "bla" (string-join '("bla") "|delim|" 'infix)))
460 (pass-if "two strings, explicit infix"
461 (string=? "bla|delim|fasel" (string-join '("bla" "fasel") "|delim|"
464 (pass-if "two strings, explicit infix, BMP"
465 (string=? "\u0100\u0101::\u0102\u0103"
466 (string-join '("\u0100\u0101" "\u0102\u0103") "::"
469 (pass-if-exception "empty list, strict infix"
470 exception:strict-infix-grammar
471 (string-join '() "|delim|" 'strict-infix))
473 (pass-if "empty, strict infix"
474 (string=? "" (string-join '("") "|delim|" 'strict-infix)))
476 (pass-if "non-empty, strict infix"
477 (string=? "foo" (string-join '("foo") "|delim|" 'strict-infix)))
479 (pass-if "two strings, strict infix"
480 (string=? "foo|delim|bar" (string-join '("foo" "bar") "|delim|"
483 (pass-if "empty list, prefix"
484 (string=? "" (string-join '() "|delim|" 'prefix)))
486 (pass-if "empty, prefix"
487 (string=? "|delim|" (string-join '("") "|delim|" 'prefix)))
489 (pass-if "non-empty, prefix"
490 (string=? "|delim|foo" (string-join '("foo") "|delim|" 'prefix)))
492 (pass-if "two strings, prefix"
493 (string=? "|delim|foo|delim|bar" (string-join '("foo" "bar") "|delim|"
496 (pass-if "empty list, suffix"
497 (string=? "" (string-join '() "|delim|" 'suffix)))
499 (pass-if "empty, suffix"
500 (string=? "|delim|" (string-join '("") "|delim|" 'suffix)))
502 (pass-if "non-empty, suffix"
503 (string=? "foo|delim|" (string-join '("foo") "|delim|" 'suffix)))
505 (pass-if "two strings, suffix"
506 (string=? "foo|delim|bar|delim|" (string-join '("foo" "bar") "|delim|"
509 (with-test-prefix "string-copy"
511 (pass-if "empty string"
512 (string=? "" (string-copy "")))
514 (pass-if "full string"
515 (string=? "foo-bar" (string-copy "foo-bar")))
517 (pass-if "full string, BMP"
518 (string=? "foo-\u0100\u0101" (string-copy "foo-\u0100\u0101")))
520 (pass-if "start index"
521 (string=? "o-bar" (string-copy "foo-bar" 2)))
523 (pass-if "start index"
524 (string=? "o-bar" (string-copy "\u0100\u0101o-bar" 2)))
526 (pass-if "start and end index"
527 (string=? "o-ba" (string-copy "foo-bar" 2 6)))
530 (with-test-prefix "substring/shared"
532 (pass-if "empty string"
533 (eq? "" (substring/shared "" 0)))
535 (pass-if "non-empty string"
536 (string=? "foo" (substring/shared "foo-bar" 0 3)))
538 (pass-if "non-empty string, not eq?"
539 (string=? "foo-bar" (substring/shared "foo-bar" 0 7))))
541 (with-test-prefix "string-copy!"
543 (pass-if "non-empty string"
544 (string=? "welld, oh yeah!"
546 (t (string-copy "world, oh yeah!")))
547 (string-copy! t 1 s 1 3)
550 (with-test-prefix "string-take"
552 (pass-if "empty string"
553 (string=? "" (string-take "foo bar braz" 0)))
555 (pass-if "non-empty string"
556 (string=? "foo " (string-take "foo bar braz" 4)))
558 (pass-if "non-empty string BMP"
559 (string=? "\u0100oo " (string-take "\u0100oo \u0101ar braz" 4)))
561 (pass-if "full string"
562 (string=? "foo bar braz" (string-take "foo bar braz" 12))))
564 (with-test-prefix "string-take-right"
566 (pass-if "empty string"
567 (string=? "" (string-take-right "foo bar braz" 0)))
569 (pass-if "non-empty string"
570 (string=? "braz" (string-take-right "foo bar braz" 4)))
572 (pass-if "non-empty string"
573 (string=? "braz" (string-take-right "foo ba\u0100 braz" 4)))
575 (pass-if "full string"
576 (string=? "foo bar braz" (string-take-right "foo bar braz" 12))))
578 (with-test-prefix "string-drop"
580 (pass-if "empty string"
581 (string=? "" (string-drop "foo bar braz" 12)))
583 (pass-if "non-empty string"
584 (string=? "braz" (string-drop "foo bar braz" 8)))
586 (pass-if "non-empty string BMP"
587 (string=? "braz" (string-drop "foo \u0100\u0101\u0102 braz" 8)))
589 (pass-if "full string"
590 (string=? "foo bar braz" (string-drop "foo bar braz" 0))))
592 (with-test-prefix "string-drop-right"
594 (pass-if "empty string"
595 (string=? "" (string-drop-right "foo bar braz" 12)))
597 (pass-if "non-empty string"
598 (string=? "foo " (string-drop-right "foo bar braz" 8)))
600 (pass-if "non-empty string BMP"
601 (string=? "foo " (string-drop-right "foo \u0100\u0101\u0102 braz" 8)))
603 (pass-if "full string"
604 (string=? "foo bar braz" (string-drop-right "foo bar braz" 0))))
606 (with-test-prefix "string-pad"
608 (pass-if "empty string, zero pad"
609 (string=? "" (string-pad "" 0)))
611 (pass-if "empty string, zero pad, pad char"
612 (string=? "" (string-pad "" 0)))
614 (pass-if "empty pad string, 2 pad "
615 (string=? " " (string-pad "" 2)))
617 (pass-if "empty pad string, 2 pad, pad char"
618 (string=? "!!" (string-pad "" 2 #\!)))
620 (pass-if "empty pad string, 2 pad, pad char, start index"
621 (string=? "!c" (string-pad "abc" 2 #\! 2)))
623 (pass-if "empty pad string, 2 pad, pad char, start and end index"
624 (string=? "!c" (string-pad "abcd" 2 #\! 2 3)))
626 (pass-if "freestyle 1"
627 (string=? "32" (string-pad (number->string 532) 2 #\!)))
629 (pass-if "freestyle 2"
630 (string=? "!532" (string-pad (number->string 532) 4 #\!))))
632 (with-test-prefix "string-pad-right"
634 (pass-if "empty string, zero pad"
635 (string=? "" (string-pad-right "" 0)))
637 (pass-if "empty string, zero pad, pad char"
638 (string=? "" (string-pad-right "" 0)))
640 (pass-if "empty pad string, 2 pad "
641 (string=? " " (string-pad-right "" 2)))
643 (pass-if "empty pad string, 2 pad, pad char"
644 (string=? "!!" (string-pad-right "" 2 #\!)))
646 (pass-if "empty pad string, 2 pad, pad char, start index"
647 (string=? "c!" (string-pad-right "abc" 2 #\! 2)))
649 (pass-if "empty pad string, 2 pad, pad char, start and end index"
650 (string=? "c!" (string-pad-right "abcd" 2 #\! 2 3)))
652 (pass-if "freestyle 1"
653 (string=? "53" (string-pad-right (number->string 532) 2 #\!)))
655 (pass-if "freestyle 2"
656 (string=? "532!" (string-pad-right (number->string 532) 4 #\!))))
658 (with-test-prefix "string-trim"
660 (with-test-prefix "bad char_pred"
662 (pass-if-exception "integer" exception:wrong-type-arg
663 (string-trim "abcde" 123))
665 (pass-if-exception "string" exception:wrong-type-arg
666 (string-trim "abcde" "zzz")))
668 (pass-if "empty string"
669 (string=? "" (string-trim "")))
671 (pass-if "no char/pred"
672 (string=? "foo " (string-trim " \tfoo ")))
674 (pass-if "start index, pred"
675 (string=? "foo " (string-trim " \tfoo " char-whitespace? 1)))
677 (pass-if "start and end index, pred"
678 (string=? "f" (string-trim " \tfoo " char-whitespace? 1 3)))
680 (pass-if "start index, char"
681 (string=? "\tfoo " (string-trim " \tfoo " #\space 1)))
683 (pass-if "start and end index, char"
684 (string=? "\tf" (string-trim " \tfoo " #\space 1 3)))
686 (pass-if "start index, charset"
687 (string=? "foo " (string-trim " \tfoo " char-set:whitespace 1)))
689 (pass-if "start and end index, charset"
690 (string=? "f" (string-trim " \tfoo " char-set:whitespace 1 3))))
692 (with-test-prefix "string-trim-right"
694 (with-test-prefix "bad char_pred"
696 (pass-if-exception "integer" exception:wrong-type-arg
697 (string-trim-right "abcde" 123))
699 (pass-if-exception "string" exception:wrong-type-arg
700 (string-trim-right "abcde" "zzz")))
702 (pass-if "empty string"
703 (string=? "" (string-trim-right "")))
705 (pass-if "no char/pred"
706 (string=? " \tfoo" (string-trim-right " \tfoo ")))
708 (pass-if "start index, pred"
709 (string=? "\tfoo" (string-trim-right " \tfoo " char-whitespace? 1)))
711 (pass-if "start and end index, pred"
712 (string=? "\tf" (string-trim-right " \tfoo " char-whitespace? 1 3)))
714 (pass-if "start index, char"
715 (string=? "\tfoo" (string-trim-right " \tfoo " #\space 1)))
717 (pass-if "start and end index, char"
718 (string=? "\tf" (string-trim-right " \tfoo " #\space 1 3)))
720 (pass-if "start index, charset"
721 (string=? "\tfoo" (string-trim-right " \tfoo " char-set:whitespace 1)))
723 (pass-if "start and end index, charset"
724 (string=? "\tf" (string-trim-right " \tfoo " char-set:whitespace 1 3))))
726 (with-test-prefix "string-trim-both"
728 (with-test-prefix "bad char_pred"
730 (pass-if-exception "integer" exception:wrong-type-arg
731 (string-trim-both "abcde" 123))
733 (pass-if-exception "string" exception:wrong-type-arg
734 (string-trim-both "abcde" "zzz")))
736 (pass-if "empty string"
737 (string=? "" (string-trim-both "")))
739 (pass-if "no char/pred"
740 (string=? "foo" (string-trim-both " \tfoo ")))
742 (pass-if "start index, pred"
743 (string=? "foo" (string-trim-both " \tfoo " char-whitespace? 1)))
745 (pass-if "start and end index, pred"
746 (string=? "f" (string-trim-both " \tfoo " char-whitespace? 1 3)))
748 (pass-if "start index, char"
749 (string=? "\tfoo" (string-trim-both " \tfoo " #\space 1)))
751 (pass-if "start and end index, char"
752 (string=? "\tf" (string-trim-both " \tfoo " #\space 1 3)))
754 (pass-if "start index, charset"
755 (string=? "foo" (string-trim-both " \tfoo " char-set:whitespace 1)))
757 (pass-if "start and end index, charset"
758 (string=? "f" (string-trim-both " \tfoo " char-set:whitespace 1 3))))
760 (define s0 (make-string 200 #\!))
761 (define s1 (make-string 0 #\!))
763 (with-test-prefix "string-fill!"
765 (pass-if "empty string, no indices"
766 (string-fill! s1 #\*)
767 (= (string-length s1) 0))
769 (pass-if "empty string, start index"
770 (string-fill! s1 #\* 0)
771 (= (string-length s1) 0))
773 (pass-if "empty string, start and end index"
774 (string-fill! s1 #\* 0 0)
775 (= (string-length s1) 0))
777 (pass-if "no indices"
778 (string-fill! s0 #\*)
779 (char=? (string-ref s0 0) #\*))
781 (pass-if "start index"
782 (string-fill! s0 #\+ 10)
783 (char=? (string-ref s0 11) #\+))
785 (pass-if "start and end index"
786 (string-fill! s0 #\| 12 20)
787 (char=? (string-ref s0 13) #\|)))
789 (with-test-prefix "string-prefix-length"
791 (pass-if "empty prefix"
792 (= 0 (string-prefix-length "" "foo bar")))
794 (pass-if "non-empty prefix - match"
795 (= 3 (string-prefix-length "foo" "foo bar")))
797 (pass-if "non-empty prefix - no match"
798 (= 0 (string-prefix-length "bar" "foo bar"))))
800 (with-test-prefix "string-prefix-length-ci"
802 (pass-if "empty prefix"
803 (= 0 (string-prefix-length-ci "" "foo bar")))
805 (pass-if "non-empty prefix - match"
806 (= 3 (string-prefix-length-ci "fOo" "foo bar")))
808 (pass-if "non-empty prefix - no match"
809 (= 0 (string-prefix-length-ci "bAr" "foo bar"))))
811 (with-test-prefix "string-suffix-length"
813 (pass-if "empty suffix"
814 (= 0 (string-suffix-length "" "foo bar")))
816 (pass-if "non-empty suffix - match"
817 (= 3 (string-suffix-length "bar" "foo bar")))
819 (pass-if "non-empty suffix - no match"
820 (= 0 (string-suffix-length "foo" "foo bar"))))
822 (with-test-prefix "string-suffix-length-ci"
824 (pass-if "empty suffix"
825 (= 0 (string-suffix-length-ci "" "foo bar")))
827 (pass-if "non-empty suffix - match"
828 (= 3 (string-suffix-length-ci "bAr" "foo bar")))
830 (pass-if "non-empty suffix - no match"
831 (= 0 (string-suffix-length-ci "fOo" "foo bar"))))
833 (with-test-prefix "string-prefix?"
835 (pass-if "empty prefix"
836 (string-prefix? "" "foo bar"))
838 (pass-if "non-empty prefix - match"
839 (string-prefix? "foo" "foo bar"))
841 (pass-if "non-empty prefix - no match"
842 (not (string-prefix? "bar" "foo bar"))))
844 (with-test-prefix "string-prefix-ci?"
846 (pass-if "empty prefix"
847 (string-prefix-ci? "" "foo bar"))
849 (pass-if "non-empty prefix - match"
850 (string-prefix-ci? "fOo" "foo bar"))
852 (pass-if "non-empty prefix - no match"
853 (not (string-prefix-ci? "bAr" "foo bar"))))
855 (with-test-prefix "string-suffix?"
857 (pass-if "empty suffix"
858 (string-suffix? "" "foo bar"))
860 (pass-if "non-empty suffix - match"
861 (string-suffix? "bar" "foo bar"))
863 (pass-if "non-empty suffix - no match"
864 (not (string-suffix? "foo" "foo bar"))))
866 (with-test-prefix "string-suffix-ci?"
868 (pass-if "empty suffix"
869 (string-suffix-ci? "" "foo bar"))
871 (pass-if "non-empty suffix - match"
872 (string-suffix-ci? "bAr" "foo bar"))
874 (pass-if "non-empty suffix - no match"
875 (not (string-suffix-ci? "fOo" "foo bar"))))
877 (with-test-prefix "string-index"
879 (with-test-prefix "bad char_pred"
881 (pass-if-exception "integer" exception:wrong-type-arg
882 (string-index "abcde" 123))
884 (pass-if-exception "string" exception:wrong-type-arg
885 (string-index "abcde" "zzz")))
887 (pass-if "empty string - char"
888 (not (string-index "" #\a)))
890 (pass-if "non-empty - char - match"
891 (= 5 (string-index "foo bar" #\a)))
893 (pass-if "non-empty - char - no match"
894 (not (string-index "frobnicate" #\x)))
896 (pass-if "empty string - char - start index"
897 (not (string-index "" #\a 0)))
899 (pass-if "non-empty - char - match - start index"
900 (= 5 (string-index "foo bar" #\a 1)))
902 (pass-if "non-empty - char - no match - start index"
903 (not (string-index "frobnicate" #\x 2)))
905 (pass-if "empty string - char - start and end index"
906 (not (string-index "" #\a 0 0)))
908 (pass-if "non-empty - char - match - start and end index"
909 (= 5 (string-index "foo bar" #\a 1 6)))
911 (pass-if "non-empty - char - no match - start and end index"
912 (not (string-index "frobnicate" #\a 2 5)))
914 (pass-if "empty string - charset"
915 (not (string-index "" char-set:letter)))
917 (pass-if "non-empty - charset - match"
918 (= 0 (string-index "foo bar" char-set:letter)))
920 (pass-if "non-empty - charset - no match"
921 (not (string-index "frobnicate" char-set:digit)))
923 (pass-if "empty string - charset - start index"
924 (not (string-index "" char-set:letter 0)))
926 (pass-if "non-empty - charset - match - start index"
927 (= 1 (string-index "foo bar" char-set:letter 1)))
929 (pass-if "non-empty - charset - no match - start index"
930 (not (string-index "frobnicate" char-set:digit 2)))
932 (pass-if "empty string - charset - start and end index"
933 (not (string-index "" char-set:letter 0 0)))
935 (pass-if "non-empty - charset - match - start and end index"
936 (= 1 (string-index "foo bar" char-set:letter 1 6)))
938 (pass-if "non-empty - charset - no match - start and end index"
939 (not (string-index "frobnicate" char-set:digit 2 5)))
941 (pass-if "empty string - pred"
942 (not (string-index "" char-alphabetic?)))
944 (pass-if "non-empty - pred - match"
945 (= 0 (string-index "foo bar" char-alphabetic?)))
947 (pass-if "non-empty - pred - no match"
948 (not (string-index "frobnicate" char-numeric?)))
950 (pass-if "empty string - pred - start index"
951 (not (string-index "" char-alphabetic? 0)))
953 (pass-if "non-empty - pred - match - start index"
954 (= 1 (string-index "foo bar" char-alphabetic? 1)))
956 (pass-if "non-empty - pred - no match - start index"
957 (not (string-index "frobnicate" char-numeric? 2)))
959 (pass-if "empty string - pred - start and end index"
960 (not (string-index "" char-alphabetic? 0 0)))
962 (pass-if "non-empty - pred - match - start and end index"
963 (= 1 (string-index "foo bar" char-alphabetic? 1 6)))
965 (pass-if "non-empty - pred - no match - start and end index"
966 (not (string-index "frobnicate" char-numeric? 2 5)))
968 ;; in guile 1.6.7 and earlier this resulted in a segv, because
969 ;; SCM_MAKE_CHAR didn't cope with "signed char" arguments containing an
971 (pass-if "8-bit char in string"
973 (string-index (string (integer->char 200)) char-numeric?)
976 (with-test-prefix "string-index-right"
978 (with-test-prefix "bad char_pred"
980 (pass-if-exception "integer" exception:wrong-type-arg
981 (string-index-right "abcde" 123))
983 (pass-if-exception "string" exception:wrong-type-arg
984 (string-index-right "abcde" "zzz")))
986 (pass-if "empty string - char"
987 (not (string-index-right "" #\a)))
989 (pass-if "non-empty - char - match"
990 (= 5 (string-index-right "foo bar" #\a)))
992 (pass-if "non-empty - char - no match"
993 (not (string-index-right "frobnicate" #\x)))
995 (pass-if "empty string - char - start index-right"
996 (not (string-index-right "" #\a 0)))
998 (pass-if "non-empty - char - match - start index"
999 (= 5 (string-index-right "foo bar" #\a 1)))
1001 (pass-if "non-empty - char - no match - start index"
1002 (not (string-index-right "frobnicate" #\x 2)))
1004 (pass-if "empty string - char - start and end index"
1005 (not (string-index-right "" #\a 0 0)))
1007 (pass-if "non-empty - char - match - start and end index"
1008 (= 5 (string-index-right "foo bar" #\a 1 6)))
1010 (pass-if "non-empty - char - no match - start and end index"
1011 (not (string-index-right "frobnicate" #\a 2 5)))
1013 (pass-if "empty string - charset"
1014 (not (string-index-right "" char-set:letter)))
1016 (pass-if "non-empty - charset - match"
1017 (= 6 (string-index-right "foo bar" char-set:letter)))
1019 (pass-if "non-empty - charset - no match"
1020 (not (string-index-right "frobnicate" char-set:digit)))
1022 (pass-if "empty string - charset - start index"
1023 (not (string-index-right "" char-set:letter 0)))
1025 (pass-if "non-empty - charset - match - start index"
1026 (= 6 (string-index-right "foo bar" char-set:letter 1)))
1028 (pass-if "non-empty - charset - no match - start index"
1029 (not (string-index-right "frobnicate" char-set:digit 2)))
1031 (pass-if "empty string - charset - start and end index"
1032 (not (string-index-right "" char-set:letter 0 0)))
1034 (pass-if "non-empty - charset - match - start and end index"
1035 (= 5 (string-index-right "foo bar" char-set:letter 1 6)))
1037 (pass-if "non-empty - charset - no match - start and end index"
1038 (not (string-index-right "frobnicate" char-set:digit 2 5)))
1040 (pass-if "empty string - pred"
1041 (not (string-index-right "" char-alphabetic?)))
1043 (pass-if "non-empty - pred - match"
1044 (= 6 (string-index-right "foo bar" char-alphabetic?)))
1046 (pass-if "non-empty - pred - no match"
1047 (not (string-index-right "frobnicate" char-numeric?)))
1049 (pass-if "empty string - pred - start index"
1050 (not (string-index-right "" char-alphabetic? 0)))
1052 (pass-if "non-empty - pred - match - start index"
1053 (= 6 (string-index-right "foo bar" char-alphabetic? 1)))
1055 (pass-if "non-empty - pred - no match - start index"
1056 (not (string-index-right "frobnicate" char-numeric? 2)))
1058 (pass-if "empty string - pred - start and end index"
1059 (not (string-index-right "" char-alphabetic? 0 0)))
1061 (pass-if "non-empty - pred - match - start and end index"
1062 (= 5 (string-index-right "foo bar" char-alphabetic? 1 6)))
1064 (pass-if "non-empty - pred - no match - start and end index"
1065 (not (string-index-right "frobnicate" char-numeric? 2 5))))
1067 (with-test-prefix "string-skip"
1069 (with-test-prefix "bad char_pred"
1071 (pass-if-exception "integer" exception:wrong-type-arg
1072 (string-skip "abcde" 123))
1074 (pass-if-exception "string" exception:wrong-type-arg
1075 (string-skip "abcde" "zzz")))
1077 (pass-if "empty string - char"
1078 (not (string-skip "" #\a)))
1080 (pass-if "non-empty - char - match"
1081 (= 0 (string-skip "foo bar" #\a)))
1083 (pass-if "non-empty - char - no match"
1084 (= 0 (string-skip "frobnicate" #\x)))
1086 (pass-if "empty string - char - start index"
1087 (not (string-skip "" #\a 0)))
1089 (pass-if "non-empty - char - match - start index"
1090 (= 1 (string-skip "foo bar" #\a 1)))
1092 (pass-if "non-empty - char - no match - start index"
1093 (= 2 (string-skip "frobnicate" #\x 2)))
1095 (pass-if "empty string - char - start and end index"
1096 (not (string-skip "" #\a 0 0)))
1098 (pass-if "non-empty - char - match - start and end index"
1099 (= 1 (string-skip "foo bar" #\a 1 6)))
1101 (pass-if "non-empty - char - no match - start and end index"
1102 (= 2 (string-skip "frobnicate" #\a 2 5)))
1104 (pass-if "empty string - charset"
1105 (not (string-skip "" char-set:letter)))
1107 (pass-if "non-empty - charset - match"
1108 (= 3 (string-skip "foo bar" char-set:letter)))
1110 (pass-if "non-empty - charset - no match"
1111 (= 0 (string-skip "frobnicate" char-set:digit)))
1113 (pass-if "empty string - charset - start index"
1114 (not (string-skip "" char-set:letter 0)))
1116 (pass-if "non-empty - charset - match - start index"
1117 (= 3 (string-skip "foo bar" char-set:letter 1)))
1119 (pass-if "non-empty - charset - no match - start index"
1120 (= 2 (string-skip "frobnicate" char-set:digit 2)))
1122 (pass-if "empty string - charset - start and end index"
1123 (not (string-skip "" char-set:letter 0 0)))
1125 (pass-if "non-empty - charset - match - start and end index"
1126 (= 3 (string-skip "foo bar" char-set:letter 1 6)))
1128 (pass-if "non-empty - charset - no match - start and end index"
1129 (= 2 (string-skip "frobnicate" char-set:digit 2 5)))
1131 (pass-if "empty string - pred"
1132 (not (string-skip "" char-alphabetic?)))
1134 (pass-if "non-empty - pred - match"
1135 (= 3 (string-skip "foo bar" char-alphabetic?)))
1137 (pass-if "non-empty - pred - no match"
1138 (= 0 (string-skip "frobnicate" char-numeric?)))
1140 (pass-if "empty string - pred - start index"
1141 (not (string-skip "" char-alphabetic? 0)))
1143 (pass-if "non-empty - pred - match - start index"
1144 (= 3 (string-skip "foo bar" char-alphabetic? 1)))
1146 (pass-if "non-empty - pred - no match - start index"
1147 (= 2 (string-skip "frobnicate" char-numeric? 2)))
1149 (pass-if "empty string - pred - start and end index"
1150 (not (string-skip "" char-alphabetic? 0 0)))
1152 (pass-if "non-empty - pred - match - start and end index"
1153 (= 3 (string-skip "foo bar" char-alphabetic? 1 6)))
1155 (pass-if "non-empty - pred - no match - start and end index"
1156 (= 2 (string-skip "frobnicate" char-numeric? 2 5))))
1158 (with-test-prefix "string-skip-right"
1160 (with-test-prefix "bad char_pred"
1162 (pass-if-exception "integer" exception:wrong-type-arg
1163 (string-skip-right "abcde" 123))
1165 (pass-if-exception "string" exception:wrong-type-arg
1166 (string-skip-right "abcde" "zzz")))
1168 (pass-if "empty string - char"
1169 (not (string-skip-right "" #\a)))
1171 (pass-if "non-empty - char - match"
1172 (= 6 (string-skip-right "foo bar" #\a)))
1174 (pass-if "non-empty - char - no match"
1175 (= 9 (string-skip-right "frobnicate" #\x)))
1177 (pass-if "empty string - char - start index-right"
1178 (not (string-skip-right "" #\a 0)))
1180 (pass-if "non-empty - char - match - start index"
1181 (= 6 (string-skip-right "foo bar" #\a 1)))
1183 (pass-if "non-empty - char - no match - start index"
1184 (= 9 (string-skip-right "frobnicate" #\x 2)))
1186 (pass-if "empty string - char - start and end index"
1187 (not (string-skip-right "" #\a 0 0)))
1189 (pass-if "non-empty - char - match - start and end index"
1190 (= 4 (string-skip-right "foo bar" #\a 1 6)))
1192 (pass-if "non-empty - char - no match - start and end index"
1193 (= 4 (string-skip-right "frobnicate" #\a 2 5)))
1195 (pass-if "empty string - charset"
1196 (not (string-skip-right "" char-set:letter)))
1198 (pass-if "non-empty - charset - match"
1199 (= 3 (string-skip-right "foo bar" char-set:letter)))
1201 (pass-if "non-empty - charset - no match"
1202 (= 9 (string-skip-right "frobnicate" char-set:digit)))
1204 (pass-if "empty string - charset - start index"
1205 (not (string-skip-right "" char-set:letter 0)))
1207 (pass-if "non-empty - charset - match - start index"
1208 (= 3 (string-skip-right "foo bar" char-set:letter 1)))
1210 (pass-if "non-empty - charset - no match - start index"
1211 (= 9 (string-skip-right "frobnicate" char-set:digit 2)))
1213 (pass-if "empty string - charset - start and end index"
1214 (not (string-skip-right "" char-set:letter 0 0)))
1216 (pass-if "non-empty - charset - match - start and end index"
1217 (= 3 (string-skip-right "foo bar" char-set:letter 1 6)))
1219 (pass-if "non-empty - charset - no match - start and end index"
1220 (= 4 (string-skip-right "frobnicate" char-set:digit 2 5)))
1222 (pass-if "empty string - pred"
1223 (not (string-skip-right "" char-alphabetic?)))
1225 (pass-if "non-empty - pred - match"
1226 (= 3 (string-skip-right "foo bar" char-alphabetic?)))
1228 (pass-if "non-empty - pred - no match"
1229 (= 9 (string-skip-right "frobnicate" char-numeric?)))
1231 (pass-if "empty string - pred - start index"
1232 (not (string-skip-right "" char-alphabetic? 0)))
1234 (pass-if "non-empty - pred - match - start index"
1235 (= 3 (string-skip-right "foo bar" char-alphabetic? 1)))
1237 (pass-if "non-empty - pred - no match - start index"
1238 (= 9 (string-skip-right "frobnicate" char-numeric? 2)))
1240 (pass-if "empty string - pred - start and end index"
1241 (not (string-skip-right "" char-alphabetic? 0 0)))
1243 (pass-if "non-empty - pred - match - start and end index"
1244 (= 3 (string-skip-right "foo bar" char-alphabetic? 1 6)))
1246 (pass-if "non-empty - pred - no match - start and end index"
1247 (= 4 (string-skip-right "frobnicate" char-numeric? 2 5))))
1253 (with-test-prefix "string-count"
1255 (with-test-prefix "bad char_pred"
1257 (pass-if-exception "integer" exception:wrong-type-arg
1258 (string-count "abcde" 123))
1260 (pass-if-exception "string" exception:wrong-type-arg
1261 (string-count "abcde" "zzz")))
1263 (with-test-prefix "char"
1265 (pass-if (eqv? 0 (string-count "" #\a)))
1266 (pass-if (eqv? 0 (string-count "-" #\a)))
1267 (pass-if (eqv? 1 (string-count "a" #\a)))
1268 (pass-if (eqv? 0 (string-count "--" #\a)))
1269 (pass-if (eqv? 1 (string-count "a-" #\a)))
1270 (pass-if (eqv? 1 (string-count "-a" #\a)))
1271 (pass-if (eqv? 2 (string-count "aa" #\a)))
1272 (pass-if (eqv? 0 (string-count "---" #\a)))
1273 (pass-if (eqv? 1 (string-count "-a-" #\a)))
1274 (pass-if (eqv? 1 (string-count "a--" #\a)))
1275 (pass-if (eqv? 2 (string-count "aa-" #\a)))
1276 (pass-if (eqv? 2 (string-count "a-a" #\a)))
1277 (pass-if (eqv? 3 (string-count "aaa" #\a)))
1278 (pass-if (eqv? 1 (string-count "--a" #\a)))
1279 (pass-if (eqv? 2 (string-count "-aa" #\a))))
1281 (with-test-prefix "charset"
1283 (pass-if (eqv? 0 (string-count "" char-set:letter)))
1284 (pass-if (eqv? 0 (string-count "-" char-set:letter)))
1285 (pass-if (eqv? 1 (string-count "a" char-set:letter)))
1286 (pass-if (eqv? 0 (string-count "--" char-set:letter)))
1287 (pass-if (eqv? 1 (string-count "a-" char-set:letter)))
1288 (pass-if (eqv? 1 (string-count "-a" char-set:letter)))
1289 (pass-if (eqv? 2 (string-count "aa" char-set:letter)))
1290 (pass-if (eqv? 0 (string-count "---" char-set:letter)))
1291 (pass-if (eqv? 1 (string-count "-a-" char-set:letter)))
1292 (pass-if (eqv? 1 (string-count "a--" char-set:letter)))
1293 (pass-if (eqv? 2 (string-count "aa-" char-set:letter)))
1294 (pass-if (eqv? 2 (string-count "a-a" char-set:letter)))
1295 (pass-if (eqv? 3 (string-count "aaa" char-set:letter)))
1296 (pass-if (eqv? 1 (string-count "--a" char-set:letter)))
1297 (pass-if (eqv? 2 (string-count "-aa" char-set:letter))))
1299 (with-test-prefix "proc"
1301 (pass-if (eqv? 0 (string-count "" char-alphabetic?)))
1302 (pass-if (eqv? 0 (string-count "-" char-alphabetic?)))
1303 (pass-if (eqv? 1 (string-count "a" char-alphabetic?)))
1304 (pass-if (eqv? 0 (string-count "--" char-alphabetic?)))
1305 (pass-if (eqv? 1 (string-count "a-" char-alphabetic?)))
1306 (pass-if (eqv? 1 (string-count "-a" char-alphabetic?)))
1307 (pass-if (eqv? 2 (string-count "aa" char-alphabetic?)))
1308 (pass-if (eqv? 0 (string-count "---" char-alphabetic?)))
1309 (pass-if (eqv? 1 (string-count "-a-" char-alphabetic?)))
1310 (pass-if (eqv? 1 (string-count "a--" char-alphabetic?)))
1311 (pass-if (eqv? 2 (string-count "aa-" char-alphabetic?)))
1312 (pass-if (eqv? 2 (string-count "a-a" char-alphabetic?)))
1313 (pass-if (eqv? 3 (string-count "aaa" char-alphabetic?)))
1314 (pass-if (eqv? 1 (string-count "--a" char-alphabetic?)))
1315 (pass-if (eqv? 2 (string-count "-aa" char-alphabetic?)))))
1318 (with-test-prefix "string-replace"
1320 (pass-if "empty string(s), no indices"
1321 (string=? "" (string-replace "" "")))
1323 (pass-if "empty string(s), 1 index"
1324 (string=? "" (string-replace "" "" 0)))
1326 (pass-if "empty string(s), 2 indices"
1327 (string=? "" (string-replace "" "" 0 0)))
1329 (pass-if "empty string(s), 3 indices"
1330 (string=? "" (string-replace "" "" 0 0 0)))
1332 (pass-if "empty string(s), 4 indices"
1333 (string=? "" (string-replace "" "" 0 0 0 0)))
1335 (pass-if "no indices"
1336 (string=? "uu" (string-replace "foo bar" "uu")))
1338 (pass-if "one index"
1339 (string=? "fuu" (string-replace "foo bar" "uu" 1)))
1341 (pass-if "two indices"
1342 (string=? "fuuar" (string-replace "foo bar" "uu" 1 5)))
1344 (pass-if "three indices"
1345 (string=? "fuar" (string-replace "foo bar" "uu" 1 5 1)))
1347 (pass-if "four indices"
1348 (string=? "fuar" (string-replace "foo bar" "uu" 1 5 1 2))))
1350 (with-test-prefix "string-tokenize"
1352 (pass-if "empty string, no char/pred"
1353 (zero? (length (string-tokenize ""))))
1355 (pass-if "empty string, charset"
1356 (zero? (length (string-tokenize "" char-set:punctuation))))
1358 (pass-if "no char/pred"
1359 (equal? '("foo" "bar" "!a") (string-tokenize "foo\tbar !a")))
1362 (equal? '("foo" "bar" "!a") (string-tokenize "foo\tbar !a"
1365 (pass-if "charset, start index"
1366 (equal? '("oo" "bar" "!a") (string-tokenize "foo\tbar !a"
1367 char-set:graphic 1)))
1369 (pass-if "charset, start and end index"
1370 (equal? '("oo" "bar" "!") (string-tokenize "foo\tbar !a"
1371 char-set:graphic 1 9))))
1376 (with-test-prefix "string-filter"
1378 (with-test-prefix "bad char_pred"
1380 (pass-if-exception "integer" exception:wrong-type-arg
1381 (string-filter "abcde" 123))
1383 (pass-if-exception "string" exception:wrong-type-arg
1384 (string-filter "abcde" "zzz")))
1386 (pass-if "empty string, char"
1387 (string=? "" (string-filter "" #\.)))
1389 (pass-if "empty string, charset"
1390 (string=? "" (string-filter "" char-set:punctuation)))
1392 (pass-if "empty string, pred"
1393 (string=? "" (string-filter "" char-alphabetic?)))
1396 (string=? "..." (string-filter ".foo.bar." #\.)))
1399 (string=? "..." (string-filter ".foo.bar." char-set:punctuation)))
1402 (string=? "foobar" (string-filter ".foo.bar." char-alphabetic?)))
1404 (pass-if "char, start index"
1405 (string=? ".." (string-filter ".foo.bar." #\. 2)))
1407 (pass-if "charset, start index"
1408 (string=? ".." (string-filter ".foo.bar." char-set:punctuation 2)))
1410 (pass-if "pred, start index"
1411 (string=? "oobar" (string-filter ".foo.bar." char-alphabetic? 2)))
1413 (pass-if "char, start and end index"
1414 (string=? "" (string-filter ".foo.bar." #\. 2 4)))
1416 (pass-if "charset, start and end index"
1417 (string=? "" (string-filter ".foo.bar." char-set:punctuation 2 4)))
1419 (pass-if "pred, start and end index"
1420 (string=? "oo" (string-filter ".foo.bar." char-alphabetic? 2 4)))
1422 (with-test-prefix "char"
1424 (pass-if (equal? "x" (string-filter "x" #\x)))
1425 (pass-if (equal? "xx" (string-filter "xx" #\x)))
1426 (pass-if (equal? "xx" (string-filter "xyx" #\x)))
1427 (pass-if (equal? "x" (string-filter "xyyy" #\x)))
1428 (pass-if (equal? "x" (string-filter "yyyx" #\x)))
1430 (pass-if (equal? "xx" (string-filter "xxx" #\x 1)))
1431 (pass-if (equal? "xx" (string-filter "xxx" #\x 0 2)))
1432 (pass-if (equal? "x" (string-filter "xyx" #\x 1)))
1433 (pass-if (equal? "x" (string-filter "yxx" #\x 0 2)))
1435 ;; leading and trailing removals
1436 (pass-if (string=? "" (string-filter "." #\x)))
1437 (pass-if (string=? "" (string-filter ".." #\x)))
1438 (pass-if (string=? "" (string-filter "..." #\x)))
1439 (pass-if (string=? "x" (string-filter ".x" #\x)))
1440 (pass-if (string=? "x" (string-filter "..x" #\x)))
1441 (pass-if (string=? "x" (string-filter "...x" #\x)))
1442 (pass-if (string=? "x" (string-filter "x." #\x)))
1443 (pass-if (string=? "x" (string-filter "x.." #\x)))
1444 (pass-if (string=? "x" (string-filter "x..." #\x)))
1445 (pass-if (string=? "x" (string-filter "...x..." #\x))))
1447 (with-test-prefix "charset"
1449 (let ((charset (char-set #\x #\y)))
1450 (pass-if (equal? "x" (string-filter "x" charset)))
1451 (pass-if (equal? "xx" (string-filter "xx" charset)))
1452 (pass-if (equal? "xy" (string-filter "xy" charset)))
1453 (pass-if (equal? "x" (string-filter "xaaa" charset)))
1454 (pass-if (equal? "y" (string-filter "aaay" charset)))
1456 (pass-if (equal? "yx" (string-filter "xyx" charset 1)))
1457 (pass-if (equal? "xy" (string-filter "xyx" charset 0 2)))
1458 (pass-if (equal? "x" (string-filter "xax" charset 1)))
1459 (pass-if (equal? "x" (string-filter "axx" charset 0 2))))
1461 ;; leading and trailing removals
1462 (pass-if (string=? "" (string-filter "." char-set:letter)))
1463 (pass-if (string=? "" (string-filter ".." char-set:letter)))
1464 (pass-if (string=? "" (string-filter "..." char-set:letter)))
1465 (pass-if (string=? "x" (string-filter ".x" char-set:letter)))
1466 (pass-if (string=? "x" (string-filter "..x" char-set:letter)))
1467 (pass-if (string=? "x" (string-filter "...x" char-set:letter)))
1468 (pass-if (string=? "x" (string-filter "x." char-set:letter)))
1469 (pass-if (string=? "x" (string-filter "x.." char-set:letter)))
1470 (pass-if (string=? "x" (string-filter "x..." char-set:letter)))
1471 (pass-if (string=? "x" (string-filter "...x..." char-set:letter)))))
1477 (with-test-prefix "string-delete"
1479 (with-test-prefix "bad char_pred"
1481 (pass-if-exception "integer" exception:wrong-type-arg
1482 (string-delete "abcde" 123))
1484 (pass-if-exception "string" exception:wrong-type-arg
1485 (string-delete "abcde" "zzz")))
1487 (pass-if "empty string, char"
1488 (string=? "" (string-delete "" #\.)))
1490 (pass-if "empty string, charset"
1491 (string=? "" (string-delete "" char-set:punctuation)))
1493 (pass-if "empty string, pred"
1494 (string=? "" (string-delete "" char-alphabetic?)))
1497 (string=? "foobar" (string-delete ".foo.bar." #\.)))
1500 (string=? "foobar" (string-delete ".foo.bar." char-set:punctuation)))
1503 (string=? "..." (string-delete ".foo.bar." char-alphabetic?)))
1505 (pass-if "char, start index"
1506 (string=? "oobar" (string-delete ".foo.bar." #\. 2)))
1508 (pass-if "charset, start index"
1509 (string=? "oobar" (string-delete ".foo.bar." char-set:punctuation 2)))
1511 (pass-if "pred, start index"
1512 (string=? ".." (string-delete ".foo.bar." char-alphabetic? 2)))
1514 (pass-if "char, start and end index"
1515 (string=? "oo" (string-delete ".foo.bar." #\. 2 4)))
1517 (pass-if "charset, start and end index"
1518 (string=? "oo" (string-delete ".foo.bar." char-set:punctuation 2 4)))
1520 (pass-if "pred, start and end index"
1521 (string=? "" (string-delete ".foo.bar." char-alphabetic? 2 4)))
1523 ;; leading and trailing removals
1524 (pass-if (string=? "" (string-delete "." #\.)))
1525 (pass-if (string=? "" (string-delete ".." #\.)))
1526 (pass-if (string=? "" (string-delete "..." #\.)))
1527 (pass-if (string=? "x" (string-delete ".x" #\.)))
1528 (pass-if (string=? "x" (string-delete "..x" #\.)))
1529 (pass-if (string=? "x" (string-delete "...x" #\.)))
1530 (pass-if (string=? "x" (string-delete "x." #\.)))
1531 (pass-if (string=? "x" (string-delete "x.." #\.)))
1532 (pass-if (string=? "x" (string-delete "x..." #\.)))
1533 (pass-if (string=? "x" (string-delete "...x..." #\.)))
1535 ;; leading and trailing removals
1536 (pass-if (string=? "" (string-delete "." char-set:punctuation)))
1537 (pass-if (string=? "" (string-delete ".." char-set:punctuation)))
1538 (pass-if (string=? "" (string-delete "..." char-set:punctuation)))
1539 (pass-if (string=? "x" (string-delete ".x" char-set:punctuation)))
1540 (pass-if (string=? "x" (string-delete "..x" char-set:punctuation)))
1541 (pass-if (string=? "x" (string-delete "...x" char-set:punctuation)))
1542 (pass-if (string=? "x" (string-delete "x." char-set:punctuation)))
1543 (pass-if (string=? "x" (string-delete "x.." char-set:punctuation)))
1544 (pass-if (string=? "x" (string-delete "x..." char-set:punctuation)))
1545 (pass-if (string=? "x" (string-delete "...x..." char-set:punctuation))))
1548 (with-test-prefix "string-map"
1550 (with-test-prefix "bad proc"
1552 (pass-if-exception "integer" exception:wrong-type-arg
1553 (string-map 123 "abcde"))
1555 (pass-if-exception "string" exception:wrong-type-arg
1556 (string-map "zzz" "abcde")))
1559 (string=? "xxx" (string-map (lambda (c) #\x) "foo")))
1562 (string=? "foo" (string-map identity "foo")))
1565 (string=? "FOO" (string-map char-upcase "foo"))))
1567 (with-test-prefix "string-map!"
1569 (with-test-prefix "bad proc"
1571 (pass-if-exception "integer" exception:wrong-type-arg
1572 (string-map 123 "abcde"))
1574 (pass-if-exception "string" exception:wrong-type-arg
1575 (string-map "zzz" "abcde")))
1578 (let ((str (string-copy "foo")))
1579 (string-map! (lambda (c) #\x) str)
1580 (string=? str "xxx")))
1583 (let ((str (string-copy "foo")))
1584 (string-map! identity str)
1585 (string=? str "foo")))
1588 (let ((str (string-copy "foo")))
1589 (string-map! char-upcase str)
1590 (string=? str "FOO"))))
1592 (with-test-prefix "string-for-each"
1594 (with-test-prefix "bad proc"
1596 (pass-if-exception "integer" exception:wrong-type-arg
1597 (string-for-each 123 "abcde"))
1599 (pass-if-exception "string" exception:wrong-type-arg
1600 (string-for-each "zzz" "abcde")))
1604 (bar (make-string (string-length foo)))
1607 (lambda (c) (string-set! bar i c) (set! i (1+ i))) foo)
1608 (string=? foo bar))))
1610 (with-test-prefix "string-for-each-index"
1612 (with-test-prefix "bad proc"
1614 (pass-if-exception "integer" exception:wrong-type-arg
1615 (string-for-each-index 123 "abcde"))
1617 (pass-if-exception "string" exception:wrong-type-arg
1618 (string-for-each-index "zzz" "abcde")))
1622 (bar (make-string (string-length foo))))
1623 (string-for-each-index
1624 (lambda (i) (string-set! bar i (string-ref foo i))) foo)
1625 (string=? foo bar))))