0.8.16.11: Partial fix for #318 & more incompatible changes
[sbcl.git] / tests / string.pure.lisp
index c44ffb3..702dfee 100644 (file)
@@ -13,6 +13,7 @@
 
 (in-package "CL-USER")
 
+;;; basic non-destructive case operations
 (assert (string= (string-upcase     "This is a test.") "THIS IS A TEST."))
 (assert (string= (string-downcase   "This is a test.") "this is a test."))
 (assert (string= (string-capitalize "This is a test.") "This Is A Test."))
                 "Is this 900-sex-hott, please?"))
 (assert (string= (string-capitalize "Is this 900-Sex-hott, please?")
                 "Is This 900-Sex-Hott, Please?"))
+
+;;; The non-destructive case operations accept string designators, not
+;;; just strings.
+(assert (string= (string-upcase '|String designator|) "STRING DESIGNATOR"))
+(assert (string= (string-downcase #\S) "s"))
+(assert (string= (string-downcase #\.) "."))
+(assert (string= (string-capitalize 'ya-str-desig :end 5) "Ya-StR-DESIG"))
+
+;;; basic destructive case operations
+(let ((nstring (make-array 5 :element-type 'character :fill-pointer 0)))
+  (vector-push-extend #\c nstring)
+  (vector-push-extend #\a nstring)
+  (vector-push-extend #\t nstring)
+  (nstring-upcase nstring)
+  (assert (string= nstring "CAT"))
+  (setf (fill-pointer nstring) 2)
+  (nstring-downcase nstring :start 1)
+  (setf (fill-pointer nstring) 3)
+  (assert (string= nstring "CaT"))
+  (nstring-capitalize nstring)
+  (assert (string= nstring "Cat")))
+
+;;; (VECTOR NIL)s are strings.  Tests for that and issues uncovered in
+;;; the process.
+(assert (typep (make-array 1 :element-type nil) 'string))
+(assert (not (typep (make-array 2 :element-type nil) 'base-string)))
+(assert (typep (make-string 3 :element-type nil) 'simple-string))
+(assert (not (typep (make-string 4 :element-type nil) 'simple-base-string)))
+
+(assert (subtypep (class-of (make-array 1 :element-type nil))
+                 (find-class 'string)))
+(assert (subtypep (class-of (make-array 2 :element-type nil :fill-pointer 1))
+                 (find-class 'string)))
+
+(assert (string= "" (make-array 0 :element-type nil)))
+(assert (string/= "a" (make-array 0 :element-type nil)))
+(assert (string= "" (make-array 5 :element-type nil :fill-pointer 0)))
+
+(assert (= (sxhash "")
+          (sxhash (make-array 0 :element-type nil))
+          (sxhash (make-array 5 :element-type nil :fill-pointer 0))
+          (sxhash (make-string 0 :element-type nil))))
+(assert (subtypep (type-of (make-array 2 :element-type nil)) 'simple-string))
+(assert (subtypep (type-of (make-array 4 :element-type nil :fill-pointer t))
+                 'string))
+
+(assert (eq (intern "") (intern (make-array 0 :element-type nil))))
+(assert (eq (intern "")
+           (intern (make-array 5 :element-type nil :fill-pointer 0))))
+
+(assert (raises-error? (make-string 5 :element-type t)))
+(assert (raises-error? (let () (make-string 5 :element-type t))))