| 1 |
;; (import (except (scheme base) |
| 2 |
;; string=? string<? string>? string<=? string>=?) |
| 3 |
;; (except (scheme char) |
| 4 |
;; string-ci=? string-ci<? string-ci>? string-ci<=? string-ci>=?) |
| 5 |
;; (srfi-152)) |
| 6 |
|
| 7 |
;; (cond-expand |
| 8 |
;; ((library (chibi test)) |
| 9 |
;; (import (chibi test))) |
| 10 |
;; ((library (srfi 64)) |
| 11 |
;; (import (srfi 64)) |
| 12 |
;; (define-syntax test |
| 13 |
;; (syntax-rules () |
| 14 |
;; ((_ arg ...) (test-equal arg ...)))) |
| 15 |
;; (define-syntax test-exit |
| 16 |
;; (syntax-rules () |
| 17 |
;; ((_) (test-end)))) |
| 18 |
;; (test-begin "srfi-152 top")) |
| 19 |
;; (else |
| 20 |
;; (error "no suitable test framework available"))) |
| 21 |
|
| 22 |
(define (complement proc) (lambda (x) (not (proc x)))) |
| 23 |
(define (char-newline? ch) (eqv? ch #\newline)) |
| 24 |
(define (char-is-r? ch) (eqv? ch #\r)) |
| 25 |
(define (char-is-colon? ch) (eqv? ch #\:)) |
| 26 |
(define (char-is-a? ch) (eqv? ch #\a)) |
| 27 |
(define (char-is-space? ch) (eq? ch #\space)) |
| 28 |
|
| 29 |
;; artefact of converting from cursors to indexes and back |
| 30 |
(define (dummy-index string index) index) |
| 31 |
|
| 32 |
(define ABC "abc") |
| 33 |
|
| 34 |
(test-group "srfi-152" |
| 35 |
(test-group "srfi-152:gauche" |
| 36 |
(test-group "srfi-152:gauche:predicates" |
| 37 |
(test "string-null?" #f (string-null? "abc")) |
| 38 |
(test "string-null?" #t (string-null? "")) |
| 39 |
(test "string-every" #t (string-every char-is-a? "")) |
| 40 |
(test "string-every" #t (string-every char-is-a? "aaaa")) |
| 41 |
(test "string-every" #f (string-every char-is-a? "aaba")) |
| 42 |
(test "string-every" #t (string-every char-lower-case? "aaba")) |
| 43 |
(test "string-every" #f (string-every char-lower-case? "aAba")) |
| 44 |
(test "string-every" #t (string-every char-lower-case? "")) |
| 45 |
(test "string-every" #t (string-every (lambda (x) (char-ci=? x #\a)) "aAaA")) |
| 46 |
(test "string-every" #f (string-every (lambda (x) (char-ci=? x #\a)) "aAbA")) |
| 47 |
(test "string-every" (char->integer #\A) |
| 48 |
(string-every (lambda (x) (char->integer x)) "aAbA")) |
| 49 |
(test "string-every" #t |
| 50 |
(string-every (lambda (x) (error "hoge")) "")) |
| 51 |
(test "string-any" #t (string-any char-is-a? "aaaa")) |
| 52 |
(test "string-any" #f (string-any char-is-a? "Abcd")) |
| 53 |
(test "string-any" #f (string-any #\a "")) |
| 54 |
(test "string-any" #t (string-any char-lower-case? "ABcD")) |
| 55 |
(test "string-any" #f (string-any char-lower-case? "ABCD")) |
| 56 |
(test "string-any" #f (string-any char-lower-case? "")) |
| 57 |
(test "string-any" #t (string-any (lambda (x) (char-ci=? x #\a)) "CAaA")) |
| 58 |
(test "string-any" #f (string-any (lambda (x) (char-ci=? x #\a)) "ZBRC")) |
| 59 |
(test "string-any" #f (string-any (lambda (x) (char-ci=? x #\a)) "")) |
| 60 |
(test "string-any" (char->integer #\a) |
| 61 |
(string-any (lambda (x) (char->integer x)) "aAbA")) |
| 62 |
) |
| 63 |
(test-group "srfi-152:gauche:constructors" |
| 64 |
(test "string-tabulate" "0123456789" |
| 65 |
(string-tabulate (lambda (code) |
| 66 |
(integer->char (+ code (char->integer #\0)))) |
| 67 |
10)) |
| 68 |
(test "string-tabulate" "" |
| 69 |
(string-tabulate (lambda (code) |
| 70 |
(integer->char (+ code (char->integer #\0)))) |
| 71 |
0)) |
| 72 |
(test "reverse-list->string" "cBa" |
| 73 |
(reverse-list->string '(#\a #\B #\c))) |
| 74 |
(test "reverse-list->string" "" |
| 75 |
(reverse-list->string '())) |
| 76 |
(test "string-join" "foo+bar+baz" |
| 77 |
(string-join '("foo" "bar" "baz") "+")) |
| 78 |
(test "string-join" "foo bar baz" |
| 79 |
(string-join '("foo" "bar" "baz"))) |
| 80 |
(test "string-join" "/foo/bar/baz" |
| 81 |
(string-join '("foo" "bar" "baz") "/" 'prefix)) |
| 82 |
(test "string-join" "foo;bar;baz;" |
| 83 |
(string-join '("foo" "bar" "baz") ";" 'suffix)) |
| 84 |
) |
| 85 |
(test-group "srfi-152:gauche:selectors" |
| 86 |
(test "substring" "cde" (substring "abcde" 2 5)) |
| 87 |
(test "substring" "cd" (substring "abcde" 2 4)) |
| 88 |
(test "string-copy!" "abCDEfg" |
| 89 |
(let ((x (string-copy "abcdefg"))) |
| 90 |
(string-copy! x 2 "CDE") |
| 91 |
x)) |
| 92 |
(test "string-copy!" "abCDEfg" |
| 93 |
(let ((x (string-copy "abcdefg"))) |
| 94 |
(string-copy! x 2 "ZABCDE" 3) |
| 95 |
x)) |
| 96 |
(test "string-copy!" "abCDEfg" |
| 97 |
(let ((x (string-copy "abcdefg"))) |
| 98 |
(string-copy! x 2 "ZABCDEFG" 3 6) |
| 99 |
x)) |
| 100 |
(test "string-take" "Pete S" (string-take "Pete Szilagyi" 6)) |
| 101 |
(test "string-take" "" (string-take "Pete Szilagyi" 0)) |
| 102 |
(test "string-take" "Pete Szilagyi" (string-take "Pete Szilagyi" 13)) |
| 103 |
(test "string-drop" "zilagyi" (string-drop "Pete Szilagyi" 6)) |
| 104 |
(test "string-drop" "Pete Szilagyi" (string-drop "Pete Szilagyi" 0)) |
| 105 |
(test "string-drop" "" (string-drop "Pete Szilagyi" 13)) |
| 106 |
|
| 107 |
(test "string-take-right" "rules" (string-take-right "Beta rules" 5)) |
| 108 |
(test "string-take-right" "" (string-take-right "Beta rules" 0)) |
| 109 |
(test "string-take-right" "Beta rules" (string-take-right "Beta rules" 10)) |
| 110 |
(test "string-drop-right" "Beta " (string-drop-right "Beta rules" 5)) |
| 111 |
(test "string-drop-right" "Beta rules" (string-drop-right "Beta rules" 0)) |
| 112 |
(test "string-drop-right" "" (string-drop-right "Beta rules" 10)) |
| 113 |
|
| 114 |
(test "string-pad" " 325" (string-pad "325" 5)) |
| 115 |
(test "string-pad" "71325" (string-pad "71325" 5)) |
| 116 |
(test "string-pad" "71325" (string-pad "8871325" 5)) |
| 117 |
(test "string-pad" "~~325" (string-pad "325" 5 #\~)) |
| 118 |
(test "string-pad" "~~~25" (string-pad "325" 5 #\~ 1)) |
| 119 |
(test "string-pad" "~~~~2" (string-pad "325" 5 #\~ 1 2)) |
| 120 |
(test "string-pad-right" "325 " (string-pad-right "325" 5)) |
| 121 |
(test "string-pad-right" "71325" (string-pad-right "71325" 5)) |
| 122 |
(test "string-pad-right" "88713" (string-pad-right "8871325" 5)) |
| 123 |
(test "string-pad-right" "325~~" (string-pad-right "325" 5 #\~)) |
| 124 |
(test "string-pad-right" "25~~~" (string-pad-right "325" 5 #\~ 1)) |
| 125 |
(test "string-pad-right" "2~~~~" (string-pad-right "325" 5 #\~ 1 2)) |
| 126 |
|
| 127 |
(test "string-trim" "a b c d \n" |
| 128 |
(string-trim " \t a b c d \n")) |
| 129 |
(test "string-trim" "\t a b c d \n" |
| 130 |
(string-trim " \t a b c d \n" char-is-space?)) |
| 131 |
(test "string-trim" "a b c d \n" |
| 132 |
(string-trim "4358948a b c d \n" char-numeric?)) |
| 133 |
|
| 134 |
(test "string-trim-right" " \t a b c d" |
| 135 |
(string-trim-right " \t a b c d \n")) |
| 136 |
(test "string-trim-right" " \t a b c d " |
| 137 |
(string-trim-right " \t a b c d \n" char-newline?)) |
| 138 |
(test "string-trim-right" "349853a b c d" |
| 139 |
(string-trim-right "349853a b c d03490" char-numeric?)) |
| 140 |
|
| 141 |
(test "string-trim-both" "a b c d" |
| 142 |
(string-trim-both " \t a b c d \n")) |
| 143 |
(test "string-trim-both" " \t a b c d " |
| 144 |
(string-trim-both " \t a b c d \n" char-newline?)) |
| 145 |
(test "string-trim-both" "a b c d" |
| 146 |
(string-trim-both "349853a b c d03490" char-numeric?)) |
| 147 |
|
| 148 |
) |
| 149 |
(test-group "srfi-152:gauche:replacement" |
| 150 |
(test "string-replace" "-ab01234cdefghi" |
| 151 |
(string-replace "-abcdefghi" "01234" 3 3)) |
| 152 |
(test "string-replace" "-ab012cdefghi" |
| 153 |
(string-replace "-abcdefghi" "01234" 3 3 0 3)) |
| 154 |
(test "string-replace" "-ab01234fghi" |
| 155 |
(string-replace "-abcdefghi" "01234" 3 6)) |
| 156 |
(test "string-replace" "-ab34fghi" |
| 157 |
(string-replace "-abcdefghi" "01234" 3 6 3 5)) |
| 158 |
(test "string-replace" "abcdXYZghi" |
| 159 |
(string-replace "abcdefghi" "XYZ" 4 6)) |
| 160 |
(test "string-replace" "abcdZghi" |
| 161 |
(string-replace "abcdefghi" "XYZ" 4 6 2)) |
| 162 |
(test "string-replace" "abcdZefghi" |
| 163 |
(string-replace "abcdefghi" "XYZ" 4 4 2)) |
| 164 |
(test "string-replace" "abcdefghi" |
| 165 |
(string-replace "abcdefghi" "XYZ" 4 4 1 1)) |
| 166 |
(test "string-replace" "abcdhi" |
| 167 |
(string-replace "abcdefghi" "" 4 7)) |
| 168 |
|
| 169 |
|
| 170 |
) |
| 171 |
|
| 172 |
;; NB: This isn't in srfi document |
| 173 |
'(test-group "srfi-152:extended-comparisons" |
| 174 |
(test "base cases for extended string comparisons" |
| 175 |
'(#t #t #t #t #t #t #t #t #t #t) |
| 176 |
(map (lambda (f) (and (f) (f "foo"))) |
| 177 |
(list string=? string<? string>? string<=? string>=? |
| 178 |
string-ci=? string-ci<? string-ci>? string-ci<=? string-ci>=?)))) |
| 179 |
|
| 180 |
(test-group "srfi-152:gauche:comparison" |
| 181 |
(test "string=?" #t (string=? "foo" "foo")) |
| 182 |
|
| 183 |
|
| 184 |
(test "string<=?" #t (string<=? "fol" "foo")) |
| 185 |
|
| 186 |
(test "string<?" #t (string<? "fol" "foo")) |
| 187 |
|
| 188 |
(test "string>=?" #t (string>=? "foo" "fol")) |
| 189 |
|
| 190 |
(test "string>?" #t (string>? "foo" "fol")) |
| 191 |
|
| 192 |
(test "string-ci=?" #t (string-ci=? "Foo" "foO")) |
| 193 |
|
| 194 |
|
| 195 |
(test "string-ci<=?" #t (string-ci<=? "FOL" "foo")) |
| 196 |
|
| 197 |
(test "string-ci<?" #t (string-ci<? "fol" "FOO")) |
| 198 |
|
| 199 |
(test "string-ci>=?" #t (string-ci>=? "FOO" "fol")) |
| 200 |
|
| 201 |
(test "string-ci>?" #t (string-ci>? "FOO" "fol")) |
| 202 |
|
| 203 |
(test "string=?" #t (string=? "abcd" (string-append "a" "b" "c" "d"))) |
| 204 |
|
| 205 |
) |
| 206 |
|
| 207 |
(test-group "srfi-152:gauche:presuffixes" |
| 208 |
|
| 209 |
(test "string-prefix-length" 5 |
| 210 |
(string-prefix-length "cancaNCAM" "cancancan")) |
| 211 |
(test "string-suffix-length" 2 |
| 212 |
(string-suffix-length "CanCan" "cankancan")) |
| 213 |
|
| 214 |
(test "string-prefix?" #t (string-prefix? "abcd" "abcdefg")) |
| 215 |
(test "string-prefix?" #f (string-prefix? "abcf" "abcdefg")) |
| 216 |
(test "string-suffix?" #t (string-suffix? "defg" "abcdefg")) |
| 217 |
(test "string-suffix?" #f (string-suffix? "aefg" "abcdefg")) |
| 218 |
) |
| 219 |
(test-group "srfi-152:gauche:searching" |
| 220 |
|
| 221 |
(test "string-index #1" 4 |
| 222 |
(string-index "abcd:efgh:ijkl" char-is-colon?)) |
| 223 |
(test "string-index #2" 4 |
| 224 |
(string-index "abcd:efgh;ijkl" (complement char-alphabetic?))) |
| 225 |
(test "string-index #3" #f |
| 226 |
(string-index "abcd:efgh;ijkl" char-numeric?)) |
| 227 |
(test "string-index #4" 9 |
| 228 |
(string-index "abcd:efgh:ijkl" char-is-colon? 5)) |
| 229 |
(test "string-index-right #1" 4 |
| 230 |
(string-index-right "abcd:efgh;ijkl" char-is-colon?)) |
| 231 |
(test "string-index-right #2" 9 |
| 232 |
(string-index-right "abcd:efgh;ijkl" (complement char-alphabetic?))) |
| 233 |
(test "string-index-right #3" #f |
| 234 |
(string-index-right "abcd:efgh;ijkl" char-numeric?)) |
| 235 |
(test "string-index-right #4" 4 |
| 236 |
(string-index-right "abcd:efgh;ijkl" (complement char-alphabetic?) 2 5)) |
| 237 |
(test "string-contains" 3 |
| 238 |
(string-contains "Ma mere l'oye" "mer")) |
| 239 |
(test "string-contains" #f |
| 240 |
(string-contains "Ma mere l'oye" "Mer")) |
| 241 |
) |
| 242 |
(test-group "srfi-152:gauche:append" |
| 243 |
(test "string-append" #f |
| 244 |
(let ((s "test")) (eq? s (string-append s)))) |
| 245 |
(test "string-concatenate" #f |
| 246 |
(let ((s "test")) (eq? s (string-concatenate (list s))))) |
| 247 |
(test "string-concatenate" "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
| 248 |
(string-concatenate |
| 249 |
'("A" "B" "C" "D" "E" "F" "G" "H" |
| 250 |
"I" "J" "K" "L" "M" "N" "O" "P" |
| 251 |
"Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" |
| 252 |
"a" "b" "c" "d" "e" "f" "g" "h" |
| 253 |
"i" "j" "k" "l" "m" "n" "o" "p" |
| 254 |
"q" "r" "s" "t" "u" "v" "w" "x" "y" "z"))) |
| 255 |
(test "string-concatenate-reverse" "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA" |
| 256 |
(string-concatenate-reverse |
| 257 |
'("A" "B" "C" "D" "E" "F" "G" "H" |
| 258 |
"I" "J" "K" "L" "M" "N" "O" "P" |
| 259 |
"Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" |
| 260 |
"a" "b" "c" "d" "e" "f" "g" "h" |
| 261 |
"i" "j" "k" "l" "m" "n" "o" "p" |
| 262 |
"q" "r" "s" "t" "u" "v" "w" "x" "y" "z"))) |
| 263 |
(test "string-concatenate-reverse" #f |
| 264 |
(let ((s "test")) |
| 265 |
(eq? s (string-concatenate-reverse (list s))))) |
| 266 |
) |
| 267 |
(test-group "srfi-152:gauche:foldmap" |
| 268 |
(test "string-map" "svool" |
| 269 |
(string-map (lambda (c) |
| 270 |
(integer->char (- 219 (char->integer c)))) |
| 271 |
"hello")) |
| 272 |
|
| 273 |
(test "string-fold" '(#\o #\l #\l #\e #\h . #t) |
| 274 |
(string-fold cons #t "hello")) |
| 275 |
(test "string-fold" '(#\l #\e . #t) |
| 276 |
(string-fold cons #t "hello" 1 3)) |
| 277 |
(test "string-fold-right" '(#\h #\e #\l #\l #\o . #t) |
| 278 |
(string-fold-right cons #t "hello")) |
| 279 |
(test "string-fold-right" '(#\e #\l . #t) |
| 280 |
(string-fold-right cons #t "hello" 1 3)) |
| 281 |
|
| 282 |
(test "string-unfold" "hello" |
| 283 |
(string-unfold null? car cdr '(#\h #\e #\l #\l #\o))) |
| 284 |
(test "string-unfold" "hi hello" |
| 285 |
(string-unfold null? car cdr '(#\h #\e #\l #\l #\o) "hi ")) |
| 286 |
(test "string-unfold" "hi hello ho" |
| 287 |
(string-unfold null? car cdr |
| 288 |
'(#\h #\e #\l #\l #\o) "hi " |
| 289 |
(lambda (x) " ho"))) |
| 290 |
|
| 291 |
(test "string-unfold-right" "olleh" |
| 292 |
(string-unfold-right null? car cdr '(#\h #\e #\l #\l #\o))) |
| 293 |
(test "string-unfold-right" "olleh hi" |
| 294 |
(string-unfold-right null? car cdr '(#\h #\e #\l #\l #\o) " hi")) |
| 295 |
(test "string-unfold-right" "ho olleh hi" |
| 296 |
(string-unfold-right null? car cdr |
| 297 |
'(#\h #\e #\l #\l #\o) " hi" |
| 298 |
(lambda (x) "ho "))) |
| 299 |
|
| 300 |
(test "string-for-each" "CLtL" |
| 301 |
(let ((out (open-output-string)) |
| 302 |
(prev #f)) |
| 303 |
(string-for-each (lambda (c) |
| 304 |
(if (or (not prev) |
| 305 |
(char-whitespace? prev)) |
| 306 |
(write-char c out)) |
| 307 |
(set! prev c)) |
| 308 |
"Common Lisp, the Language") |
| 309 |
|
| 310 |
(get-output-string out))) |
| 311 |
|
| 312 |
#;(test "string-for-each-index" '(4 3 2 1 0) |
| 313 |
(let ((r '())) |
| 314 |
(string-for-each-index (lambda (i) (set! r (cons i r))) "hello") |
| 315 |
r)) |
| 316 |
#;(test "string-for-each-index" '(4 3 2 1) |
| 317 |
(let ((r '())) |
| 318 |
(string-for-each-index (lambda (i) (set! r (cons i r))) "hello" 1) |
| 319 |
r)) |
| 320 |
#;(test "string-for-each-index" '(2 1) |
| 321 |
(let ((r '())) |
| 322 |
(string-for-each-index (lambda (i) (set! r (cons i r))) "hello" 1 3) |
| 323 |
r)) |
| 324 |
(test "string-count #1" 2 |
| 325 |
(string-count "abc def\tghi jkl" char-is-space?)) |
| 326 |
(test "string-count #2" 3 |
| 327 |
(string-count "abc def\tghi jkl" char-whitespace?)) |
| 328 |
(test "string-count #3" 2 |
| 329 |
(string-count "abc def\tghi jkl" char-whitespace? 4)) |
| 330 |
(test "string-count #4" 1 |
| 331 |
(string-count "abc def\tghi jkl" char-whitespace? 4 9)) |
| 332 |
|
| 333 |
(test "string-filter" "rrrr" |
| 334 |
(string-filter char-is-r? "Help make programs run, run, RUN!")) |
| 335 |
(test "string-filter" "HelpmakeprogramsrunrunRUN" |
| 336 |
(string-filter char-alphabetic? "Help make programs run, run, RUN!")) |
| 337 |
|
| 338 |
(test "string-filter" "programsrunrun" |
| 339 |
(string-filter (lambda (c) (char-lower-case? c)) |
| 340 |
"Help make programs run, run, RUN!" |
| 341 |
10)) |
| 342 |
(test "string-filter" "" |
| 343 |
(string-filter (lambda (c) (char-lower-case? c)) "")) |
| 344 |
(test "string-remove" "Help make pogams un, un, RUN!" |
| 345 |
(string-remove char-is-r? "Help make programs run, run, RUN!")) |
| 346 |
(test "string-remove" " , , !" |
| 347 |
(string-remove char-alphabetic? "Help make programs run, run, RUN!")) |
| 348 |
(test "string-remove" " , , RUN!" |
| 349 |
(string-remove (lambda (c) (char-lower-case? c)) |
| 350 |
"Help make programs run, run, RUN!" |
| 351 |
10)) |
| 352 |
(test "string-remove" "" |
| 353 |
(string-remove (lambda (c) (char-lower-case? c)) "")) |
| 354 |
|
| 355 |
) |
| 356 |
(test-group "srfi-152:gauche:replisplit" |
| 357 |
|
| 358 |
(test "string-replicate" "cdefab" |
| 359 |
(string-replicate "abcdef" 2 8)) |
| 360 |
(test "string-replicate" "efabcd" |
| 361 |
(string-replicate "abcdef" -2 4)) |
| 362 |
(test "string-replicate" "abcabca" |
| 363 |
(string-replicate "abc" 0 7)) |
| 364 |
;; (test "string-replicate" "abcabca" |
| 365 |
;; (string-replicate "abc" |
| 366 |
;; 30000000000000000000000000000000 |
| 367 |
;; 30000000000000000000000000000007)) |
| 368 |
(test "string-replicate" "defdefd" |
| 369 |
(string-replicate "abcdefg" 0 7 3 6)) |
| 370 |
(test "string-replicate" "" |
| 371 |
(string-replicate "abcdefg" 9 9 3 6)) |
| 372 |
|
| 373 |
(test "string-segment" '("ab" "cd" "ef") |
| 374 |
(string-segment "abcdef" 2)) |
| 375 |
(test "string-segment" '("ab" "cd" "ef" "g") |
| 376 |
(string-segment "abcdefg" 2)) |
| 377 |
(test "string-segment" '() |
| 378 |
(string-segment "" 2)) |
| 379 |
(test "string-split" '("Help" "make" "programs" "run," "run," "RUN!") |
| 380 |
(string-split "Help make programs run, run, RUN!" " ")) |
| 381 |
(test "string-split" '("Help" "make" "programs run, run, RUN!") |
| 382 |
(string-split "Help make programs run, run, RUN!" " " 'infix 2)) |
| 383 |
(test "string-split" '("usr" "local" "bin") |
| 384 |
(string-split "/usr/local/bin" "/" 'prefix)) |
| 385 |
(test "string-split" '("be()" "here()" "now()") |
| 386 |
(string-split "be(); here(); now(); " "; " 'suffix)) |
| 387 |
|
| 388 |
) |
| 389 |
(test-group "srfi-152:gauche:regression" |
| 390 |
;;; Regression tests: check that reported bugs have been fixed |
| 391 |
|
| 392 |
; From: Matthias Radestock <[email protected]> |
| 393 |
; Date: Wed, 10 Dec 2003 21:05:22 +0100 |
| 394 |
; |
| 395 |
; Chris Double has found the following bug in the reference implementation: |
| 396 |
; |
| 397 |
; (string-contains "xabc" "ab") => 1 ;good |
| 398 |
; (string-contains "aabc" "ab") => #f ;bad |
| 399 |
; |
| 400 |
; Matthias. |
| 401 |
|
| 402 |
(test "string-contains" 1 (string-contains "aabc" "ab")) |
| 403 |
|
| 404 |
(test "string-contains" 5 (string-contains "ababdabdabxxas" "abdabx")) |
| 405 |
|
| 406 |
|
| 407 |
; (message continues) |
| 408 |
; |
| 409 |
; PS: There is also an off-by-one error in the bounds check of the |
| 410 |
; unoptimized version of string-contains that is included as commented out |
| 411 |
; code in the reference implementation. This breaks things like |
| 412 |
; (string-contains "xab" "ab") and (string-contains "ab" "ab"). |
| 413 |
|
| 414 |
; This off-by-one bug has been fixed in the comments of the version |
| 415 |
; of SRFI-13 shipped with Larceny. In a version of the code without |
| 416 |
; the fix the following test will catch the bug: |
| 417 |
|
| 418 |
(test "string-contains" 0 (string-contains "ab" "ab")) |
| 419 |
|
| 420 |
; From: [email protected] |
| 421 |
; Date: Wed, 26 Mar 2003 08:46:41 +0100 |
| 422 |
; |
| 423 |
; The SRFI document gives, |
| 424 |
; |
| 425 |
; string-filter s char/char-set/pred [start end] -> string |
| 426 |
; string-remove s char/char-set/pred [start end] -> string |
| 427 |
; |
| 428 |
; Yet the reference implementation switches the order giving, |
| 429 |
; |
| 430 |
; ;;; string-remove char/char-set/pred string [start end] |
| 431 |
; ;;; string-filter char/char-set/pred string [start end] |
| 432 |
; ... |
| 433 |
; (define (string-remove criterion s . maybe-start+end) |
| 434 |
; ...) |
| 435 |
; (define (string-filter criterion s . maybe-start+end) |
| 436 |
; ...) |
| 437 |
; |
| 438 |
; I reviewed the SRFI-13 mailing list and c.l.scheme, but found no mention of |
| 439 |
; this issue. Apologies if I've missed something. |
| 440 |
|
| 441 |
(test "ADR" (string-filter char-upper-case? "abrAcaDabRa")) |
| 442 |
|
| 443 |
(test "abrcaaba" (string-remove char-upper-case? "abrAcaDabRa")) |
| 444 |
)) |
| 445 |
(test-group "srfi-152:larceny" |
| 446 |
;;; Predicates |
| 447 |
(test-group "srfi-152:larceny:predicates" |
| 448 |
|
| 449 |
(test-assert (string-null? "")) |
| 450 |
(test-assert (not (string-null? "abc"))) |
| 451 |
(test #t (string-every (lambda (c) (if (char? c) c #f)) "")) |
| 452 |
(test #\c (string-every (lambda (c) (if (char? c) c #f)) "abc")) |
| 453 |
(test #f (string-every (lambda (c) (if (char>? c #\b) c #f)) "abc")) |
| 454 |
(test #\c (string-every (lambda (c) (if (char>? c #\b) c #f)) "abc" 2)) |
| 455 |
(test #t (string-every (lambda (c) (if (char>? c #\b) c #f)) "abc" 1 1)) |
| 456 |
(test #f (string-any (lambda (c) (if (char? c) c #f)) "")) |
| 457 |
(test #\a (string-any (lambda (c) (if (char? c) c #f)) "abc")) |
| 458 |
(test #\c (string-any (lambda (c) (if (char>? c #\b) c #f)) "abc")) |
| 459 |
(test #\c (string-any (lambda (c) (if (char>? c #\b) c #f)) "abc" 2)) |
| 460 |
(test #f (string-any (lambda (c) (if (char>? c #\b) c #f)) "abc" 0 2)) |
| 461 |
) |
| 462 |
;;; Constructors |
| 463 |
(test-group "srfi-152:larceny:constructors" |
| 464 |
(test "" |
| 465 |
(string-tabulate (lambda (i) |
| 466 |
(integer->char (+ i (char->integer #\a)))) |
| 467 |
0)) |
| 468 |
(test "abc" |
| 469 |
(string-tabulate (lambda (i) |
| 470 |
(integer->char (+ i (char->integer #\a)))) |
| 471 |
3)) |
| 472 |
(test "abc" |
| 473 |
(let ((p (open-input-string "abc"))) |
| 474 |
(string-unfold eof-object? |
| 475 |
values |
| 476 |
(lambda (x) (read-char p)) |
| 477 |
(read-char p)))) |
| 478 |
(test "" (string-unfold null? car cdr '())) |
| 479 |
(test "abc" (string-unfold null? car cdr (string->list "abc"))) |
| 480 |
(test "def" (string-unfold null? car cdr '() "def")) |
| 481 |
(test "defabcG" |
| 482 |
(string-unfold null? |
| 483 |
car |
| 484 |
cdr |
| 485 |
(string->list "abc") |
| 486 |
"def" |
| 487 |
(lambda (x) (and (null? x) "G")))) |
| 488 |
(test "" (string-unfold-right null? car cdr '())) |
| 489 |
(test "cba" (string-unfold-right null? car cdr (string->list "abc"))) |
| 490 |
(test "def" (string-unfold-right null? car cdr '() "def")) |
| 491 |
(test "Gcbadef" |
| 492 |
(string-unfold-right null? |
| 493 |
car |
| 494 |
cdr |
| 495 |
(string->list "abc") |
| 496 |
"def" |
| 497 |
(lambda (x) (and (null? x) "G")))) |
| 498 |
) |
| 499 |
;;; Conversion |
| 500 |
(test-group "srfi-152:larceny:conversion" |
| 501 |
(test '() (string->list "")) |
| 502 |
(test '() (string->list "" 0)) |
| 503 |
(test '() (string->list "" 0 0)) |
| 504 |
(test '(#\a #\b #\c) (string->list "abc")) |
| 505 |
(test '() (string->list "abc" 3)) |
| 506 |
(test '(#\b #\c) (string->list "abc" 1 3)) |
| 507 |
(test '(#\b #\c) |
| 508 |
(string->list "abc" |
| 509 |
(dummy-index "abc" 1) |
| 510 |
(dummy-index "abc" 3))) |
| 511 |
(test '#() (string->vector "")) |
| 512 |
(test '#() (string->vector "" 0)) |
| 513 |
(test '#() (string->vector "" 0 0)) |
| 514 |
(test '#(#\a #\b #\c) (string->vector "abc")) |
| 515 |
(test '#() (string->vector "abc" 3)) |
| 516 |
(test '#(#\b #\c) (string->vector "abc" 1 3)) |
| 517 |
(test '#(#\b #\c) |
| 518 |
(string->vector "abc" |
| 519 |
(dummy-index "abc" 1) |
| 520 |
(dummy-index "abc" 3))) |
| 521 |
(test "" (reverse-list->string '())) |
| 522 |
(test "cba" (reverse-list->string '(#\a #\b #\c))) |
| 523 |
(test "" (string-join '())) |
| 524 |
(test " ab cd e f " |
| 525 |
(string-join '("" "ab" "cd" "" "e" "f" ""))) |
| 526 |
(test "" (string-join '() "")) |
| 527 |
(test "abcdef" |
| 528 |
(string-join '("" "ab" "cd" "" "e" "f" "") "")) |
| 529 |
(test "" (string-join '() "xyz")) |
| 530 |
(test "xyzabxyzcdxyzxyzexyzfxyz" |
| 531 |
(string-join '("" "ab" "cd" "" "e" "f" "") "xyz")) |
| 532 |
(test "" (string-join '() "" 'infix)) |
| 533 |
(test "abcdef" |
| 534 |
(string-join '("" "ab" "cd" "" "e" "f" "") "" 'infix)) |
| 535 |
(test "" (string-join '() "xyz" 'infix)) |
| 536 |
(test "xyzabxyzcdxyzxyzexyzfxyz" |
| 537 |
(string-join '("" "ab" "cd" "" "e" "f" "") "xyz" 'infix)) |
| 538 |
(test-error |
| 539 |
(string-join '() "" 'strict-infix)) |
| 540 |
(test "abcdef" |
| 541 |
(string-join '("" "ab" "cd" "" "e" "f" "") "" 'strict-infix)) |
| 542 |
(test-error |
| 543 |
(string-join '() "xyz" 'strict-infix)) |
| 544 |
(test "xyzabxyzcdxyzxyzexyzfxyz" |
| 545 |
(string-join '("" "ab" "cd" "" "e" "f" "") "xyz" 'strict-infix)) |
| 546 |
(test "" (string-join '() "" 'suffix)) |
| 547 |
(test "abcdef" |
| 548 |
(string-join '("" "ab" "cd" "" "e" "f" "") "" 'suffix)) |
| 549 |
(test "" (string-join '() "xyz" 'suffix)) |
| 550 |
(test "xyzabxyzcdxyzxyzexyzfxyzxyz" |
| 551 |
(string-join '("" "ab" "cd" "" "e" "f" "") "xyz" 'suffix)) |
| 552 |
(test "" (string-join '() "" 'prefix)) |
| 553 |
(test "abcdef" |
| 554 |
(string-join '("" "ab" "cd" "" "e" "f" "") "" 'prefix)) |
| 555 |
(test "" (string-join '() "xyz" 'prefix)) |
| 556 |
(test "xyzxyzabxyzcdxyzxyzexyzfxyz" |
| 557 |
(string-join '("" "ab" "cd" "" "e" "f" "") "xyz" 'prefix)) |
| 558 |
) |
| 559 |
;;; Selection |
| 560 |
(test-group "srfi-152:larceny:selection" |
| 561 |
(test #\a (string-ref "abc" 0)) |
| 562 |
(test #\c (string-ref "abc" 2)) |
| 563 |
(test #\a (string-ref "abc" (dummy-index "abc" 0))) |
| 564 |
(test #\c (string-ref "abc" (dummy-index "abc" 2))) |
| 565 |
(test "" (substring "" 0 0)) |
| 566 |
(test "" (substring "abc" 0 0)) |
| 567 |
(test "" (substring "abc" 3 3)) |
| 568 |
(test ABC (substring ABC 0 3)) |
| 569 |
(test ABC |
| 570 |
(substring ABC |
| 571 |
(dummy-index "abc" 0) |
| 572 |
(dummy-index "abc" 3))) |
| 573 |
(test "b" (substring "abc" 1 2)) |
| 574 |
(test "" (string-copy "")) |
| 575 |
(test "abc" (string-copy "abc")) |
| 576 |
(test "" (string-copy "abc" 3)) |
| 577 |
(test "c" (string-copy "abc" 2)) |
| 578 |
(test "abc" (string-copy "abc" 0)) |
| 579 |
(test "b" (string-copy "abc" 1 2)) |
| 580 |
(test "" (string-copy "" 0 0)) |
| 581 |
(test "" (string-copy "abc" 0 0)) |
| 582 |
(test "" (string-copy "abc" 3 3)) |
| 583 |
(test "abc" (string-copy "abc" 0 3)) |
| 584 |
(test "b" (string-copy "abc" 1 2)) |
| 585 |
(test (substring ABC 1 2) |
| 586 |
(string-copy ABC |
| 587 |
(dummy-index "abc" 1) |
| 588 |
(dummy-index "abc" 2))) |
| 589 |
(test "" (string-take "" 0)) |
| 590 |
(test "" (string-take "abcdef" 0)) |
| 591 |
(test "ab" (string-take "abcdef" 2)) |
| 592 |
(test "" (string-drop "" 0)) |
| 593 |
(test "abcdef" (string-drop "abcdef" 0)) |
| 594 |
(test "cdef" (string-drop "abcdef" 2)) |
| 595 |
(test "" (string-take-right "" 0)) |
| 596 |
(test "" (string-take-right "abcdef" 0)) |
| 597 |
(test "ef" (string-take-right "abcdef" 2)) |
| 598 |
(test "" (string-drop-right "" 0)) |
| 599 |
(test "abcdef" (string-drop-right "abcdef" 0)) |
| 600 |
(test "abcd" (string-drop-right "abcdef" 2)) |
| 601 |
(test "" (string-pad "" 0)) |
| 602 |
(test " " (string-pad "" 5)) |
| 603 |
(test " 325" (string-pad "325" 5)) |
| 604 |
(test "71325" (string-pad "71325" 5)) |
| 605 |
(test "71325" (string-pad "8871325" 5)) |
| 606 |
(test "" (string-pad "" 0 #\*)) |
| 607 |
(test "*****" (string-pad "" 5 #\*)) |
| 608 |
(test "**325" (string-pad "325" 5 #\*)) |
| 609 |
(test "71325" (string-pad "71325" 5 #\*)) |
| 610 |
(test "71325" (string-pad "8871325" 5 #\*)) |
| 611 |
(test "" (string-pad "" 0 #\* 0)) |
| 612 |
(test "*****" (string-pad "" 5 #\* 0)) |
| 613 |
(test "**325" (string-pad "325" 5 #\* 0)) |
| 614 |
(test "71325" (string-pad "71325" 5 #\* 0)) |
| 615 |
(test "71325" (string-pad "8871325" 5 #\* 0)) |
| 616 |
(test "***25" (string-pad "325" 5 #\* 1)) |
| 617 |
(test "*1325" (string-pad "71325" 5 #\* 1)) |
| 618 |
(test "71325" (string-pad "8871325" 5 #\* 1)) |
| 619 |
(test "" (string-pad "" 0 #\* 0 0)) |
| 620 |
(test "*****" (string-pad "" 5 #\* 0 0)) |
| 621 |
(test "**325" (string-pad "325" 5 #\* 0 3)) |
| 622 |
(test "**713" (string-pad "71325" 5 #\* 0 3)) |
| 623 |
(test "**887" (string-pad "8871325" 5 #\* 0 3)) |
| 624 |
(test "***25" (string-pad "325" 5 #\* 1 3)) |
| 625 |
(test "**132" (string-pad "71325" 5 #\* 1 4)) |
| 626 |
(test "*8713" (string-pad "8871325" 5 #\* 1 5)) |
| 627 |
(test "" (string-pad-right "" 0)) |
| 628 |
(test " " (string-pad-right "" 5)) |
| 629 |
(test "325 " (string-pad-right "325" 5)) |
| 630 |
(test "71325" (string-pad-right "71325" 5)) |
| 631 |
(test "88713" (string-pad-right "8871325" 5)) |
| 632 |
(test "" (string-pad-right "" 0 #\*)) |
| 633 |
(test "*****" (string-pad-right "" 5 #\*)) |
| 634 |
(test "325**" (string-pad-right "325" 5 #\*)) |
| 635 |
(test "71325" (string-pad-right "71325" 5 #\*)) |
| 636 |
(test "88713" (string-pad-right "8871325" 5 #\*)) |
| 637 |
(test "" (string-pad-right "" 0 #\* 0)) |
| 638 |
(test "*****" (string-pad-right "" 5 #\* 0)) |
| 639 |
(test "325**" (string-pad-right "325" 5 #\* 0)) |
| 640 |
(test "71325" (string-pad-right "71325" 5 #\* 0)) |
| 641 |
(test "88713" (string-pad-right "8871325" 5 #\* 0)) |
| 642 |
(test "25***" (string-pad-right "325" 5 #\* 1)) |
| 643 |
(test "1325*" (string-pad-right "71325" 5 #\* 1)) |
| 644 |
(test "87132" (string-pad-right "8871325" 5 #\* 1)) |
| 645 |
(test "" (string-pad-right "" 0 #\* 0 0)) |
| 646 |
(test "*****" (string-pad-right "" 5 #\* 0 0)) |
| 647 |
(test "325**" (string-pad-right "325" 5 #\* 0 3)) |
| 648 |
(test "713**" (string-pad-right "71325" 5 #\* 0 3)) |
| 649 |
(test "887**" (string-pad-right "8871325" 5 #\* 0 3)) |
| 650 |
(test "25***" (string-pad-right "325" 5 #\* 1 3)) |
| 651 |
(test "132**" (string-pad-right "71325" 5 #\* 1 4)) |
| 652 |
(test "8713*" (string-pad-right "8871325" 5 #\* 1 5)) |
| 653 |
(test "" (string-trim "")) |
| 654 |
(test "a b c " (string-trim " a b c ")) |
| 655 |
(test "" (string-trim "" char-whitespace?)) |
| 656 |
(test "a b c " (string-trim " a b c " char-whitespace?)) |
| 657 |
(test "" (string-trim " a b c " char?)) |
| 658 |
(test "" (string-trim "" char-whitespace? 0)) |
| 659 |
(test "a b c " (string-trim " a b c " char-whitespace? 0)) |
| 660 |
(test "" (string-trim " a b c " char? 0)) |
| 661 |
(test "b c " (string-trim " a b c " char-whitespace? 3)) |
| 662 |
(test "" (string-trim " a b c " char? 3)) |
| 663 |
(test "" (string-trim " a b c " char? 0 11)) |
| 664 |
(test "b c " (string-trim " a b c " char-whitespace? 3 11)) |
| 665 |
(test "" (string-trim " a b c " char? 3 11)) |
| 666 |
(test "" (string-trim " a b c " char? 0 8)) |
| 667 |
(test "b " (string-trim " a b c " char-whitespace? 3 8)) |
| 668 |
(test "" (string-trim " a b c " char? 3 8)) |
| 669 |
(test "" (string-trim-right "")) |
| 670 |
(test " a b c" (string-trim-right " a b c ")) |
| 671 |
(test "" (string-trim-right "" char-whitespace?)) |
| 672 |
(test " a b c" (string-trim-right " a b c " char-whitespace?)) |
| 673 |
(test "" (string-trim-right " a b c " char?)) |
| 674 |
(test "" (string-trim-right "" char-whitespace? 0)) |
| 675 |
(test " a b c" (string-trim-right " a b c " char-whitespace? 0)) |
| 676 |
(test "" (string-trim-right " a b c " char? 0)) |
| 677 |
(test " b c" (string-trim-right " a b c " char-whitespace? 3)) |
| 678 |
(test "" (string-trim-right " a b c " char? 3)) |
| 679 |
(test "" (string-trim-right " a b c " char? 0 11)) |
| 680 |
(test " b c" (string-trim-right " a b c " char-whitespace? 3 11)) |
| 681 |
(test "" (string-trim-right " a b c " char? 3 11)) |
| 682 |
(test "" (string-trim-right " a b c " char? 0 8)) |
| 683 |
(test " b" (string-trim-right " a b c " char-whitespace? 3 8)) |
| 684 |
(test "" (string-trim-right " a b c " char? 3 8)) |
| 685 |
(test "" (string-trim-both "")) |
| 686 |
(test "a b c" (string-trim-both " a b c ")) |
| 687 |
(test "" (string-trim-both "" char-whitespace?)) |
| 688 |
(test "a b c" (string-trim-both " a b c " char-whitespace?)) |
| 689 |
(test "" (string-trim-both " a b c " char?)) |
| 690 |
(test "" (string-trim-both "" char-whitespace? 0)) |
| 691 |
(test "a b c" (string-trim-both " a b c " char-whitespace? 0)) |
| 692 |
(test "" (string-trim-both " a b c " char? 0)) |
| 693 |
(test "b c" (string-trim-both " a b c " char-whitespace? 3)) |
| 694 |
(test "" (string-trim-both " a b c " char? 3)) |
| 695 |
(test "" (string-trim-both " a b c " char? 0 11)) |
| 696 |
(test "b c" (string-trim-both " a b c " char-whitespace? 3 11)) |
| 697 |
(test "" (string-trim-both " a b c " char? 3 11)) |
| 698 |
(test "" (string-trim-both " a b c " char? 0 8)) |
| 699 |
(test "b" (string-trim-both " a b c " char-whitespace? 3 8)) |
| 700 |
(test "" (string-trim-both " a b c " char? 3 8)) |
| 701 |
(test 0 (string-prefix-length "" "")) |
| 702 |
(test 0 (string-prefix-length "" "aabbccddee")) |
| 703 |
(test 0 (string-prefix-length "aisle" "")) |
| 704 |
(test 0 (string-prefix-length "" "aabbccddee")) |
| 705 |
(test 1 (string-prefix-length "aisle" "aabbccddee")) |
| 706 |
(test 0 (string-prefix-length "bail" "aabbccddee")) |
| 707 |
(test 4 (string-prefix-length "prefix" "preface")) |
| 708 |
(test 0 (string-prefix-length "" "" 0)) |
| 709 |
(test 0 (string-prefix-length "" "aabbccddee" 0)) |
| 710 |
(test 0 (string-prefix-length "aisle" "" 0)) |
| 711 |
(test 1 (string-prefix-length "aisle" "aabbccddee" 0)) |
| 712 |
(test 0 (string-prefix-length "bail" "aabbccddee" 0)) |
| 713 |
(test 4 (string-prefix-length "prefix" "preface" 0)) |
| 714 |
(test 0 (string-prefix-length "aisle" "" 1)) |
| 715 |
(test 0 (string-prefix-length "aisle" "aabbccddee" 1)) |
| 716 |
(test 1 (string-prefix-length "bail" "aabbccddee" 1)) |
| 717 |
(test 0 (string-prefix-length "prefix" "preface" 1)) |
| 718 |
(test 0 (string-prefix-length "" "" 0 0)) |
| 719 |
(test 0 (string-prefix-length "" "aabbccddee" 0 0)) |
| 720 |
(test 0 (string-prefix-length "aisle" "" 0 4)) |
| 721 |
(test 1 (string-prefix-length "aisle" "aabbccddee" 0 4)) |
| 722 |
(test 0 (string-prefix-length "bail" "aabbccddee" 0 1)) |
| 723 |
(test 0 (string-prefix-length "aisle" "" 1 4)) |
| 724 |
(test 0 (string-prefix-length "aisle" "aabbccddee" 1 4)) |
| 725 |
(test 1 (string-prefix-length "bail" "aabbccddee" 1 4)) |
| 726 |
(test 0 (string-prefix-length "prefix" "preface" 1 5)) |
| 727 |
(test 0 (string-prefix-length "" "" 0 0 0)) |
| 728 |
(test 0 (string-prefix-length "" "aabbccddee" 0 0 0)) |
| 729 |
(test 0 (string-prefix-length "aisle" "" 0 4 0)) |
| 730 |
(test 0 (string-prefix-length "aisle" "aabbccddee" 0 4 2)) |
| 731 |
(test 1 (string-prefix-length "bail" "aabbccddee" 0 1 2)) |
| 732 |
(test 0 (string-prefix-length "prefix" "preface" 0 5 1)) |
| 733 |
(test 0 (string-prefix-length "aisle" "" 1 4 0)) |
| 734 |
(test 0 (string-prefix-length "aisle" "aabbccddee" 1 4 3)) |
| 735 |
(test 0 (string-prefix-length "bail" "aabbccddee" 1 4 3)) |
| 736 |
(test 3 (string-prefix-length "prefix" "preface" 1 5 1)) |
| 737 |
(test 0 (string-prefix-length "" "" 0 0 0 0)) |
| 738 |
(test 0 (string-prefix-length "" "aabbccddee" 0 0 0 0)) |
| 739 |
(test 0 (string-prefix-length "aisle" "" 0 4 0 0)) |
| 740 |
(test 0 (string-prefix-length "aisle" "aabbccddee" 0 4 2 10)) |
| 741 |
(test 1 (string-prefix-length "bail" "aabbccddee" 0 1 2 10)) |
| 742 |
(test 0 (string-prefix-length "prefix" "preface" 0 5 1 6)) |
| 743 |
(test 0 (string-prefix-length "aisle" "" 1 4 0 0)) |
| 744 |
(test 0 (string-prefix-length "aisle" "aabbccddee" 1 4 3 3)) |
| 745 |
(test 0 (string-prefix-length "bail" "aabbccddee" 1 4 3 6)) |
| 746 |
(test 3 (string-prefix-length "prefix" "preface" 1 5 1 7)) |
| 747 |
(test 0 (string-suffix-length "" "")) |
| 748 |
(test 0 (string-suffix-length "" "aabbccddee")) |
| 749 |
(test 0 (string-suffix-length "aisle" "")) |
| 750 |
(test 0 (string-suffix-length "" "aabbccddee")) |
| 751 |
(test 1 (string-suffix-length "aisle" "aabbccddee")) |
| 752 |
(test 0 (string-suffix-length "bail" "aabbccddee")) |
| 753 |
(test 3 (string-suffix-length "place" "preface")) |
| 754 |
(test 0 (string-suffix-length "" "" 0)) |
| 755 |
(test 0 (string-suffix-length "" "aabbccddee" 0)) |
| 756 |
(test 0 (string-suffix-length "aisle" "" 0)) |
| 757 |
(test 1 (string-suffix-length "aisle" "aabbccddee" 0)) |
| 758 |
(test 0 (string-suffix-length "bail" "aabbccddee" 0)) |
| 759 |
(test 3 (string-suffix-length "place" "preface" 0)) |
| 760 |
(test 0 (string-suffix-length "aisle" "" 1)) |
| 761 |
(test 1 (string-suffix-length "aisle" "aabbccddee" 1)) |
| 762 |
(test 0 (string-suffix-length "bail" "aabbccddee" 1)) |
| 763 |
(test 3 (string-suffix-length "place" "preface" 1)) |
| 764 |
(test 0 (string-suffix-length "" "" 0 0)) |
| 765 |
(test 0 (string-suffix-length "" "aabbccddee" 0 0)) |
| 766 |
(test 0 (string-suffix-length "aisle" "" 0 4)) |
| 767 |
(test 0 (string-suffix-length "aisle" "aabbccddee" 0 4)) |
| 768 |
(test 0 (string-suffix-length "bail" "aabbccddee" 0 1)) |
| 769 |
(test 0 (string-suffix-length "aisle" "" 1 4)) |
| 770 |
(test 0 (string-suffix-length "aisle" "aabbccddee" 1 4)) |
| 771 |
(test 1 (string-suffix-length "aisle" "aabbccddee" 1 5)) |
| 772 |
(test 0 (string-suffix-length "bail" "aabbccddee" 1 4)) |
| 773 |
(test 3 (string-suffix-length "place" "preface" 1 5)) |
| 774 |
(test 0 (string-suffix-length "" "" 0 0 0)) |
| 775 |
(test 0 (string-suffix-length "" "aabbccddee" 0 0 0)) |
| 776 |
(test 0 (string-suffix-length "aisle" "" 0 4 0)) |
| 777 |
(test 0 (string-suffix-length "aisle" "aabbccddee" 0 4 2)) |
| 778 |
(test 0 (string-suffix-length "bail" "aabbccddee" 0 1 2)) |
| 779 |
(test 3 (string-suffix-length "place" "preface" 0 5 1)) |
| 780 |
(test 0 (string-suffix-length "aisle" "" 1 4 0)) |
| 781 |
(test 0 (string-suffix-length "aisle" "aabbccddee" 1 4 3)) |
| 782 |
(test 0 (string-suffix-length "bail" "aabbccddee" 1 4 3)) |
| 783 |
(test 3 (string-suffix-length "place" "preface" 1 5 1)) |
| 784 |
(test 0 (string-suffix-length "" "" 0 0 0 0)) |
| 785 |
(test 0 (string-suffix-length "" "aabbccddee" 0 0 0 0)) |
| 786 |
(test 0 (string-suffix-length "aisle" "" 0 4 0 0)) |
| 787 |
(test 1 (string-suffix-length "aisle" "aabbccddee" 0 5 2 10)) |
| 788 |
(test 1 (string-suffix-length "bail" "aabbccddee" 0 1 2 4)) |
| 789 |
(test 0 (string-suffix-length "place" "preface" 0 5 1 6)) |
| 790 |
(test 2 (string-suffix-length "place" "preface" 0 4 1 6)) |
| 791 |
(test 0 (string-suffix-length "aisle" "" 1 4 0 0)) |
| 792 |
(test 0 (string-suffix-length "aisle" "aabbccddee" 1 4 3 3)) |
| 793 |
(test 0 (string-suffix-length "bail" "aabbccddee" 1 4 3 6)) |
| 794 |
(test 3 (string-suffix-length "place" "preface" 1 5 1 7)) |
| 795 |
(test #t (string-prefix? "" "")) |
| 796 |
(test #t (string-prefix? "" "abc")) |
| 797 |
(test #t (string-prefix? "a" "abc")) |
| 798 |
(test #f (string-prefix? "c" "abc")) |
| 799 |
(test #t (string-prefix? "ab" "abc")) |
| 800 |
(test #f (string-prefix? "ac" "abc")) |
| 801 |
(test #t (string-prefix? "abc" "abc")) |
| 802 |
(test #t (string-suffix? "" "")) |
| 803 |
(test #t (string-suffix? "" "abc")) |
| 804 |
(test #f (string-suffix? "a" "abc")) |
| 805 |
(test #t (string-suffix? "c" "abc")) |
| 806 |
(test #f (string-suffix? "ac" "abc")) |
| 807 |
(test #t (string-suffix? "bc" "abc")) |
| 808 |
(test #t (string-suffix? "abc" "abc")) |
| 809 |
(test #t (string-prefix? "" "" 0)) |
| 810 |
(test #t (string-prefix? "" "abc" 0)) |
| 811 |
(test #t (string-prefix? "a" "abc" 0)) |
| 812 |
(test #f (string-prefix? "c" "abc" 0)) |
| 813 |
(test #t (string-prefix? "ab" "abc" 0)) |
| 814 |
(test #f (string-prefix? "ac" "abc" 0)) |
| 815 |
(test #t (string-prefix? "abc" "abc" 0)) |
| 816 |
(test #t (string-suffix? "" "" 0)) |
| 817 |
(test #t (string-suffix? "" "abc" 0)) |
| 818 |
(test #f (string-suffix? "a" "abc" 0)) |
| 819 |
(test #t (string-suffix? "c" "abc" 0)) |
| 820 |
(test #f (string-suffix? "ac" "abc" 0)) |
| 821 |
(test #t (string-suffix? "bc" "abc" 0)) |
| 822 |
(test #t (string-suffix? "abc" "abc" 0)) |
| 823 |
(test #t (string-prefix? "ab" "abc" 2)) |
| 824 |
(test #t (string-prefix? "ac" "abc" 2)) |
| 825 |
(test #f (string-prefix? "abc" "abc" 2)) |
| 826 |
(test #t (string-suffix? "ac" "abc" 2)) |
| 827 |
(test #t (string-suffix? "bc" "abc" 2)) |
| 828 |
(test #t (string-suffix? "abc" "abc" 2)) |
| 829 |
(test #t (string-prefix? "" "" 0 0)) |
| 830 |
(test #t (string-prefix? "" "abc" 0 0)) |
| 831 |
(test #t (string-prefix? "a" "abc" 0 0)) |
| 832 |
(test #f (string-prefix? "c" "abc" 0 1)) |
| 833 |
(test #t (string-prefix? "ab" "abc" 0 1)) |
| 834 |
(test #t (string-prefix? "ab" "abc" 0 2)) |
| 835 |
(test #f (string-prefix? "ac" "abc" 0 2)) |
| 836 |
(test #t (string-prefix? "abc" "abc" 0 3)) |
| 837 |
(test #t (string-suffix? "" "" 0 0)) |
| 838 |
(test #t (string-suffix? "" "abc" 0 0)) |
| 839 |
(test #f (string-suffix? "a" "abc" 0 1)) |
| 840 |
(test #t (string-suffix? "c" "abc" 0 1)) |
| 841 |
(test #t (string-suffix? "ac" "abc" 1 2)) |
| 842 |
(test #f (string-suffix? "ac" "abc" 0 2)) |
| 843 |
(test #t (string-suffix? "bc" "abc" 0 2)) |
| 844 |
(test #t (string-suffix? "abc" "abc" 0 3)) |
| 845 |
(test #t (string-prefix? "ab" "abc" 2 2)) |
| 846 |
(test #t (string-prefix? "ac" "abc" 2 2)) |
| 847 |
(test #f (string-prefix? "abc" "abc" 2 3)) |
| 848 |
(test #t (string-suffix? "ac" "abc" 2 2)) |
| 849 |
(test #t (string-suffix? "bc" "abc" 2 2)) |
| 850 |
(test #t (string-suffix? "abc" "abc" 2 3)) |
| 851 |
(test #t (string-prefix? "" "" 0 0 0)) |
| 852 |
(test #t (string-prefix? "" "abc" 0 0 0)) |
| 853 |
(test #t (string-prefix? "a" "abc" 0 0 0)) |
| 854 |
(test #f (string-prefix? "c" "abc" 0 1 0)) |
| 855 |
(test #t (string-prefix? "ab" "abc" 0 1 0)) |
| 856 |
(test #t (string-prefix? "ab" "abc" 0 2 0)) |
| 857 |
(test #f (string-prefix? "ac" "abc" 0 2 0)) |
| 858 |
(test #t (string-prefix? "abc" "abc" 0 3 0)) |
| 859 |
(test #t (string-suffix? "" "" 0 0 0)) |
| 860 |
(test #t (string-suffix? "" "abc" 0 0 0)) |
| 861 |
(test #f (string-suffix? "a" "abc" 0 1 0)) |
| 862 |
(test #t (string-suffix? "c" "abc" 0 1 0)) |
| 863 |
(test #t (string-suffix? "ac" "abc" 1 2 0)) |
| 864 |
(test #f (string-suffix? "ac" "abc" 0 2 0)) |
| 865 |
(test #t (string-suffix? "bc" "abc" 0 2 0)) |
| 866 |
(test #t (string-suffix? "abc" "abc" 0 3 0)) |
| 867 |
(test #t (string-prefix? "ab" "abc" 2 2 0)) |
| 868 |
(test #t (string-prefix? "ac" "abc" 2 2 0)) |
| 869 |
(test #f (string-prefix? "abc" "abc" 2 3 0)) |
| 870 |
(test #t (string-suffix? "ac" "abc" 2 2 0)) |
| 871 |
(test #t (string-suffix? "bc" "abc" 2 2 0)) |
| 872 |
(test #t (string-suffix? "abc" "abc" 2 3 0)) |
| 873 |
(test #t (string-prefix? "" "abc" 0 0 1)) |
| 874 |
(test #t (string-prefix? "a" "abc" 0 0 1)) |
| 875 |
(test #t (string-prefix? "c" "abc" 0 1 2)) |
| 876 |
(test #f (string-prefix? "ab" "abc" 0 1 2)) |
| 877 |
(test #f (string-prefix? "ab" "abc" 0 2 1)) |
| 878 |
(test #f (string-prefix? "ac" "abc" 0 2 1)) |
| 879 |
(test #f (string-prefix? "abc" "abc" 0 3 1)) |
| 880 |
(test #f (string-suffix? "a" "abc" 0 1 2)) |
| 881 |
(test #t (string-suffix? "c" "abc" 0 1 1)) |
| 882 |
(test #t (string-suffix? "ac" "abc" 1 2 2)) |
| 883 |
(test #t (string-suffix? "bc" "abc" 0 2 1)) |
| 884 |
(test #f (string-suffix? "bc" "abc" 0 2 2)) |
| 885 |
(test #t (string-prefix? "" "" 0 0 0 0)) |
| 886 |
(test #t (string-prefix? "" "abc" 0 0 0 3)) |
| 887 |
(test #t (string-prefix? "a" "abc" 0 0 0 3)) |
| 888 |
(test #f (string-prefix? "c" "abc" 0 1 0 3)) |
| 889 |
(test #t (string-prefix? "ab" "abc" 0 1 0 3)) |
| 890 |
(test #t (string-prefix? "ab" "abc" 0 2 0 3)) |
| 891 |
(test #f (string-prefix? "ac" "abc" 0 2 0 3)) |
| 892 |
(test #t (string-prefix? "abc" "abc" 0 3 0 3)) |
| 893 |
(test #t (string-suffix? "" "abc" 0 0 0 3)) |
| 894 |
(test #f (string-suffix? "a" "abc" 0 1 0 3)) |
| 895 |
(test #t (string-suffix? "c" "abc" 0 1 0 3)) |
| 896 |
(test #t (string-suffix? "ac" "abc" 1 2 0 3)) |
| 897 |
(test #f (string-suffix? "ac" "abc" 0 2 0 3)) |
| 898 |
(test #t (string-suffix? "bc" "abc" 0 2 0 3)) |
| 899 |
(test #t (string-suffix? "abc" "abc" 0 3 0 3)) |
| 900 |
(test #t (string-prefix? "ab" "abc" 2 2 0 3)) |
| 901 |
(test #t (string-prefix? "ac" "abc" 2 2 0 3)) |
| 902 |
(test #f (string-prefix? "abc" "abc" 2 3 0 3)) |
| 903 |
(test #t (string-suffix? "ac" "abc" 2 2 0 3)) |
| 904 |
(test #t (string-suffix? "bc" "abc" 2 2 0 3)) |
| 905 |
(test #t (string-suffix? "abc" "abc" 2 3 0 3)) |
| 906 |
(test #t (string-prefix? "" "abc" 0 0 1 3)) |
| 907 |
(test #t (string-prefix? "a" "abc" 0 0 1 3)) |
| 908 |
(test #t (string-prefix? "c" "abc" 0 1 2 3)) |
| 909 |
(test #f (string-prefix? "ab" "abc" 0 1 2 3)) |
| 910 |
(test #f (string-prefix? "ab" "abc" 0 2 1 3)) |
| 911 |
(test #f (string-prefix? "ac" "abc" 0 2 1 3)) |
| 912 |
(test #f (string-prefix? "abc" "abc" 0 3 1 3)) |
| 913 |
(test #f (string-suffix? "a" "abc" 0 1 2 3)) |
| 914 |
(test #t (string-suffix? "c" "abc" 0 1 1 3)) |
| 915 |
(test #t (string-suffix? "ac" "abc" 1 2 2 3)) |
| 916 |
(test #t (string-suffix? "bc" "abc" 0 2 1 3)) |
| 917 |
(test #f (string-suffix? "bc" "abc" 0 2 2 3)) |
| 918 |
(test #t (string-prefix? "" "abc" 0 0 0 2)) |
| 919 |
(test #t (string-prefix? "a" "abc" 0 0 0 2)) |
| 920 |
(test #f (string-prefix? "c" "abc" 0 1 0 2)) |
| 921 |
(test #t (string-prefix? "ab" "abc" 0 1 0 2)) |
| 922 |
(test #f (string-prefix? "abc" "abc" 0 3 0 2)) |
| 923 |
(test #t (string-suffix? "" "abc" 0 0 0 2)) |
| 924 |
(test #f (string-suffix? "c" "abc" 0 1 0 2)) |
| 925 |
(test #f (string-suffix? "ac" "abc" 1 2 0 2)) |
| 926 |
) |
| 927 |
;;; Searching |
| 928 |
(test-group "srfi-152:larceny:searching" |
| 929 |
(test #f |
| 930 |
(dummy-index "" |
| 931 |
(string-index "" char?))) |
| 932 |
(test 0 |
| 933 |
(dummy-index "abcdef" |
| 934 |
(string-index "abcdef" char?))) |
| 935 |
(test 4 |
| 936 |
(dummy-index "abcdef" |
| 937 |
(string-index "abcdef" |
| 938 |
(lambda (c) (char>? c #\d))))) |
| 939 |
(test #f |
| 940 |
(dummy-index "abcdef" |
| 941 |
(string-index "abcdef" char-whitespace?))) |
| 942 |
(test #f |
| 943 |
(dummy-index "abcdef" |
| 944 |
(string-index-right "" char?))) |
| 945 |
(test 5 |
| 946 |
(dummy-index "abcdef" |
| 947 |
(string-index-right "abcdef" char?))) |
| 948 |
(test 5 |
| 949 |
(dummy-index "abcdef" |
| 950 |
(string-index-right "abcdef" |
| 951 |
(lambda (c) (char>? c #\d))))) |
| 952 |
(test #f |
| 953 |
(dummy-index "abcdef" |
| 954 |
(string-index-right "abcdef" char-whitespace?))) |
| 955 |
(test #f |
| 956 |
(dummy-index "" (string-skip "" string?))) |
| 957 |
(test 0 |
| 958 |
(dummy-index "abcdef" |
| 959 |
(string-skip "abcdef" string?))) |
| 960 |
(test 4 |
| 961 |
(dummy-index "abcdef" |
| 962 |
(string-skip "abcdef" |
| 963 |
(lambda (c) (char<=? c #\d))))) |
| 964 |
(test #f |
| 965 |
(dummy-index "abcdef" |
| 966 |
(string-skip "abcdef" char?))) |
| 967 |
(test #f |
| 968 |
(dummy-index "" (string-skip-right "" string?))) |
| 969 |
(test 5 |
| 970 |
(dummy-index "abcdef" |
| 971 |
(string-skip-right "abcdef" string?))) |
| 972 |
(test 5 |
| 973 |
(dummy-index "abcdef" |
| 974 |
(string-skip-right "abcdef" |
| 975 |
(lambda (c) (char<=? c #\d))))) |
| 976 |
(test #f |
| 977 |
(dummy-index "abcdef" |
| 978 |
(string-skip-right "abcdef" char?))) |
| 979 |
(test 2 |
| 980 |
(dummy-index "abcdef" |
| 981 |
(string-index "abcdef" char? 2))) |
| 982 |
(test 4 |
| 983 |
(dummy-index "abcdef" |
| 984 |
(string-index "abcdef" |
| 985 |
(lambda (c) (char>? c #\d)) 2))) |
| 986 |
(test #f |
| 987 |
(dummy-index "abcdef" |
| 988 |
(string-index "abcdef" char-whitespace? 2))) |
| 989 |
(test 5 |
| 990 |
(dummy-index "abcdef" |
| 991 |
(string-index-right "abcdef" char? 2))) |
| 992 |
(test 5 |
| 993 |
(dummy-index "abcdef" |
| 994 |
(string-index-right "abcdef" |
| 995 |
(lambda (c) |
| 996 |
(char>? c #\d)) 2))) |
| 997 |
(test #f |
| 998 |
(dummy-index "abcdef" |
| 999 |
(string-index-right "abcdef" char-whitespace? 2))) |
| 1000 |
(test 2 |
| 1001 |
(dummy-index "abcdef" |
| 1002 |
(string-skip "abcdef" string? 2))) |
| 1003 |
(test 4 |
| 1004 |
(dummy-index "abcdef" |
| 1005 |
(string-skip "abcdef" |
| 1006 |
(lambda (c) |
| 1007 |
(char<=? c #\d)) 2))) |
| 1008 |
(test #f |
| 1009 |
(dummy-index "abcdef" |
| 1010 |
(string-skip "abcdef" char? 2))) |
| 1011 |
(test 5 |
| 1012 |
(dummy-index "abcdef" |
| 1013 |
(string-skip-right "abcdef" string? 2))) |
| 1014 |
(test 5 |
| 1015 |
(dummy-index "abcdef" |
| 1016 |
(string-skip-right "abcdef" |
| 1017 |
(lambda (c) |
| 1018 |
(char<=? c #\d)) 2))) |
| 1019 |
(test #f |
| 1020 |
(dummy-index "abcdef" |
| 1021 |
(string-skip-right "abcdef" char? 2))) |
| 1022 |
(test 2 |
| 1023 |
(dummy-index "abcdef" |
| 1024 |
(string-index "abcdef" char? 2 5))) |
| 1025 |
(test 4 |
| 1026 |
(dummy-index "abcdef" |
| 1027 |
(string-index "abcdef" |
| 1028 |
(lambda (c) (char>? c #\d)) 2 5))) |
| 1029 |
(test #f |
| 1030 |
(dummy-index "abcdef" |
| 1031 |
(string-index "abcdef" char-whitespace? 2 5))) |
| 1032 |
(test 4 |
| 1033 |
(dummy-index "abcdef" |
| 1034 |
(string-index-right "abcdef" char? 2 5))) |
| 1035 |
(test 4 |
| 1036 |
(dummy-index "abcdef" |
| 1037 |
(string-index-right "abcdef" |
| 1038 |
(lambda (c) |
| 1039 |
(char>? c #\d)) 2 5))) |
| 1040 |
(test #f |
| 1041 |
(dummy-index "abcdef" |
| 1042 |
(string-index-right "abcdef" |
| 1043 |
char-whitespace? 2 5))) |
| 1044 |
(test 2 |
| 1045 |
(dummy-index "abcdef" |
| 1046 |
(string-skip "abcdef" string? 2 5))) |
| 1047 |
(test 4 |
| 1048 |
(dummy-index "abcdef" |
| 1049 |
(string-skip "abcdef" |
| 1050 |
(lambda (c) (char<=? c #\d)) 2 5))) |
| 1051 |
(test #f |
| 1052 |
(dummy-index "abcdef" |
| 1053 |
(string-skip "abcdef" char? 2 5))) |
| 1054 |
(test 4 |
| 1055 |
(dummy-index "abcdef" |
| 1056 |
(string-skip-right "abcdef" string? 2 5))) |
| 1057 |
(test 4 |
| 1058 |
(dummy-index "abcdef" |
| 1059 |
(string-skip-right "abcdef" |
| 1060 |
(lambda (c) |
| 1061 |
(char<=? c #\d)) 2 5))) |
| 1062 |
(test #f |
| 1063 |
(dummy-index "abcdef" |
| 1064 |
(string-skip-right "abcdef" char? 2 5))) |
| 1065 |
(test 0 |
| 1066 |
(dummy-index "" |
| 1067 |
(string-contains "" ""))) |
| 1068 |
(test 0 |
| 1069 |
(dummy-index "abcdeffffoo" |
| 1070 |
(string-contains "abcdeffffoo" ""))) |
| 1071 |
(test 0 |
| 1072 |
(dummy-index "abcdeffffoo" |
| 1073 |
(string-contains "abcdeffffoo" "a"))) |
| 1074 |
(test 5 |
| 1075 |
(dummy-index "abcdeffffoo" |
| 1076 |
(string-contains "abcdeffffoo" "ff"))) |
| 1077 |
(test 4 |
| 1078 |
(dummy-index "abcdeffffoo" |
| 1079 |
(string-contains "abcdeffffoo" "eff"))) |
| 1080 |
(test 8 |
| 1081 |
(dummy-index "abcdeffffoo" |
| 1082 |
(string-contains "abcdeffffoo" "foo"))) |
| 1083 |
(test #f |
| 1084 |
(dummy-index "abcdeffffoo" |
| 1085 |
(string-contains "abcdeffffoo" "efffoo"))) |
| 1086 |
(test 0 |
| 1087 |
(dummy-index "" |
| 1088 |
(string-contains-right "" ""))) |
| 1089 |
(test 11 |
| 1090 |
(dummy-index "abcdeffffoo" |
| 1091 |
(string-contains-right "abcdeffffoo" ""))) |
| 1092 |
(test 0 |
| 1093 |
(dummy-index "abcdeffffoo" |
| 1094 |
(string-contains-right "abcdeffffoo" "a"))) |
| 1095 |
(test 7 |
| 1096 |
(dummy-index "abcdeffffoo" |
| 1097 |
(string-contains-right "abcdeffffoo" "ff"))) |
| 1098 |
(test 4 |
| 1099 |
(dummy-index "abcdeffffoo" |
| 1100 |
(string-contains-right "abcdeffffoo" "eff"))) |
| 1101 |
(test 8 |
| 1102 |
(dummy-index "abcdeffffoo" |
| 1103 |
(string-contains-right "abcdeffffoo" "foo"))) |
| 1104 |
(test #f |
| 1105 |
(dummy-index "abcdeffffoo" |
| 1106 |
(string-contains-right "abcdeffffoo" |
| 1107 |
"efffoo"))) |
| 1108 |
(test 0 |
| 1109 |
(dummy-index "" |
| 1110 |
(string-contains "" "" 0))) |
| 1111 |
(test 2 |
| 1112 |
(dummy-index "abcdeffffoo" |
| 1113 |
(string-contains "abcdeffffoo" "" 2))) |
| 1114 |
(test #f |
| 1115 |
(dummy-index "abcdeffffoo" |
| 1116 |
(string-contains "abcdeffffoo" "a" 2))) |
| 1117 |
(test 5 |
| 1118 |
(dummy-index "abcdeffffoo" |
| 1119 |
(string-contains "abcdeffffoo" "ff" 2))) |
| 1120 |
(test 4 |
| 1121 |
(dummy-index "abcdeffffoo" |
| 1122 |
(string-contains "abcdeffffoo" "eff" 2))) |
| 1123 |
(test 8 |
| 1124 |
(dummy-index "abcdeffffoo" |
| 1125 |
(string-contains "abcdeffffoo" "foo" 2))) |
| 1126 |
(test #f |
| 1127 |
(dummy-index "abcdeffffoo" |
| 1128 |
(string-contains "abcdeffffoo" "efffoo" 2))) |
| 1129 |
(test 0 |
| 1130 |
(dummy-index "" |
| 1131 |
(string-contains-right "" "" 0))) |
| 1132 |
(test 11 |
| 1133 |
(dummy-index "abcdeffffoo" |
| 1134 |
(string-contains-right "abcdeffffoo" |
| 1135 |
"" 2))) |
| 1136 |
(test #f |
| 1137 |
(dummy-index "abcdeffffoo" |
| 1138 |
(string-contains-right "abcdeffffoo" |
| 1139 |
"a" 2))) |
| 1140 |
(test 7 |
| 1141 |
(dummy-index "abcdeffffoo" |
| 1142 |
(string-contains-right "abcdeffffoo" |
| 1143 |
"ff" 2))) |
| 1144 |
(test 4 |
| 1145 |
(dummy-index "abcdeffffoo" |
| 1146 |
(string-contains-right "abcdeffffoo" |
| 1147 |
"eff" 2))) |
| 1148 |
(test 8 |
| 1149 |
(dummy-index "abcdeffffoo" |
| 1150 |
(string-contains-right "abcdeffffoo" |
| 1151 |
"foo" 2))) |
| 1152 |
(test #f |
| 1153 |
(dummy-index "abcdeffffoo" |
| 1154 |
(string-contains-right "abcdeffffoo" |
| 1155 |
"efffoo" 2))) |
| 1156 |
(test 0 |
| 1157 |
(dummy-index "" |
| 1158 |
(string-contains "" "" 0 0))) |
| 1159 |
(test 2 |
| 1160 |
(dummy-index "abcdeffffoo" |
| 1161 |
(string-contains "abcdeffffoo" |
| 1162 |
"" 2 10))) |
| 1163 |
(test #f |
| 1164 |
(dummy-index "abcdeffffoo" |
| 1165 |
(string-contains "abcdeffffoo" |
| 1166 |
"a" 2 10))) |
| 1167 |
(test 5 |
| 1168 |
(dummy-index "abcdeffffoo" |
| 1169 |
(string-contains "abcdeffffoo" |
| 1170 |
"ff" 2 10))) |
| 1171 |
(test 4 |
| 1172 |
(dummy-index "abcdeffffoo" |
| 1173 |
(string-contains "abcdeffffoo" |
| 1174 |
"eff" 2 10))) |
| 1175 |
(test #f |
| 1176 |
(dummy-index "abcdeffffoo" |
| 1177 |
(string-contains "abcdeffffoo" |
| 1178 |
"foo" 2 10))) |
| 1179 |
(test #f |
| 1180 |
(dummy-index "abcdeffffoo" |
| 1181 |
(string-contains "abcdeffffoo" |
| 1182 |
"efffoo" 2 10))) |
| 1183 |
(test 0 |
| 1184 |
(dummy-index "" |
| 1185 |
(string-contains-right "" "" 0 0))) |
| 1186 |
(test 10 |
| 1187 |
(dummy-index "abcdeffffoo" |
| 1188 |
(string-contains-right "abcdeffffoo" |
| 1189 |
"" 2 10))) |
| 1190 |
(test #f |
| 1191 |
(dummy-index "abcdeffffoo" |
| 1192 |
(string-contains-right "abcdeffffoo" |
| 1193 |
"a" 2 10))) |
| 1194 |
(test 7 |
| 1195 |
(dummy-index "abcdeffffoo" |
| 1196 |
(string-contains-right "abcdeffffoo" |
| 1197 |
"ff" 2 10))) |
| 1198 |
(test 4 |
| 1199 |
(dummy-index "abcdeffffoo" |
| 1200 |
(string-contains-right "abcdeffffoo" |
| 1201 |
"eff" 2 10))) |
| 1202 |
(test #f |
| 1203 |
(dummy-index "abcdeffffoo" |
| 1204 |
(string-contains-right "abcdeffffoo" |
| 1205 |
"foo" 2 10))) |
| 1206 |
(test #f |
| 1207 |
(dummy-index "abcdeffffoo" |
| 1208 |
(string-contains-right "abcdeffffoo" |
| 1209 |
"efffoo" 2 10))) |
| 1210 |
(test 0 |
| 1211 |
(dummy-index "" |
| 1212 |
(string-contains "" "" 0 0 0))) |
| 1213 |
(test 2 |
| 1214 |
(dummy-index "abcdeffffoo" |
| 1215 |
(string-contains "abcdeffffoo" |
| 1216 |
"" 2 10 0))) |
| 1217 |
(test 2 |
| 1218 |
(dummy-index "abcdeffffoo" |
| 1219 |
(string-contains "abcdeffffoo" |
| 1220 |
"a" 2 10 1))) |
| 1221 |
(test 5 |
| 1222 |
(dummy-index "abcdeffffoo" |
| 1223 |
(string-contains "abcdeffffoo" |
| 1224 |
"ff" 2 10 1))) |
| 1225 |
(test 5 |
| 1226 |
(dummy-index "abcdeffffoo" |
| 1227 |
(string-contains "abcdeffffoo" |
| 1228 |
"eff" 2 10 1))) |
| 1229 |
(test #f |
| 1230 |
(dummy-index "abcdeffffoo" |
| 1231 |
(string-contains "abcdeffffoo" |
| 1232 |
"foo" 2 10 1))) |
| 1233 |
(test #f |
| 1234 |
(dummy-index "abcdeffffoo" |
| 1235 |
(string-contains "abcdeffffoo" |
| 1236 |
"efffoo" 2 10 1))) |
| 1237 |
(test 0 |
| 1238 |
(dummy-index "" |
| 1239 |
(string-contains-right "" "" 0 0 0))) |
| 1240 |
(test 10 |
| 1241 |
(dummy-index "abcdeffffoo" |
| 1242 |
(string-contains-right "abcdeffffoo" |
| 1243 |
"" 2 10 0))) |
| 1244 |
(test 10 |
| 1245 |
(dummy-index "abcdeffffoo" |
| 1246 |
(string-contains-right "abcdeffffoo" |
| 1247 |
"a" 2 10 1))) |
| 1248 |
(test 8 |
| 1249 |
(dummy-index "abcdeffffoo" |
| 1250 |
(string-contains-right "abcdeffffoo" |
| 1251 |
"ff" 2 10 1))) |
| 1252 |
(test 7 |
| 1253 |
(dummy-index "abcdeffffoo" |
| 1254 |
(string-contains-right "abcdeffffoo" |
| 1255 |
"eff" 2 10 1))) |
| 1256 |
(test #f |
| 1257 |
(dummy-index "abcdeffffoo" |
| 1258 |
(string-contains-right "abcdeffffoo" |
| 1259 |
"foo" 2 10 1))) |
| 1260 |
(test #f |
| 1261 |
(dummy-index "abcdeffffoo" |
| 1262 |
(string-contains-right "abcdeffffoo" |
| 1263 |
"efffoo" 2 10 1))) |
| 1264 |
(test 0 |
| 1265 |
(dummy-index "" |
| 1266 |
(string-contains "" "" 0 0 0 0))) |
| 1267 |
(test 2 |
| 1268 |
(dummy-index "abcdeffffoo" |
| 1269 |
(string-contains "abcdeffffoo" |
| 1270 |
"" 2 10 0 0))) |
| 1271 |
(test 2 |
| 1272 |
(dummy-index "abcdeffffoo" |
| 1273 |
(string-contains "abcdeffffoo" |
| 1274 |
"a" 2 10 1 1))) |
| 1275 |
(test 5 |
| 1276 |
(dummy-index "abcdeffffoo" |
| 1277 |
(string-contains "abcdeffffoo" |
| 1278 |
"ff" 2 10 1 2))) |
| 1279 |
(test 5 |
| 1280 |
(dummy-index "abcdeffffoo" |
| 1281 |
(string-contains "abcdeffffoo" |
| 1282 |
"eff" 2 10 1 2))) |
| 1283 |
(test 9 |
| 1284 |
(dummy-index "abcdeffffoo" |
| 1285 |
(string-contains "abcdeffffoo" |
| 1286 |
"foo" 2 10 1 2))) |
| 1287 |
(test 4 |
| 1288 |
(dummy-index "abcdeffffoo" |
| 1289 |
(string-contains "abcdeffffoo" |
| 1290 |
"efffoo" 2 10 0 2))) |
| 1291 |
(test 0 |
| 1292 |
(dummy-index "" |
| 1293 |
(string-contains-right "" "" 0 0 0 0))) |
| 1294 |
(test 10 |
| 1295 |
(dummy-index "abcdeffffoo" |
| 1296 |
(string-contains-right "abcdeffffoo" |
| 1297 |
"" 2 10 0 0))) |
| 1298 |
(test 10 |
| 1299 |
(dummy-index "abcdeffffoo" |
| 1300 |
(string-contains-right "abcdeffffoo" |
| 1301 |
"a" 2 10 1 1))) |
| 1302 |
(test 8 |
| 1303 |
(dummy-index "abcdeffffoo" |
| 1304 |
(string-contains-right "abcdeffffoo" |
| 1305 |
"ff" 2 10 1 2))) |
| 1306 |
(test 8 |
| 1307 |
(dummy-index "abcdeffffoo" |
| 1308 |
(string-contains-right "abcdeffffoo" |
| 1309 |
"eff" 2 10 1 2))) |
| 1310 |
(test 9 |
| 1311 |
(dummy-index "abcdeffffoo" |
| 1312 |
(string-contains-right "abcdeffffoo" |
| 1313 |
"foo" 2 10 1 2))) |
| 1314 |
(test 7 |
| 1315 |
(dummy-index "abcdeffffoo" |
| 1316 |
(string-contains-right "abcdeffffoo" |
| 1317 |
"efffoo" 2 10 1 3))) |
| 1318 |
) |
| 1319 |
;;; The whole string |
| 1320 |
(test-group "srfi-152:larceny:wholestring" |
| 1321 |
(test "" (string-concatenate '())) |
| 1322 |
(test "abcdef" (string-concatenate '("" "a" "bcd" "" "ef" "" ""))) |
| 1323 |
(test "" (string-concatenate-reverse '())) |
| 1324 |
(test "efbcda" |
| 1325 |
(string-concatenate-reverse '("" "a" "bcd" "" "ef" "" ""))) |
| 1326 |
(test "huh?" (string-concatenate-reverse '() "huh?")) |
| 1327 |
(test "efbcdaxy" |
| 1328 |
(string-concatenate-reverse '("" "a" "bcd" "" "ef" "" "") "xy")) |
| 1329 |
(test "huh" (string-concatenate-reverse '() "huh?" 3)) |
| 1330 |
(test "efbcdax" |
| 1331 |
(string-concatenate-reverse '("" "a" "bcd" "" "ef" "" "") "x" 1)) |
| 1332 |
(test 8 |
| 1333 |
(string-fold (lambda (c count) |
| 1334 |
(if (char-whitespace? c) |
| 1335 |
(+ count 1) |
| 1336 |
count)) |
| 1337 |
0 |
| 1338 |
" ...a couple of spaces in this one... ")) |
| 1339 |
(test 7 |
| 1340 |
(string-fold (lambda (c count) |
| 1341 |
(if (char-whitespace? c) |
| 1342 |
(+ count 1) |
| 1343 |
count)) |
| 1344 |
0 |
| 1345 |
" ...a couple of spaces in this one... " |
| 1346 |
1)) |
| 1347 |
(test 6 |
| 1348 |
(string-fold (lambda (c count) |
| 1349 |
(if (char-whitespace? c) |
| 1350 |
(+ count 1) |
| 1351 |
count)) |
| 1352 |
0 |
| 1353 |
" ...a couple of spaces in this one... " |
| 1354 |
1 |
| 1355 |
32)) |
| 1356 |
(test (string->list "abcdef") |
| 1357 |
(string-fold-right cons '() "abcdef")) |
| 1358 |
(test (string->list "def") |
| 1359 |
(string-fold-right cons '() "abcdef" 3)) |
| 1360 |
(test (string->list "cde") |
| 1361 |
(string-fold-right cons '() "abcdef" 2 5)) |
| 1362 |
(test "aabraacaadaabraa" |
| 1363 |
(let* ((s "abracadabra") |
| 1364 |
(ans-len (string-fold (lambda (c sum) |
| 1365 |
(+ sum (if (char=? c #\a) 2 1))) |
| 1366 |
0 s)) |
| 1367 |
(ans (make-string ans-len))) |
| 1368 |
(string-fold (lambda (c i) |
| 1369 |
(let ((i (if (char=? c #\a) |
| 1370 |
(begin (string-set! ans i #\a) |
| 1371 |
(+ i 1)) |
| 1372 |
i))) |
| 1373 |
(string-set! ans i c) |
| 1374 |
(+ i 1))) |
| 1375 |
0 s) |
| 1376 |
ans)) |
| 1377 |
(test '(101 100 99 98 97) |
| 1378 |
(let ((s "abcde") (v '())) |
| 1379 |
(string-for-each |
| 1380 |
(lambda (char) |
| 1381 |
(set! v (cons (char->integer char) v))) |
| 1382 |
s) |
| 1383 |
v)) |
| 1384 |
(test "cdefabcdefabcd" |
| 1385 |
(string-replicate "abcdef" -4 10)) |
| 1386 |
(test "bcdefbcdefbcd" |
| 1387 |
(string-replicate "abcdef" 90 103 1)) |
| 1388 |
(test "ecdecdecde" |
| 1389 |
(string-replicate "abcdef" -13 -3 2 5)) |
| 1390 |
(test 6 (string-count "abcdef" char?)) |
| 1391 |
(test 4 (string-count "counting whitespace, again " char-whitespace? 5)) |
| 1392 |
(test 3 (string-count "abcdefwxyz" |
| 1393 |
(lambda (c) (odd? (char->integer c))) |
| 1394 |
2 8)) |
| 1395 |
(test "It's lots of fun to code it up in Scheme." |
| 1396 |
(string-replace "It's easy to code it up in Scheme." |
| 1397 |
"lots of fun" |
| 1398 |
5 9)) |
| 1399 |
(test "The miserable perl programmer endured daily ridicule." |
| 1400 |
(string-replace "The TCL programmer endured daily ridicule." |
| 1401 |
"another miserable perl drone" |
| 1402 |
4 7 8 22)) |
| 1403 |
(test "It's really easy to code it up in Scheme." |
| 1404 |
(string-replace "It's easy to code it up in Scheme." |
| 1405 |
"really " |
| 1406 |
5 5)) |
| 1407 |
(test-assert (null? (string-split "" ""))) |
| 1408 |
(test '("a" "b" "c") (string-split "abc" "")) |
| 1409 |
(test '() (string-split "" "" 'infix)) |
| 1410 |
(test '("a" "b" "c") (string-split "abc" "" 'infix)) |
| 1411 |
(test '("a" "b" "c") (string-split "abc" "" 'strict-infix)) |
| 1412 |
(test '() (string-split "" "" 'prefix)) |
| 1413 |
(test '("a" "b" "c") (string-split "abc" "" 'prefix)) |
| 1414 |
(test '() (string-split "" "" 'suffix)) |
| 1415 |
(test '("a" "b" "c") (string-split "abc" "" 'suffix)) |
| 1416 |
(test '() (string-split "" "" 'infix #f)) |
| 1417 |
(test '("a" "b" "c") (string-split "abc" "" 'infix #f)) |
| 1418 |
(test-error |
| 1419 |
(string-split "" "" 'strict-infix)) |
| 1420 |
(test '("a" "b" "c") (string-split "abc" "" 'strict-infix 3)) |
| 1421 |
(test '() (string-split "" "" 'prefix 3)) |
| 1422 |
(test '("a" "b" "c") (string-split "abc" "" 'prefix 3)) |
| 1423 |
(test '() (string-split "" "" 'suffix 3)) |
| 1424 |
(test '("a" "b" "c") (string-split "abc" "" 'suffix 3)) |
| 1425 |
(test '("b" "c") (string-split "abc" "" 'strict-infix 3 1)) |
| 1426 |
(test '() (string-split "" "" 'prefix 3 0)) |
| 1427 |
(test '("b" "c") (string-split "abc" "" 'prefix 3 1)) |
| 1428 |
(test '("b") (string-split "abc" "" 'strict-infix 3 1 2)) |
| 1429 |
(test '() (string-split "" "" 'prefix 3 0 0)) |
| 1430 |
(test '("b") (string-split "abc" "" 'prefix 3 1 2)) |
| 1431 |
(test '() (string-split "" "" 'suffix 3 0 0)) |
| 1432 |
(test '("b") (string-split "abc" "" 'suffix 3 1 2)) |
| 1433 |
(test "aiueaaaoi" |
| 1434 |
(string-filter (lambda (c) (memv c (string->list "aeiou"))) |
| 1435 |
"What is number, that man may know it?")) |
| 1436 |
(test "And wmn, tht sh my knw nmbr?" |
| 1437 |
(string-remove (lambda (c) (memv c (string->list "aeiou"))) |
| 1438 |
"And woman, that she may know number?")) |
| 1439 |
(test "iueaaaoi" |
| 1440 |
(string-filter (lambda (c) (memv c (string->list "aeiou"))) |
| 1441 |
"What is number, that man may know it?" |
| 1442 |
4)) |
| 1443 |
(test "mn, tht sh my knw nmbr?" |
| 1444 |
(string-remove (lambda (c) (memv c (string->list "aeiou"))) |
| 1445 |
"And woman, that she may know number?" |
| 1446 |
6)) |
| 1447 |
(test "aaao" |
| 1448 |
(string-filter (lambda (c) (memv c (string->list "aeiou"))) |
| 1449 |
"What is number, that man may know it?" |
| 1450 |
16 32)) |
| 1451 |
(test "And woman, that sh may know" |
| 1452 |
(string-remove (lambda (c) (memv c (string->list "eiu"))) |
| 1453 |
"And woman, that she may know number?" |
| 1454 |
0 28)) |
| 1455 |
) |
| 1456 |
) |
| 1457 |
(test-group "srfi-152:residual" |
| 1458 |
(test #t (string? "abc")) |
| 1459 |
(test #f (string? 32)) |
| 1460 |
(test "$$$" (make-string 3 #\$)) |
| 1461 |
(test "$$$" (string #\$ #\$ #\$)) |
| 1462 |
(test '(#\b #\c) (string->list "abcde" 1 3)) |
| 1463 |
(test "abcde" (list->string '(#\a #\b #\c #\d #\e))) |
| 1464 |
(test "abcde" (vector->string '#(#\a #\b #\c #\d #\e))) |
| 1465 |
(test '("12345" "abcde") |
| 1466 |
(call-with-values (lambda () (string-span "12345abcde" char-numeric?)) list)) |
| 1467 |
(test '("12345" "abcde") |
| 1468 |
(call-with-values (lambda () (string-break "12345abcde" char-alphabetic?)) list)) |
| 1469 |
(test "abcde" (string-take-while "abcde12345" char-alphabetic?)) |
| 1470 |
(test "abcde" (string-take-while-right "12345abcde" char-alphabetic?)) |
| 1471 |
(test "abcde" (string-drop-while " abcde" char-whitespace?)) |
| 1472 |
(test "abcde" (string-drop-while-right "abcde " char-whitespace?)) |
| 1473 |
(test 5 (string-length "abcde")) |
| 1474 |
(test "ab!" |
| 1475 |
(let ((abc (string-copy "abc"))) |
| 1476 |
(string-set! abc 2 #\!) |
| 1477 |
abc)) |
| 1478 |
(test "ab!" |
| 1479 |
(let ((abc (string-copy "abc"))) |
| 1480 |
(string-set! abc 2 #\!) |
| 1481 |
abc)) |
| 1482 |
(test "!!!" |
| 1483 |
(let ((abc (string-copy "abc"))) |
| 1484 |
(string-fill! abc #\!) |
| 1485 |
abc)) |
| 1486 |
(test "a!c" |
| 1487 |
(let ((abc (string-copy "abc"))) |
| 1488 |
(string-fill! abc #\! 1 2) |
| 1489 |
abc)) |
| 1490 |
) |
| 1491 |
) |
| 1492 |
;(test-exit) |