123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674 |
- ;;;; srfi-13.test --- Test suite for Guile's SRFI-13 functions. -*- scheme -*-
- ;;;; Martin Grabmueller, 2001-05-07
- ;;;;
- ;;;; Copyright (C) 2001, 2004, 2005, 2006, 2011, 2012 Free Software Foundation, Inc.
- ;;;;
- ;;;; This library is free software; you can redistribute it and/or
- ;;;; modify it under the terms of the GNU Lesser General Public
- ;;;; License as published by the Free Software Foundation; either
- ;;;; version 3 of the License, or (at your option) any later version.
- ;;;;
- ;;;; This library is distributed in the hope that it will be useful,
- ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
- ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- ;;;; Lesser General Public License for more details.
- ;;;;
- ;;;; You should have received a copy of the GNU Lesser General Public
- ;;;; License along with this library; if not, write to the Free Software
- ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- (define-module (test-strings)
- #:use-module (test-suite lib)
- #:use-module (srfi srfi-13)
- #:use-module (srfi srfi-14))
- (define exception:strict-infix-grammar
- (cons 'misc-error "^strict-infix"))
- ;; Create a string from integer char values, eg. (string-ints 65) => "A"
- (define (string-ints . args)
- (apply string (map integer->char args)))
- ;; Some abbreviations
- ;; BMP - Basic Multilingual Plane (codepoints below U+FFFF)
- ;; SMP - Suplementary Multilingual Plane (codebpoints from U+10000 to U+1FFFF)
- ;;;
- ;;; string-any
- ;;;
- (with-test-prefix "string-any"
- (pass-if "null string"
- (not (string-any #\a "")))
- (pass-if "start index == end index"
- (not (string-any #\a "aaa" 1 1)))
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-any 123 "abcde"))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-any "zzz" "abcde")))
- (with-test-prefix "char"
- (pass-if "no match"
- (not (string-any #\C "abcde")))
- (pass-if "one match"
- (string-any #\C "abCde"))
- (pass-if "one match: BMP"
- (string-any (integer->char #x0100) "ab\u0100de"))
- (pass-if "one match: SMP"
- (string-any (integer->char #x010300) "ab\U010300de"))
- (pass-if "more than one match"
- (string-any #\X "abXXX"))
- (pass-if "no match, start index"
- (not (string-any #\A "Abcde" 1)))
- (pass-if "one match, start index"
- (string-any #\C "abCde" 1))
- (pass-if "more than one match, start index"
- (string-any #\X "abXXX" 1))
- (pass-if "no match, start and end index"
- (not (string-any #\X "XbcdX" 1 4)))
- (pass-if "one match, start and end index"
- (string-any #\C "abCde" 1 4))
- (pass-if "more than one match, start and end index"
- (string-any #\X "abXXX" 1 4)))
- (with-test-prefix "charset"
- (pass-if "no match"
- (not (string-any char-set:upper-case "abcde")))
- (pass-if "one match"
- (string-any char-set:upper-case "abCde"))
- (pass-if "more than one match"
- (string-any char-set:upper-case "abCDE"))
- (pass-if "no match, start index"
- (not (string-any char-set:upper-case "Abcde" 1)))
- (pass-if "one match, start index"
- (string-any char-set:upper-case "abCde" 1))
- (pass-if "more than one match, start index"
- (string-any char-set:upper-case "abCDE" 1))
- (pass-if "no match, start and end index"
- (not (string-any char-set:upper-case "AbcdE" 1 4)))
- (pass-if "one match, start and end index"
- (string-any char-set:upper-case "abCde" 1 4))
- (pass-if "more than one match, start and end index"
- (string-any char-set:upper-case "abCDE" 1 4)))
- (with-test-prefix "pred"
- (pass-if "no match"
- (not (string-any char-upper-case? "abcde")))
- (pass-if "one match"
- (string-any char-upper-case? "abCde"))
- (pass-if "more than one match"
- (string-any char-upper-case? "abCDE"))
- (pass-if "no match, start index"
- (not (string-any char-upper-case? "Abcde" 1)))
- (pass-if "one match, start index"
- (string-any char-upper-case? "abCde" 1))
- (pass-if "more than one match, start index"
- (string-any char-upper-case? "abCDE" 1))
- (pass-if "no match, start and end index"
- (not (string-any char-upper-case? "AbcdE" 1 4)))
- (pass-if "one match, start and end index"
- (string-any char-upper-case? "abCde" 1 4))
- (pass-if "more than one match, start and end index"
- (string-any char-upper-case? "abCDE" 1 4))))
- ;;;
- ;;; string-titlecase
- ;;;
- (with-test-prefix "string-titlecase"
- (pass-if "all-lower"
- (string=? "Foo" (string-titlecase "foo")))
- (pass-if "all-upper"
- (string=? "Foo" (string-titlecase "FOO")))
- (pass-if "two-words"
- (string=? "Hello, World!" (string-titlecase "hello, world!")))
- (pass-if "titlecase-characters"
- (string=? (list->string '(#\762))
- (string-titlecase (list->string '(#\763))))))
- ;;;
- ;;; string-append/shared
- ;;;
- (with-test-prefix "string-append/shared"
- (pass-if "no args"
- (string=? "" (string-append/shared)))
- (with-test-prefix "one arg"
- (pass-if "empty"
- (string=? "" (string-append/shared "")))
- (pass-if "non-empty"
- (string=? "xyz" (string-append/shared "xyz"))))
- (with-test-prefix "two args"
- (pass-if (string=? "" (string-append/shared "" "")))
- (pass-if (string=? "xyz" (string-append/shared "xyz" "")))
- (pass-if (string=? "xyz" (string-append/shared "" "xyz")))
- (pass-if (string=? "abcxyz" (string-append/shared "abc" "xyz")))
- (pass-if (string=? "abc\u0100\u0101"
- (string-append/shared "abc" "\u0100\u0101"))))
- (with-test-prefix "three args"
- (pass-if (string=? "" (string-append/shared "" "" "")))
- (pass-if (string=? "xy" (string-append/shared "xy" "" "")))
- (pass-if (string=? "xy" (string-append/shared "" "xy" "")))
- (pass-if (string=? "abxy" (string-append/shared "ab" "xy" "")))
- (pass-if (string=? "ab" (string-append/shared "" "" "ab")))
- (pass-if (string=? "xyab" (string-append/shared "xy" "" "ab")))
- (pass-if (string=? "xyab" (string-append/shared "" "xy" "ab")))
- (pass-if (string=? "ghxyab" (string-append/shared "gh" "xy" "ab"))))
- (with-test-prefix "four args"
- (pass-if (string=? "" (string-append/shared "" "" "" "")))
- (pass-if (string=? "xy" (string-append/shared "xy" "" "" "")))
- (pass-if (string=? "xy" (string-append/shared "" "xy" "" "")))
- (pass-if (string=? "xy" (string-append/shared "" "" "xy" "")))
- (pass-if (string=? "xy" (string-append/shared "" "" "" "xy")))
- (pass-if (string=? "abxy" (string-append/shared "ab" "xy" "" "")))
- (pass-if (string=? "abxy" (string-append/shared "ab" "" "xy" "")))
- (pass-if (string=? "abxy" (string-append/shared "ab" "" "" "xy")))
- (pass-if (string=? "abxy" (string-append/shared "" "ab" "" "xy")))
- (pass-if (string=? "abxy" (string-append/shared "" "" "ab" "xy")))))
- ;;;
- ;;; string-concatenate
- ;;;
- (with-test-prefix "string-concatenate"
- (pass-if-exception "inum" exception:wrong-type-arg
- (string-concatenate 123))
- (pass-if-exception "symbol" exception:wrong-type-arg
- (string-concatenate 'x))
- (pass-if-exception "improper 1" exception:wrong-type-arg
- (string-concatenate '("a" . "b")))
- (pass-if (equal? "abc" (string-concatenate '("a" "b" "c"))))
- (pass-if "concatenate BMP"
- (equal? "a\u0100" (string-concatenate '("a" "\u0100")))))
- ;;
- ;; string-compare
- ;;
- (with-test-prefix "string-compare"
- (pass-if "same as char<?"
- (eq? (char<? (integer->char 0) (integer->char 255))
- (string-compare (string-ints 0) (string-ints 255)
- (lambda (pos) #t) ;; lt
- (lambda (pos) #f) ;; eq
- (lambda (pos) #f))))) ;; gt
- ;;
- ;; string-compare-ci
- ;;
- (with-test-prefix "string-compare-ci"
- (pass-if "same as char-ci<?"
- (eq? (char-ci<? (integer->char 0) (integer->char 255))
- (string-compare-ci (string-ints 0) (string-ints 255)
- (lambda (pos) #t) ;; lt
- (lambda (pos) #f) ;; eq
- (lambda (pos) #f))))) ;; gt
- ;;;
- ;;; string-concatenate/shared
- ;;;
- (with-test-prefix "string-concatenate/shared"
- (pass-if-exception "inum" exception:wrong-type-arg
- (string-concatenate/shared 123))
- (pass-if-exception "symbol" exception:wrong-type-arg
- (string-concatenate/shared 'x))
- (pass-if-exception "improper 1" exception:wrong-type-arg
- (string-concatenate/shared '("a" . "b")))
- (pass-if (equal? "abc" (string-concatenate/shared '("a" "b" "c"))))
- (pass-if "BMP"
- (equal? "a\u0100c" (string-concatenate/shared '("a" "\u0100" "c")))))
- ;;;
- ;;; string-every
- ;;;
- (with-test-prefix "string-every"
- (pass-if "null string"
- (string-every #\a ""))
- (pass-if "start index == end index"
- (string-every #\a "bbb" 1 1))
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-every 123 "abcde"))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-every "zzz" "abcde")))
- (with-test-prefix "char"
- (pass-if "empty string"
- (string-every #\X ""))
- (pass-if "empty substring"
- (string-every #\X "abc" 1 1))
- (pass-if "no match at all"
- (not (string-every #\X "abcde")))
- (pass-if "not all match"
- (not (string-every #\X "abXXX")))
- (pass-if "all match"
- (string-every #\X "XXXXX"))
- (pass-if "all match BMP"
- (string-every #\200000 "\U010000\U010000"))
- (pass-if "no match at all, start index"
- (not (string-every #\X "Xbcde" 1)))
- (pass-if "not all match, start index"
- (not (string-every #\X "XXcde" 1)))
- (pass-if "all match, start index"
- (string-every #\X "aXXXX" 1))
- (pass-if "no match at all, start and end index"
- (not (string-every #\X "XbcdX" 1 4)))
- (pass-if "not all match, start and end index"
- (not (string-every #\X "XXcde" 1 4)))
- (pass-if "all match, start and end index"
- (string-every #\X "aXXXe" 1 4)))
- (with-test-prefix "charset"
- (pass-if "empty string"
- (string-every char-set:upper-case ""))
- (pass-if "empty substring"
- (string-every char-set:upper-case "abc" 1 1))
- (pass-if "no match at all"
- (not (string-every char-set:upper-case "abcde")))
- (pass-if "not all match"
- (not (string-every char-set:upper-case "abCDE")))
- (pass-if "all match"
- (string-every char-set:upper-case "ABCDE"))
- (pass-if "no match at all, start index"
- (not (string-every char-set:upper-case "Abcde" 1)))
- (pass-if "not all match, start index"
- (not (string-every char-set:upper-case "ABcde" 1)))
- (pass-if "all match, start index"
- (string-every char-set:upper-case "aBCDE" 1))
- (pass-if "no match at all, start and end index"
- (not (string-every char-set:upper-case "AbcdE" 1 4)))
- (pass-if "not all match, start and end index"
- (not (string-every char-set:upper-case "ABcde" 1 4)))
- (pass-if "all match, start and end index"
- (string-every char-set:upper-case "aBCDe" 1 4)))
- (with-test-prefix "pred"
- ;; in guile 1.6.4 and earlier string-every incorrectly returned #f on an
- ;; empty string
- (pass-if "empty string"
- (string-every char-upper-case? ""))
- (pass-if "empty substring"
- (string-every char-upper-case? "abc" 1 1))
- (pass-if "no match at all"
- (not (string-every char-upper-case? "abcde")))
- (pass-if "not all match"
- (not (string-every char-upper-case? "abCDE")))
- (pass-if "all match"
- (string-every char-upper-case? "ABCDE"))
- (pass-if "no match at all, start index"
- (not (string-every char-upper-case? "Abcde" 1)))
- (pass-if "not all match, start index"
- (not (string-every char-upper-case? "ABcde" 1)))
- (pass-if "all match, start index"
- (string-every char-upper-case? "aBCDE" 1))
- (pass-if "no match at all, start and end index"
- (not (string-every char-upper-case? "AbcdE" 1 4)))
- (pass-if "not all match, start and end index"
- (not (string-every char-upper-case? "ABcde" 1 4)))
- (pass-if "all match, start and end index"
- (string-every char-upper-case? "aBCDe" 1 4))))
- (with-test-prefix "string-tabulate"
- (with-test-prefix "bad proc"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-tabulate 123 10))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-tabulate "zzz" 10)))
- (pass-if "static fill-char"
- (string=? (string-tabulate (lambda (idx) #\!) 10) "!!!!!!!!!!"))
- (pass-if "variable fill-char"
- (string=? (string-tabulate
- (lambda (idx) (integer->char (+ idx 32))) 10) " !\"#$%&'()")))
- (with-test-prefix "string->list"
- (pass-if "empty"
- (zero? (length (string->list ""))))
- (pass-if "nonempty"
- (= (length (string->list "foo")) 3))
- (pass-if "empty, start index"
- (zero? (length (string->list "foo" 3 3))))
- (pass-if "nonempty, start index"
- (= (length (string->list "foo" 1 3)) 2))
- (pass-if "nonempty, start index, BMP"
- (= (length (string->list "\xff\u0100\u0300" 1 3)) 2))
- )
- (with-test-prefix "reverse-list->string"
- (pass-if "empty"
- (string-null? (reverse-list->string '())))
- (pass-if "nonempty"
- (string=? "foo" (reverse-list->string '(#\o #\o #\f))))
- (pass-if "nonempty, BMP"
- (string=? "\u0100\u0101\u0102" (reverse-list->string '(#\402 #\401 #\400)))))
- (with-test-prefix "string-join"
- (pass-if "empty list, no delimiter, implicit infix, empty 1"
- (string=? "" (string-join '())))
- (pass-if "empty string, no delimiter, implicit infix, empty 2"
- (string=? "" (string-join '(""))))
- (pass-if "non-empty, no delimiter, implicit infix"
- (string=? "bla" (string-join '("bla"))))
- (pass-if "empty list, implicit infix, empty 1"
- (string=? "" (string-join '() "|delim|")))
- (pass-if "empty string, implicit infix, empty 2"
- (string=? "" (string-join '("") "|delim|")))
- (pass-if "non-empty, implicit infix"
- (string=? "bla" (string-join '("bla") "|delim|")))
- (pass-if "non-empty, implicit infix"
- (string=? "bla" (string-join '("bla") "|delim|")))
- (pass-if "two strings, implicit infix"
- (string=? "bla|delim|fasel" (string-join '("bla" "fasel") "|delim|")))
- (pass-if "empty, explicit infix"
- (string=? "" (string-join '("") "|delim|" 'infix)))
- (pass-if "empty list, explicit infix"
- (string=? "" (string-join '() "|delim|" 'infix)))
- (pass-if "non-empty, explicit infix"
- (string=? "bla" (string-join '("bla") "|delim|" 'infix)))
- (pass-if "two strings, explicit infix"
- (string=? "bla|delim|fasel" (string-join '("bla" "fasel") "|delim|"
- 'infix)))
- (pass-if "two strings, explicit infix, BMP"
- (string=? "\u0100\u0101::\u0102\u0103"
- (string-join '("\u0100\u0101" "\u0102\u0103") "::"
- 'infix)))
- (pass-if-exception "empty list, strict infix"
- exception:strict-infix-grammar
- (string-join '() "|delim|" 'strict-infix))
- (pass-if "empty, strict infix"
- (string=? "" (string-join '("") "|delim|" 'strict-infix)))
- (pass-if "non-empty, strict infix"
- (string=? "foo" (string-join '("foo") "|delim|" 'strict-infix)))
- (pass-if "two strings, strict infix"
- (string=? "foo|delim|bar" (string-join '("foo" "bar") "|delim|"
- 'strict-infix)))
- (pass-if "empty list, prefix"
- (string=? "" (string-join '() "|delim|" 'prefix)))
- (pass-if "empty, prefix"
- (string=? "|delim|" (string-join '("") "|delim|" 'prefix)))
- (pass-if "non-empty, prefix"
- (string=? "|delim|foo" (string-join '("foo") "|delim|" 'prefix)))
- (pass-if "two strings, prefix"
- (string=? "|delim|foo|delim|bar" (string-join '("foo" "bar") "|delim|"
- 'prefix)))
- (pass-if "empty list, suffix"
- (string=? "" (string-join '() "|delim|" 'suffix)))
- (pass-if "empty, suffix"
- (string=? "|delim|" (string-join '("") "|delim|" 'suffix)))
- (pass-if "non-empty, suffix"
- (string=? "foo|delim|" (string-join '("foo") "|delim|" 'suffix)))
- (pass-if "two strings, suffix"
- (string=? "foo|delim|bar|delim|" (string-join '("foo" "bar") "|delim|"
- 'suffix))))
- (with-test-prefix "string-copy"
- (pass-if "empty string"
- (string=? "" (string-copy "")))
- (pass-if "full string"
- (string=? "foo-bar" (string-copy "foo-bar")))
- (pass-if "full string, BMP"
- (string=? "foo-\u0100\u0101" (string-copy "foo-\u0100\u0101")))
- (pass-if "start index"
- (string=? "o-bar" (string-copy "foo-bar" 2)))
- (pass-if "start index"
- (string=? "o-bar" (string-copy "\u0100\u0101o-bar" 2)))
- (pass-if "start and end index"
- (string=? "o-ba" (string-copy "foo-bar" 2 6))))
- (with-test-prefix "substring/shared"
- (pass-if "empty string"
- (let ((s ""))
- (eq? s (substring/shared s 0))))
- (pass-if "non-empty string, not eq?"
- (string=? "foo" (substring/shared "foo-bar" 0 3)))
- (pass-if "shared copy of non-empty string is eq?"
- (let ((s "foo-bar"))
- (eq? s (substring/shared s 0 7)))))
- (with-test-prefix "string-copy!"
- (pass-if "non-empty string"
- (string=? "welld, oh yeah!"
- (let* ((s "hello")
- (t (string-copy "world, oh yeah!")))
- (string-copy! t 1 s 1 3)
- t)))
- (pass-if-equal "overlapping src and dest, moving right"
- "aabce"
- (let ((str (string-copy "abcde")))
- (string-copy! str 1 str 0 3) str))
- (pass-if-equal "overlapping src and dest, moving left"
- "bcdde"
- (let ((str (string-copy "abcde")))
- (string-copy! str 0 str 1 4) str)))
- (with-test-prefix "string-take"
- (pass-if "empty string"
- (string=? "" (string-take "foo bar braz" 0)))
- (pass-if "non-empty string"
- (string=? "foo " (string-take "foo bar braz" 4)))
- (pass-if "non-empty string BMP"
- (string=? "\u0100oo " (string-take "\u0100oo \u0101ar braz" 4)))
- (pass-if "full string"
- (string=? "foo bar braz" (string-take "foo bar braz" 12))))
- (with-test-prefix "string-take-right"
- (pass-if "empty string"
- (string=? "" (string-take-right "foo bar braz" 0)))
- (pass-if "non-empty string"
- (string=? "braz" (string-take-right "foo bar braz" 4)))
- (pass-if "non-empty string"
- (string=? "braz" (string-take-right "foo ba\u0100 braz" 4)))
- (pass-if "full string"
- (string=? "foo bar braz" (string-take-right "foo bar braz" 12))))
- (with-test-prefix "string-drop"
- (pass-if "empty string"
- (string=? "" (string-drop "foo bar braz" 12)))
- (pass-if "non-empty string"
- (string=? "braz" (string-drop "foo bar braz" 8)))
- (pass-if "non-empty string BMP"
- (string=? "braz" (string-drop "foo \u0100\u0101\u0102 braz" 8)))
- (pass-if "full string"
- (string=? "foo bar braz" (string-drop "foo bar braz" 0))))
- (with-test-prefix "string-drop-right"
- (pass-if "empty string"
- (string=? "" (string-drop-right "foo bar braz" 12)))
- (pass-if "non-empty string"
- (string=? "foo " (string-drop-right "foo bar braz" 8)))
- (pass-if "non-empty string BMP"
- (string=? "foo " (string-drop-right "foo \u0100\u0101\u0102 braz" 8)))
- (pass-if "full string"
- (string=? "foo bar braz" (string-drop-right "foo bar braz" 0))))
- (with-test-prefix "string-pad"
- (pass-if "empty string, zero pad"
- (string=? "" (string-pad "" 0)))
- (pass-if "empty string, zero pad, pad char"
- (string=? "" (string-pad "" 0)))
- (pass-if "empty pad string, 2 pad "
- (string=? " " (string-pad "" 2)))
- (pass-if "empty pad string, 2 pad, pad char"
- (string=? "!!" (string-pad "" 2 #\!)))
- (pass-if "empty pad string, 2 pad, pad char, start index"
- (string=? "!c" (string-pad "abc" 2 #\! 2)))
- (pass-if "empty pad string, 2 pad, pad char, start and end index"
- (string=? "!c" (string-pad "abcd" 2 #\! 2 3)))
- (pass-if "freestyle 1"
- (string=? "32" (string-pad (number->string 532) 2 #\!)))
- (pass-if "freestyle 2"
- (string=? "!532" (string-pad (number->string 532) 4 #\!))))
- (with-test-prefix "string-pad-right"
- (pass-if "empty string, zero pad"
- (string=? "" (string-pad-right "" 0)))
- (pass-if "empty string, zero pad, pad char"
- (string=? "" (string-pad-right "" 0)))
- (pass-if "empty pad string, 2 pad "
- (string=? " " (string-pad-right "" 2)))
- (pass-if "empty pad string, 2 pad, pad char"
- (string=? "!!" (string-pad-right "" 2 #\!)))
- (pass-if "empty pad string, 2 pad, pad char, start index"
- (string=? "c!" (string-pad-right "abc" 2 #\! 2)))
- (pass-if "empty pad string, 2 pad, pad char, start and end index"
- (string=? "c!" (string-pad-right "abcd" 2 #\! 2 3)))
- (pass-if "freestyle 1"
- (string=? "53" (string-pad-right (number->string 532) 2 #\!)))
- (pass-if "freestyle 2"
- (string=? "532!" (string-pad-right (number->string 532) 4 #\!))))
- (with-test-prefix "string-trim"
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-trim "abcde" 123))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-trim "abcde" "zzz")))
- (pass-if "empty string"
- (string=? "" (string-trim "")))
- (pass-if "no char/pred"
- (string=? "foo " (string-trim " \tfoo ")))
- (pass-if "start index, pred"
- (string=? "foo " (string-trim " \tfoo " char-whitespace? 1)))
- (pass-if "start and end index, pred"
- (string=? "f" (string-trim " \tfoo " char-whitespace? 1 3)))
- (pass-if "start index, char"
- (string=? "\tfoo " (string-trim " \tfoo " #\space 1)))
- (pass-if "start and end index, char"
- (string=? "\tf" (string-trim " \tfoo " #\space 1 3)))
- (pass-if "start index, charset"
- (string=? "foo " (string-trim " \tfoo " char-set:whitespace 1)))
- (pass-if "start and end index, charset"
- (string=? "f" (string-trim " \tfoo " char-set:whitespace 1 3))))
- (with-test-prefix "string-trim-right"
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-trim-right "abcde" 123))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-trim-right "abcde" "zzz")))
- (pass-if "empty string"
- (string=? "" (string-trim-right "")))
- (pass-if "no char/pred"
- (string=? " \tfoo" (string-trim-right " \tfoo ")))
- (pass-if "start index, pred"
- (string=? "\tfoo" (string-trim-right " \tfoo " char-whitespace? 1)))
- (pass-if "start and end index, pred"
- (string=? "\tf" (string-trim-right " \tfoo " char-whitespace? 1 3)))
- (pass-if "start index, char"
- (string=? "\tfoo" (string-trim-right " \tfoo " #\space 1)))
- (pass-if "start and end index, char"
- (string=? "\tf" (string-trim-right " \tfoo " #\space 1 3)))
- (pass-if "start index, charset"
- (string=? "\tfoo" (string-trim-right " \tfoo " char-set:whitespace 1)))
- (pass-if "start and end index, charset"
- (string=? "\tf" (string-trim-right " \tfoo " char-set:whitespace 1 3))))
- (with-test-prefix "string-trim-both"
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-trim-both "abcde" 123))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-trim-both "abcde" "zzz")))
- (pass-if "empty string"
- (string=? "" (string-trim-both "")))
- (pass-if "no char/pred"
- (string=? "foo" (string-trim-both " \tfoo ")))
- (pass-if "start index, pred"
- (string=? "foo" (string-trim-both " \tfoo " char-whitespace? 1)))
- (pass-if "start and end index, pred"
- (string=? "f" (string-trim-both " \tfoo " char-whitespace? 1 3)))
- (pass-if "start index, char"
- (string=? "\tfoo" (string-trim-both " \tfoo " #\space 1)))
- (pass-if "start and end index, char"
- (string=? "\tf" (string-trim-both " \tfoo " #\space 1 3)))
- (pass-if "start index, charset"
- (string=? "foo" (string-trim-both " \tfoo " char-set:whitespace 1)))
- (pass-if "start and end index, charset"
- (string=? "f" (string-trim-both " \tfoo " char-set:whitespace 1 3))))
- (define s0 (make-string 200 #\!))
- (define s1 (make-string 0 #\!))
- (with-test-prefix "string-fill!"
- (pass-if "empty string, no indices"
- (string-fill! s1 #\*)
- (= (string-length s1) 0))
- (pass-if "empty string, start index"
- (string-fill! s1 #\* 0)
- (= (string-length s1) 0))
- (pass-if "empty string, start and end index"
- (string-fill! s1 #\* 0 0)
- (= (string-length s1) 0))
- (pass-if "no indices"
- (string-fill! s0 #\*)
- (char=? (string-ref s0 0) #\*))
- (pass-if "start index"
- (string-fill! s0 #\+ 10)
- (char=? (string-ref s0 11) #\+))
- (pass-if "start and end index"
- (string-fill! s0 #\| 12 20)
- (char=? (string-ref s0 13) #\|)))
- (with-test-prefix "string-prefix-length"
- (pass-if "empty prefix"
- (= 0 (string-prefix-length "" "foo bar")))
- (pass-if "non-empty prefix - match"
- (= 3 (string-prefix-length "foo" "foo bar")))
- (pass-if "non-empty prefix - no match"
- (= 0 (string-prefix-length "bar" "foo bar"))))
- (with-test-prefix "string-prefix-length-ci"
- (pass-if "empty prefix"
- (= 0 (string-prefix-length-ci "" "foo bar")))
- (pass-if "non-empty prefix - match"
- (= 3 (string-prefix-length-ci "fOo" "foo bar")))
- (pass-if "non-empty prefix - no match"
- (= 0 (string-prefix-length-ci "bAr" "foo bar"))))
- (with-test-prefix "string-suffix-length"
- (pass-if "empty suffix"
- (= 0 (string-suffix-length "" "foo bar")))
- (pass-if "non-empty suffix - match"
- (= 3 (string-suffix-length "bar" "foo bar")))
- (pass-if "non-empty suffix - no match"
- (= 0 (string-suffix-length "foo" "foo bar"))))
- (with-test-prefix "string-suffix-length-ci"
- (pass-if "empty suffix"
- (= 0 (string-suffix-length-ci "" "foo bar")))
- (pass-if "non-empty suffix - match"
- (= 3 (string-suffix-length-ci "bAr" "foo bar")))
- (pass-if "non-empty suffix - no match"
- (= 0 (string-suffix-length-ci "fOo" "foo bar"))))
- (with-test-prefix "string-prefix?"
- (pass-if "empty prefix"
- (string-prefix? "" "foo bar"))
- (pass-if "non-empty prefix - match"
- (string-prefix? "foo" "foo bar"))
- (pass-if "non-empty prefix - no match"
- (not (string-prefix? "bar" "foo bar"))))
- (with-test-prefix "string-prefix-ci?"
- (pass-if "empty prefix"
- (string-prefix-ci? "" "foo bar"))
- (pass-if "non-empty prefix - match"
- (string-prefix-ci? "fOo" "foo bar"))
- (pass-if "non-empty prefix - no match"
- (not (string-prefix-ci? "bAr" "foo bar"))))
- (with-test-prefix "string-suffix?"
- (pass-if "empty suffix"
- (string-suffix? "" "foo bar"))
- (pass-if "non-empty suffix - match"
- (string-suffix? "bar" "foo bar"))
- (pass-if "non-empty suffix - no match"
- (not (string-suffix? "foo" "foo bar"))))
- (with-test-prefix "string-suffix-ci?"
- (pass-if "empty suffix"
- (string-suffix-ci? "" "foo bar"))
- (pass-if "non-empty suffix - match"
- (string-suffix-ci? "bAr" "foo bar"))
- (pass-if "non-empty suffix - no match"
- (not (string-suffix-ci? "fOo" "foo bar"))))
- (with-test-prefix "string-index"
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-index "abcde" 123))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-index "abcde" "zzz")))
- (pass-if "empty string - char"
- (not (string-index "" #\a)))
- (pass-if "non-empty - char - match"
- (= 5 (string-index "foo bar" #\a)))
- (pass-if "non-empty - char - no match"
- (not (string-index "frobnicate" #\x)))
- (pass-if "empty string - char - start index"
- (not (string-index "" #\a 0)))
- (pass-if "non-empty - char - match - start index"
- (= 5 (string-index "foo bar" #\a 1)))
- (pass-if "non-empty - char - no match - start index"
- (not (string-index "frobnicate" #\x 2)))
- (pass-if "empty string - char - start and end index"
- (not (string-index "" #\a 0 0)))
- (pass-if "non-empty - char - match - start and end index"
- (= 5 (string-index "foo bar" #\a 1 6)))
- (pass-if "non-empty - char - no match - start and end index"
- (not (string-index "frobnicate" #\a 2 5)))
- (pass-if "empty string - charset"
- (not (string-index "" char-set:letter)))
- (pass-if "non-empty - charset - match"
- (= 0 (string-index "foo bar" char-set:letter)))
- (pass-if "non-empty - charset - no match"
- (not (string-index "frobnicate" char-set:digit)))
- (pass-if "empty string - charset - start index"
- (not (string-index "" char-set:letter 0)))
- (pass-if "non-empty - charset - match - start index"
- (= 1 (string-index "foo bar" char-set:letter 1)))
- (pass-if "non-empty - charset - no match - start index"
- (not (string-index "frobnicate" char-set:digit 2)))
- (pass-if "empty string - charset - start and end index"
- (not (string-index "" char-set:letter 0 0)))
- (pass-if "non-empty - charset - match - start and end index"
- (= 1 (string-index "foo bar" char-set:letter 1 6)))
- (pass-if "non-empty - charset - no match - start and end index"
- (not (string-index "frobnicate" char-set:digit 2 5)))
- (pass-if "empty string - pred"
- (not (string-index "" char-alphabetic?)))
- (pass-if "non-empty - pred - match"
- (= 0 (string-index "foo bar" char-alphabetic?)))
- (pass-if "non-empty - pred - no match"
- (not (string-index "frobnicate" char-numeric?)))
- (pass-if "empty string - pred - start index"
- (not (string-index "" char-alphabetic? 0)))
- (pass-if "non-empty - pred - match - start index"
- (= 1 (string-index "foo bar" char-alphabetic? 1)))
- (pass-if "non-empty - pred - no match - start index"
- (not (string-index "frobnicate" char-numeric? 2)))
- (pass-if "empty string - pred - start and end index"
- (not (string-index "" char-alphabetic? 0 0)))
- (pass-if "non-empty - pred - match - start and end index"
- (= 1 (string-index "foo bar" char-alphabetic? 1 6)))
- (pass-if "non-empty - pred - no match - start and end index"
- (not (string-index "frobnicate" char-numeric? 2 5)))
- ;; in guile 1.6.7 and earlier this resulted in a segv, because
- ;; SCM_MAKE_CHAR didn't cope with "signed char" arguments containing an
- ;; 8-bit value
- (pass-if "8-bit char in string"
- (begin
- (string-index (string (integer->char 200)) char-numeric?)
- #t)))
- (with-test-prefix "string-index-right"
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-index-right "abcde" 123))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-index-right "abcde" "zzz")))
- (pass-if "empty string - char"
- (not (string-index-right "" #\a)))
- (pass-if "non-empty - char - match"
- (= 5 (string-index-right "foo bar" #\a)))
- (pass-if "non-empty - char - no match"
- (not (string-index-right "frobnicate" #\x)))
- (pass-if "empty string - char - start index-right"
- (not (string-index-right "" #\a 0)))
- (pass-if "non-empty - char - match - start index"
- (= 5 (string-index-right "foo bar" #\a 1)))
- (pass-if "non-empty - char - no match - start index"
- (not (string-index-right "frobnicate" #\x 2)))
- (pass-if "empty string - char - start and end index"
- (not (string-index-right "" #\a 0 0)))
- (pass-if "non-empty - char - match - start and end index"
- (= 5 (string-index-right "foo bar" #\a 1 6)))
- (pass-if "non-empty - char - no match - start and end index"
- (not (string-index-right "frobnicate" #\a 2 5)))
- (pass-if "empty string - charset"
- (not (string-index-right "" char-set:letter)))
- (pass-if "non-empty - charset - match"
- (= 6 (string-index-right "foo bar" char-set:letter)))
- (pass-if "non-empty - charset - no match"
- (not (string-index-right "frobnicate" char-set:digit)))
- (pass-if "empty string - charset - start index"
- (not (string-index-right "" char-set:letter 0)))
- (pass-if "non-empty - charset - match - start index"
- (= 6 (string-index-right "foo bar" char-set:letter 1)))
- (pass-if "non-empty - charset - no match - start index"
- (not (string-index-right "frobnicate" char-set:digit 2)))
- (pass-if "empty string - charset - start and end index"
- (not (string-index-right "" char-set:letter 0 0)))
- (pass-if "non-empty - charset - match - start and end index"
- (= 5 (string-index-right "foo bar" char-set:letter 1 6)))
- (pass-if "non-empty - charset - no match - start and end index"
- (not (string-index-right "frobnicate" char-set:digit 2 5)))
- (pass-if "empty string - pred"
- (not (string-index-right "" char-alphabetic?)))
- (pass-if "non-empty - pred - match"
- (= 6 (string-index-right "foo bar" char-alphabetic?)))
- (pass-if "non-empty - pred - no match"
- (not (string-index-right "frobnicate" char-numeric?)))
- (pass-if "empty string - pred - start index"
- (not (string-index-right "" char-alphabetic? 0)))
- (pass-if "non-empty - pred - match - start index"
- (= 6 (string-index-right "foo bar" char-alphabetic? 1)))
- (pass-if "non-empty - pred - no match - start index"
- (not (string-index-right "frobnicate" char-numeric? 2)))
- (pass-if "empty string - pred - start and end index"
- (not (string-index-right "" char-alphabetic? 0 0)))
- (pass-if "non-empty - pred - match - start and end index"
- (= 5 (string-index-right "foo bar" char-alphabetic? 1 6)))
- (pass-if "non-empty - pred - no match - start and end index"
- (not (string-index-right "frobnicate" char-numeric? 2 5))))
- (with-test-prefix "string-skip"
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-skip "abcde" 123))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-skip "abcde" "zzz")))
- (pass-if "empty string - char"
- (not (string-skip "" #\a)))
- (pass-if "non-empty - char - match"
- (= 0 (string-skip "foo bar" #\a)))
- (pass-if "non-empty - char - no match"
- (= 0 (string-skip "frobnicate" #\x)))
- (pass-if "empty string - char - start index"
- (not (string-skip "" #\a 0)))
- (pass-if "non-empty - char - match - start index"
- (= 1 (string-skip "foo bar" #\a 1)))
- (pass-if "non-empty - char - no match - start index"
- (= 2 (string-skip "frobnicate" #\x 2)))
- (pass-if "empty string - char - start and end index"
- (not (string-skip "" #\a 0 0)))
- (pass-if "non-empty - char - match - start and end index"
- (= 1 (string-skip "foo bar" #\a 1 6)))
- (pass-if "non-empty - char - no match - start and end index"
- (= 2 (string-skip "frobnicate" #\a 2 5)))
- (pass-if "empty string - charset"
- (not (string-skip "" char-set:letter)))
- (pass-if "non-empty - charset - match"
- (= 3 (string-skip "foo bar" char-set:letter)))
- (pass-if "non-empty - charset - no match"
- (= 0 (string-skip "frobnicate" char-set:digit)))
- (pass-if "empty string - charset - start index"
- (not (string-skip "" char-set:letter 0)))
- (pass-if "non-empty - charset - match - start index"
- (= 3 (string-skip "foo bar" char-set:letter 1)))
- (pass-if "non-empty - charset - no match - start index"
- (= 2 (string-skip "frobnicate" char-set:digit 2)))
- (pass-if "empty string - charset - start and end index"
- (not (string-skip "" char-set:letter 0 0)))
- (pass-if "non-empty - charset - match - start and end index"
- (= 3 (string-skip "foo bar" char-set:letter 1 6)))
- (pass-if "non-empty - charset - no match - start and end index"
- (= 2 (string-skip "frobnicate" char-set:digit 2 5)))
- (pass-if "empty string - pred"
- (not (string-skip "" char-alphabetic?)))
- (pass-if "non-empty - pred - match"
- (= 3 (string-skip "foo bar" char-alphabetic?)))
- (pass-if "non-empty - pred - no match"
- (= 0 (string-skip "frobnicate" char-numeric?)))
- (pass-if "empty string - pred - start index"
- (not (string-skip "" char-alphabetic? 0)))
- (pass-if "non-empty - pred - match - start index"
- (= 3 (string-skip "foo bar" char-alphabetic? 1)))
- (pass-if "non-empty - pred - no match - start index"
- (= 2 (string-skip "frobnicate" char-numeric? 2)))
- (pass-if "empty string - pred - start and end index"
- (not (string-skip "" char-alphabetic? 0 0)))
- (pass-if "non-empty - pred - match - start and end index"
- (= 3 (string-skip "foo bar" char-alphabetic? 1 6)))
- (pass-if "non-empty - pred - no match - start and end index"
- (= 2 (string-skip "frobnicate" char-numeric? 2 5))))
- (with-test-prefix "string-skip-right"
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-skip-right "abcde" 123))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-skip-right "abcde" "zzz")))
- (pass-if "empty string - char"
- (not (string-skip-right "" #\a)))
- (pass-if "non-empty - char - match"
- (= 6 (string-skip-right "foo bar" #\a)))
- (pass-if "non-empty - char - no match"
- (= 9 (string-skip-right "frobnicate" #\x)))
- (pass-if "empty string - char - start index-right"
- (not (string-skip-right "" #\a 0)))
- (pass-if "non-empty - char - match - start index"
- (= 6 (string-skip-right "foo bar" #\a 1)))
- (pass-if "non-empty - char - no match - start index"
- (= 9 (string-skip-right "frobnicate" #\x 2)))
- (pass-if "empty string - char - start and end index"
- (not (string-skip-right "" #\a 0 0)))
- (pass-if "non-empty - char - match - start and end index"
- (= 4 (string-skip-right "foo bar" #\a 1 6)))
- (pass-if "non-empty - char - no match - start and end index"
- (= 4 (string-skip-right "frobnicate" #\a 2 5)))
- (pass-if "empty string - charset"
- (not (string-skip-right "" char-set:letter)))
- (pass-if "non-empty - charset - match"
- (= 3 (string-skip-right "foo bar" char-set:letter)))
- (pass-if "non-empty - charset - no match"
- (= 9 (string-skip-right "frobnicate" char-set:digit)))
- (pass-if "empty string - charset - start index"
- (not (string-skip-right "" char-set:letter 0)))
- (pass-if "non-empty - charset - match - start index"
- (= 3 (string-skip-right "foo bar" char-set:letter 1)))
- (pass-if "non-empty - charset - no match - start index"
- (= 9 (string-skip-right "frobnicate" char-set:digit 2)))
- (pass-if "empty string - charset - start and end index"
- (not (string-skip-right "" char-set:letter 0 0)))
- (pass-if "non-empty - charset - match - start and end index"
- (= 3 (string-skip-right "foo bar" char-set:letter 1 6)))
- (pass-if "non-empty - charset - no match - start and end index"
- (= 4 (string-skip-right "frobnicate" char-set:digit 2 5)))
- (pass-if "empty string - pred"
- (not (string-skip-right "" char-alphabetic?)))
- (pass-if "non-empty - pred - match"
- (= 3 (string-skip-right "foo bar" char-alphabetic?)))
- (pass-if "non-empty - pred - no match"
- (= 9 (string-skip-right "frobnicate" char-numeric?)))
- (pass-if "empty string - pred - start index"
- (not (string-skip-right "" char-alphabetic? 0)))
- (pass-if "non-empty - pred - match - start index"
- (= 3 (string-skip-right "foo bar" char-alphabetic? 1)))
- (pass-if "non-empty - pred - no match - start index"
- (= 9 (string-skip-right "frobnicate" char-numeric? 2)))
- (pass-if "empty string - pred - start and end index"
- (not (string-skip-right "" char-alphabetic? 0 0)))
- (pass-if "non-empty - pred - match - start and end index"
- (= 3 (string-skip-right "foo bar" char-alphabetic? 1 6)))
- (pass-if "non-empty - pred - no match - start and end index"
- (= 4 (string-skip-right "frobnicate" char-numeric? 2 5))))
- ;;
- ;; string-count
- ;;
- (with-test-prefix "string-count"
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-count "abcde" 123))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-count "abcde" "zzz")))
- (with-test-prefix "char"
- (pass-if (eqv? 0 (string-count "" #\a)))
- (pass-if (eqv? 0 (string-count "-" #\a)))
- (pass-if (eqv? 1 (string-count "a" #\a)))
- (pass-if (eqv? 0 (string-count "--" #\a)))
- (pass-if (eqv? 1 (string-count "a-" #\a)))
- (pass-if (eqv? 1 (string-count "-a" #\a)))
- (pass-if (eqv? 2 (string-count "aa" #\a)))
- (pass-if (eqv? 0 (string-count "---" #\a)))
- (pass-if (eqv? 1 (string-count "-a-" #\a)))
- (pass-if (eqv? 1 (string-count "a--" #\a)))
- (pass-if (eqv? 2 (string-count "aa-" #\a)))
- (pass-if (eqv? 2 (string-count "a-a" #\a)))
- (pass-if (eqv? 3 (string-count "aaa" #\a)))
- (pass-if (eqv? 1 (string-count "--a" #\a)))
- (pass-if (eqv? 2 (string-count "-aa" #\a))))
- (with-test-prefix "charset"
- (pass-if (eqv? 0 (string-count "" char-set:letter)))
- (pass-if (eqv? 0 (string-count "-" char-set:letter)))
- (pass-if (eqv? 1 (string-count "a" char-set:letter)))
- (pass-if (eqv? 0 (string-count "--" char-set:letter)))
- (pass-if (eqv? 1 (string-count "a-" char-set:letter)))
- (pass-if (eqv? 1 (string-count "-a" char-set:letter)))
- (pass-if (eqv? 2 (string-count "aa" char-set:letter)))
- (pass-if (eqv? 0 (string-count "---" char-set:letter)))
- (pass-if (eqv? 1 (string-count "-a-" char-set:letter)))
- (pass-if (eqv? 1 (string-count "a--" char-set:letter)))
- (pass-if (eqv? 2 (string-count "aa-" char-set:letter)))
- (pass-if (eqv? 2 (string-count "a-a" char-set:letter)))
- (pass-if (eqv? 3 (string-count "aaa" char-set:letter)))
- (pass-if (eqv? 1 (string-count "--a" char-set:letter)))
- (pass-if (eqv? 2 (string-count "-aa" char-set:letter))))
- (with-test-prefix "proc"
- (pass-if (eqv? 0 (string-count "" char-alphabetic?)))
- (pass-if (eqv? 0 (string-count "-" char-alphabetic?)))
- (pass-if (eqv? 1 (string-count "a" char-alphabetic?)))
- (pass-if (eqv? 0 (string-count "--" char-alphabetic?)))
- (pass-if (eqv? 1 (string-count "a-" char-alphabetic?)))
- (pass-if (eqv? 1 (string-count "-a" char-alphabetic?)))
- (pass-if (eqv? 2 (string-count "aa" char-alphabetic?)))
- (pass-if (eqv? 0 (string-count "---" char-alphabetic?)))
- (pass-if (eqv? 1 (string-count "-a-" char-alphabetic?)))
- (pass-if (eqv? 1 (string-count "a--" char-alphabetic?)))
- (pass-if (eqv? 2 (string-count "aa-" char-alphabetic?)))
- (pass-if (eqv? 2 (string-count "a-a" char-alphabetic?)))
- (pass-if (eqv? 3 (string-count "aaa" char-alphabetic?)))
- (pass-if (eqv? 1 (string-count "--a" char-alphabetic?)))
- (pass-if (eqv? 2 (string-count "-aa" char-alphabetic?)))))
- (with-test-prefix "string-replace"
- (pass-if "empty string(s), no indices"
- (string=? "" (string-replace "" "")))
- (pass-if "empty string(s), 1 index"
- (string=? "" (string-replace "" "" 0)))
- (pass-if "empty string(s), 2 indices"
- (string=? "" (string-replace "" "" 0 0)))
- (pass-if "empty string(s), 3 indices"
- (string=? "" (string-replace "" "" 0 0 0)))
- (pass-if "empty string(s), 4 indices"
- (string=? "" (string-replace "" "" 0 0 0 0)))
- (pass-if "no indices"
- (string=? "uu" (string-replace "foo bar" "uu")))
- (pass-if "one index"
- (string=? "fuu" (string-replace "foo bar" "uu" 1)))
- (pass-if "two indices"
- (string=? "fuuar" (string-replace "foo bar" "uu" 1 5)))
- (pass-if "three indices"
- (string=? "fuar" (string-replace "foo bar" "uu" 1 5 1)))
- (pass-if "four indices"
- (string=? "fuar" (string-replace "foo bar" "uu" 1 5 1 2))))
- (with-test-prefix "string-tokenize"
- (pass-if "empty string, no char/pred"
- (zero? (length (string-tokenize ""))))
- (pass-if "empty string, charset"
- (zero? (length (string-tokenize "" char-set:punctuation))))
- (pass-if "no char/pred"
- (equal? '("foo" "bar" "!a") (string-tokenize "foo\tbar !a")))
- (pass-if "charset"
- (equal? '("foo" "bar" "!a") (string-tokenize "foo\tbar !a"
- char-set:graphic)))
- (pass-if "charset, start index"
- (equal? '("oo" "bar" "!a") (string-tokenize "foo\tbar !a"
- char-set:graphic 1)))
- (pass-if "charset, start and end index"
- (equal? '("oo" "bar" "!") (string-tokenize "foo\tbar !a"
- char-set:graphic 1 9))))
- ;;;
- ;;; string-filter
- ;;;
- (with-test-prefix "string-filter"
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-filter 123 "abcde"))
- ;; Have to comment out this test for now, given that it triggers the
- ;; deprecation warning, even as the test passes.
- #;
- (pass-if-exception "string" exception:wrong-type-arg
- (string-filter "zzz" "abcde")))
- (pass-if "empty string, char"
- (string=? "" (string-filter #\. "")))
- (pass-if "empty string, charset"
- (string=? "" (string-filter char-set:punctuation "")))
- (pass-if "empty string, pred"
- (string=? "" (string-filter char-alphabetic? "")))
- (pass-if "char"
- (string=? "..." (string-filter #\. ".foo.bar.")))
- (pass-if "charset"
- (string=? "..." (string-filter char-set:punctuation ".foo.bar.")))
- (pass-if "pred"
- (string=? "foobar" (string-filter char-alphabetic? ".foo.bar.")))
- (pass-if "char, start index"
- (string=? ".." (string-filter #\. ".foo.bar." 2)))
- (pass-if "charset, start index"
- (string=? ".." (string-filter char-set:punctuation ".foo.bar." 2)))
- (pass-if "pred, start index"
- (string=? "oobar" (string-filter char-alphabetic? ".foo.bar." 2)))
- (pass-if "char, start and end index"
- (string=? "" (string-filter #\. ".foo.bar." 2 4)))
- (pass-if "charset, start and end index"
- (string=? "" (string-filter char-set:punctuation ".foo.bar." 2 4)))
- (pass-if "pred, start and end index"
- (string=? "oo" (string-filter char-alphabetic? ".foo.bar." 2 4)))
- (with-test-prefix "char"
- (pass-if (equal? "x" (string-filter #\x "x")))
- (pass-if (equal? "xx" (string-filter #\x "xx")))
- (pass-if (equal? "xx" (string-filter #\x "xyx")))
- (pass-if (equal? "x" (string-filter #\x "xyyy")))
- (pass-if (equal? "x" (string-filter #\x "yyyx")))
- (pass-if (equal? "xx" (string-filter #\x "xxx" 1)))
- (pass-if (equal? "xx" (string-filter #\x "xxx" 0 2)))
- (pass-if (equal? "x" (string-filter #\x "xyx" 1)))
- (pass-if (equal? "x" (string-filter #\x "yxx" 0 2)))
- ;; leading and trailing removals
- (pass-if (string=? "" (string-filter #\x ".")))
- (pass-if (string=? "" (string-filter #\x "..")))
- (pass-if (string=? "" (string-filter #\x "...")))
- (pass-if (string=? "x" (string-filter #\x ".x")))
- (pass-if (string=? "x" (string-filter #\x "..x")))
- (pass-if (string=? "x" (string-filter #\x "...x")))
- (pass-if (string=? "x" (string-filter #\x "x.")))
- (pass-if (string=? "x" (string-filter #\x "x..")))
- (pass-if (string=? "x" (string-filter #\x "x...")))
- (pass-if (string=? "x" (string-filter #\x "...x..."))))
- (with-test-prefix "charset"
- (let ((charset (char-set #\x #\y)))
- (pass-if (equal? "x" (string-filter charset "x")))
- (pass-if (equal? "xx" (string-filter charset "xx")))
- (pass-if (equal? "xy" (string-filter charset "xy")))
- (pass-if (equal? "x" (string-filter charset "xaaa")))
- (pass-if (equal? "y" (string-filter charset "aaay")))
- (pass-if (equal? "yx" (string-filter charset "xyx" 1)))
- (pass-if (equal? "xy" (string-filter charset "xyx" 0 2)))
- (pass-if (equal? "x" (string-filter charset "xax" 1)))
- (pass-if (equal? "x" (string-filter charset "axx" 0 2))))
- ;; leading and trailing removals
- (pass-if (string=? "" (string-filter char-set:letter ".")))
- (pass-if (string=? "" (string-filter char-set:letter "..")))
- (pass-if (string=? "" (string-filter char-set:letter "...")))
- (pass-if (string=? "x" (string-filter char-set:letter ".x")))
- (pass-if (string=? "x" (string-filter char-set:letter "..x")))
- (pass-if (string=? "x" (string-filter char-set:letter "...x")))
- (pass-if (string=? "x" (string-filter char-set:letter "x.")))
- (pass-if (string=? "x" (string-filter char-set:letter "x..")))
- (pass-if (string=? "x" (string-filter char-set:letter "x...")))
- (pass-if (string=? "x" (string-filter char-set:letter "...x...")))))
- ;;;
- ;;; string-delete
- ;;;
- (with-test-prefix "string-delete"
- (with-test-prefix "bad char_pred"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-delete 123 "abcde"))
- ;; Like string-filter, commenting out this test.
- #;
- (pass-if-exception "string" exception:wrong-type-arg
- (string-delete "zzz" "abcde")))
- (pass-if "empty string, char"
- (string=? "" (string-delete #\. "")))
- (pass-if "empty string, charset"
- (string=? "" (string-delete char-set:punctuation "")))
- (pass-if "empty string, pred"
- (string=? "" (string-delete char-alphabetic? "")))
- (pass-if "char"
- (string=? "foobar" (string-delete #\. ".foo.bar.")))
- (pass-if "charset"
- (string=? "foobar" (string-delete char-set:punctuation ".foo.bar.")))
- (pass-if "pred"
- (string=? "..." (string-delete char-alphabetic? ".foo.bar.")))
- (pass-if "char, start index"
- (string=? "oobar" (string-delete #\. ".foo.bar." 2)))
- (pass-if "charset, start index"
- (string=? "oobar" (string-delete char-set:punctuation ".foo.bar." 2)))
- (pass-if "pred, start index"
- (string=? ".." (string-delete char-alphabetic? ".foo.bar." 2)))
- (pass-if "char, start and end index"
- (string=? "oo" (string-delete #\. ".foo.bar." 2 4)))
- (pass-if "charset, start and end index"
- (string=? "oo" (string-delete char-set:punctuation ".foo.bar." 2 4)))
- (pass-if "pred, start and end index"
- (string=? "" (string-delete char-alphabetic? ".foo.bar." 2 4)))
- ;; leading and trailing removals
- (pass-if (string=? "" (string-delete #\. ".")))
- (pass-if (string=? "" (string-delete #\. "..")))
- (pass-if (string=? "" (string-delete #\. "...")))
- (pass-if (string=? "x" (string-delete #\. ".x")))
- (pass-if (string=? "x" (string-delete #\. "..x")))
- (pass-if (string=? "x" (string-delete #\. "...x")))
- (pass-if (string=? "x" (string-delete #\. "x.")))
- (pass-if (string=? "x" (string-delete #\. "x..")))
- (pass-if (string=? "x" (string-delete #\. "x...")))
- (pass-if (string=? "x" (string-delete #\. "...x...")))
- ;; leading and trailing removals
- (pass-if (string=? "" (string-delete char-set:punctuation ".")))
- (pass-if (string=? "" (string-delete char-set:punctuation "..")))
- (pass-if (string=? "" (string-delete char-set:punctuation "...")))
- (pass-if (string=? "x" (string-delete char-set:punctuation ".x")))
- (pass-if (string=? "x" (string-delete char-set:punctuation "..x")))
- (pass-if (string=? "x" (string-delete char-set:punctuation "...x")))
- (pass-if (string=? "x" (string-delete char-set:punctuation "x.")))
- (pass-if (string=? "x" (string-delete char-set:punctuation "x..")))
- (pass-if (string=? "x" (string-delete char-set:punctuation "x...")))
- (pass-if (string=? "x" (string-delete char-set:punctuation "...x..."))))
- (with-test-prefix "string-map"
- (with-test-prefix "bad proc"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-map 123 "abcde"))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-map "zzz" "abcde")))
- (pass-if "constant"
- (string=? "xxx" (string-map (lambda (c) #\x) "foo")))
- (pass-if "identity"
- (string=? "foo" (string-map identity "foo")))
- (pass-if "upcase"
- (string=? "FOO" (string-map char-upcase "foo"))))
- (with-test-prefix "string-map!"
- (with-test-prefix "bad proc"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-map 123 "abcde"))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-map "zzz" "abcde")))
- (pass-if "constant"
- (let ((str (string-copy "foo")))
- (string-map! (lambda (c) #\x) str)
- (string=? str "xxx")))
- (pass-if "identity"
- (let ((str (string-copy "foo")))
- (string-map! identity str)
- (string=? str "foo")))
- (pass-if "upcase"
- (let ((str (string-copy "foo")))
- (string-map! char-upcase str)
- (string=? str "FOO"))))
- (with-test-prefix "string-for-each"
- (with-test-prefix "bad proc"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-for-each 123 "abcde"))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-for-each "zzz" "abcde")))
- (pass-if "copy"
- (let* ((foo "foo")
- (bar (make-string (string-length foo)))
- (i 0))
- (string-for-each
- (lambda (c) (string-set! bar i c) (set! i (1+ i))) foo)
- (string=? foo bar))))
- (with-test-prefix "string-for-each-index"
- (with-test-prefix "bad proc"
- (pass-if-exception "integer" exception:wrong-type-arg
- (string-for-each-index 123 "abcde"))
- (pass-if-exception "string" exception:wrong-type-arg
- (string-for-each-index "zzz" "abcde")))
- (pass-if "index"
- (let* ((foo "foo")
- (bar (make-string (string-length foo))))
- (string-for-each-index
- (lambda (i) (string-set! bar i (string-ref foo i))) foo)
- (string=? foo bar))))
|