1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

More tests for strings

* test-suite/tests/vectors.test: test make-vector and interactions between
  strings and vectors

* test-suite/tests/strings.test: test string-null?, string? and backslash
  escapes

* test-suite/tests/srfi-13.test: test null input strings in string-any and
  string-every
This commit is contained in:
Michael Gran 2009-09-20 20:58:08 -07:00
parent e5f5113c21
commit fee95176df
3 changed files with 73 additions and 2 deletions

View file

@ -40,6 +40,12 @@
(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
@ -259,6 +265,12 @@
(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

View file

@ -177,7 +177,7 @@
(let ((s "\U000040"))
(not (assq-ref (%string-dump s) 'stringbuf-wide))))))
(with-test-prefix "hex escapes"
(with-test-prefix "escapes"
(pass-if-exception "non-hex char in two-digit hex-escape"
exception:illegal-escape
@ -216,7 +216,44 @@
(integer->char #x010300)))
(pass-if "escaped characters match non-escaped ASCII characters"
(string=? "ABC" "\x41\u0042\U000043")))
(string=? "ABC" "\x41\u0042\U000043"))
(pass-if "R5RS backslash escapes"
(string=? "\"\\" (string #\" #\\)))
(pass-if "Guile extensions backslash escapes"
(string=? "\0\a\f\n\r\t\v"
(apply string (map integer->char '(0 7 12 10 13 9 11))))))
;;
;; string?
;;
(with-test-prefix "string?"
(pass-if "string"
(string? "abc"))
(pass-if "symbol"
(not (string? 'abc))))
;;
;; string-null?
;;
(with-test-prefix "string-null?"
(pass-if "null string"
(string-null? ""))
(pass-if "non-null string"
(not (string-null? "a")))
(pass-if "respects \\0"
(not (string-null? "\0")))
(pass-if-exception "symbol"
exception:wrong-type-arg
(string-null? 'a)))
;;
;; string=?

View file

@ -36,7 +36,29 @@
(pass-if "simple vector"
(equal? '(1 2 3) (vector->list #(1 2 3))))
(pass-if "string vector 1"
(equal? '("abc" "def" "ghi") (vector->list #("abc" "def" "ghi"))))
(pass-if "string-vector 2"
(equal? '("abc\u0100" "def\u0101" "ghi\u0102")
(vector->list #("abc\u0100" "def\u0101" "ghi\u0102"))))
(pass-if "shared array"
(let ((b (make-shared-array #(1) (lambda (x) '(0)) 2)))
(equal? b (list->vector (vector->list b))))))
(with-test-prefix "make-vector"
(pass-if "null"
(equal? #() (make-vector 0)))
(pass-if "fill with num"
(equal? #(1 1 1) (make-vector 3 1)))
(pass-if "fill with string"
(equal? #("abc" "abc" "abc") (make-vector 3 "abc")))
(pass-if "fill with string 2"
(equal? #("ab\u0100" "ab\u0100" "ab\u0100")
(make-vector 3 "ab\u0100"))))