mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-11 16:20:19 +02:00
(string-any, string-every): Exercise char and charset predicate cases.
This commit is contained in:
parent
313f062011
commit
509a2a8e59
1 changed files with 190 additions and 42 deletions
|
@ -28,70 +28,218 @@
|
||||||
(define exception:strict-infix-grammar
|
(define exception:strict-infix-grammar
|
||||||
(cons 'misc-error "^strict-infix"))
|
(cons 'misc-error "^strict-infix"))
|
||||||
|
|
||||||
|
;;;
|
||||||
|
;;; string-any
|
||||||
|
;;;
|
||||||
|
|
||||||
(with-test-prefix "string-any"
|
(with-test-prefix "string-any"
|
||||||
|
|
||||||
(pass-if "no match"
|
(with-test-prefix "bad char_pred"
|
||||||
(not (string-any char-upper-case? "abcde")))
|
|
||||||
|
|
||||||
(pass-if "one match"
|
(pass-if-exception "integer" exception:wrong-type-arg
|
||||||
(string-any char-upper-case? "abCde"))
|
(string-any 123 "abcde"))
|
||||||
|
|
||||||
(pass-if "more than one match"
|
(pass-if-exception "string" exception:wrong-type-arg
|
||||||
(string-any char-upper-case? "abCDE"))
|
(string-any "zzz" "abcde")))
|
||||||
|
|
||||||
(pass-if "no match, start index"
|
(with-test-prefix "char"
|
||||||
(not (string-any char-upper-case? "Abcde" 1)))
|
|
||||||
|
|
||||||
(pass-if "one match, start index"
|
(pass-if "no match"
|
||||||
(string-any char-upper-case? "abCde" 1))
|
(not (string-any #\C "abcde")))
|
||||||
|
|
||||||
(pass-if "more than one match, start index"
|
(pass-if "one match"
|
||||||
(string-any char-upper-case? "abCDE" 1))
|
(string-any #\C "abCde"))
|
||||||
|
|
||||||
(pass-if "no match, start and end index"
|
(pass-if "more than one match"
|
||||||
(not (string-any char-upper-case? "AbcdE" 1 4)))
|
(string-any #\X "abXXX"))
|
||||||
|
|
||||||
(pass-if "one match, start and end index"
|
(pass-if "no match, start index"
|
||||||
(string-any char-upper-case? "abCde" 1 4))
|
(not (string-any #\A "Abcde" 1)))
|
||||||
|
|
||||||
(pass-if "more than one match, start and end index"
|
(pass-if "one match, start index"
|
||||||
(string-any char-upper-case? "abCDE" 1 4)))
|
(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-every
|
||||||
|
;;;
|
||||||
|
|
||||||
(with-test-prefix "string-every"
|
(with-test-prefix "string-every"
|
||||||
|
|
||||||
;; in guile 1.6.4 and earlier string-every incorrectly returned #f on an
|
(with-test-prefix "char"
|
||||||
;; 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"
|
(pass-if "empty string"
|
||||||
(not (string-every char-upper-case? "abcde")))
|
(string-every #\X ""))
|
||||||
|
|
||||||
(pass-if "not all match"
|
(pass-if "empty substring"
|
||||||
(not (string-every char-upper-case? "abCDE")))
|
(string-every #\X "abc" 1 1))
|
||||||
|
|
||||||
(pass-if "all match"
|
(pass-if "no match at all"
|
||||||
(string-every char-upper-case? "ABCDE"))
|
(not (string-every #\X "abcde")))
|
||||||
|
|
||||||
(pass-if "no match at all, start index"
|
(pass-if "not all match"
|
||||||
(not (string-every char-upper-case? "Abcde" 1)))
|
(not (string-every #\X "abXXX")))
|
||||||
|
|
||||||
(pass-if "not all match, start index"
|
(pass-if "all match"
|
||||||
(not (string-every char-upper-case? "ABcde" 1)))
|
(string-every #\X "XXXXX"))
|
||||||
|
|
||||||
(pass-if "all match, start index"
|
(pass-if "no match at all, start index"
|
||||||
(string-every char-upper-case? "aBCDE" 1))
|
(not (string-every #\X "Xbcde" 1)))
|
||||||
|
|
||||||
(pass-if "no match at all, start and end index"
|
(pass-if "not all match, start index"
|
||||||
(not (string-every char-upper-case? "AbcdE" 1 4)))
|
(not (string-every #\X "XXcde" 1)))
|
||||||
|
|
||||||
(pass-if "not all match, start and end index"
|
(pass-if "all match, start index"
|
||||||
(not (string-every char-upper-case? "ABcde" 1 4)))
|
(string-every #\X "aXXXX" 1))
|
||||||
|
|
||||||
(pass-if "all match, start and end index"
|
(pass-if "no match at all, start and end index"
|
||||||
(string-every char-upper-case? "aBCDe" 1 4)))
|
(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 "string-tabulate"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue