string-downcase.lsp 4.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Sep 30 21:41:59 2002
;;;; Contains: Tests for STRING-DOWNCASE

(in-package :cl-test)

(deftest string-downcase.1
  (let ((s "A"))
    (values (string-downcase s) s))
  "a" "A")

(deftest string-downcase.2
  (let ((s "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))
    (values (string-downcase s) s))
  "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")

(deftest string-downcase.3
  (let ((s "0123456789!@#$%^&*()_-+=|\\{}[]:\";'<>?,./ "))
    (values (string-downcase s) s))
  "0123456789!@#$%^&*()_-+=|\\{}[]:\";'<>?,./ "
  "0123456789!@#$%^&*()_-+=|\\{}[]:\";'<>?,./ ")

(deftest string-downcase.4
  (string-downcase #\A)
  "a")

(deftest string-downcase.5
  (let ((sym '|A|))
    (values (string-downcase sym) sym))
  "a" |A|)

(deftest string-downcase.6
  (let ((s (make-array 6 :element-type 'character
sds's avatar
sds committed
36
                       :initial-contents '(#\A #\B #\C #\D #\E #\F))))
37 38 39 40 41 42
    (values (string-downcase s) s))
  "abcdef"
  "ABCDEF")

(deftest string-downcase.7
  (let ((s (make-array 6 :element-type 'standard-char
sds's avatar
sds committed
43
                       :initial-contents '(#\A #\B #\7 #\D #\E #\F))))
44 45 46 47 48 49 50 51 52 53
    (values (string-downcase s) s))
  "ab7def"
  "AB7DEF")

;; Tests with :start, :end

(deftest string-downcase.8
  (let ((s "ABCDEF"))
    (values
     (loop for i from 0 to 6
sds's avatar
sds committed
54
           collect (string-downcase s :start i))
55 56 57 58 59 60 61 62
     s))
  ("abcdef" "Abcdef" "ABcdef" "ABCdef" "ABCDef" "ABCDEf" "ABCDEF")
  "ABCDEF")

(deftest string-downcase.9
  (let ((s "ABCDEF"))
    (values
     (loop for i from 0 to 6
sds's avatar
sds committed
63
           collect (string-downcase s :start i :end nil))
64 65 66 67 68 69 70 71
     s))
  ("abcdef" "Abcdef" "ABcdef" "ABCdef" "ABCDef" "ABCDEf" "ABCDEF")
  "ABCDEF")

(deftest string-downcase.10
  (let ((s "ABCDE"))
    (values
     (loop for i from 0 to 4
sds's avatar
sds committed
72 73 74
           collect (loop for j from i to 5
                         collect (string-invertcase
                                  (string-downcase s :start i :end j))))
75 76 77 78 79 80 81 82
     s))
  (("abcde" "Abcde" "ABcde" "ABCde" "ABCDe" "ABCDE")
   ("abcde" "aBcde" "aBCde" "aBCDe" "aBCDE")
   ("abcde" "abCde" "abCDe" "abCDE")
   ("abcde" "abcDe" "abcDE")
   ("abcde" "abcdE"))
  "ABCDE")

83
(deftest string-downcase.11
84
  :notes (:nil-vectors-are-strings)
85 86 87
  (string-downcase (make-array '(0) :element-type nil))
  "")

88 89
(deftest string-downcase.12
  (loop for type in '(standard-char base-char character)
sds's avatar
sds committed
90 91 92 93
        for s = (make-array '(10) :element-type type
                            :fill-pointer 5
                            :initial-contents "aB0cDefGHi")
        collect (list s (string-downcase s)))
94 95 96 97 98
  (("aB0cD" "ab0cd") ("aB0cD" "ab0cd") ("aB0cD" "ab0cd")))


(deftest string-downcase.13
  (loop for type in '(standard-char base-char character)
sds's avatar
sds committed
99 100 101 102 103 104
        for s0 = (make-array '(10) :element-type type
                             :initial-contents "zZaB0cDefG")
        for s = (make-array '(5) :element-type type
                            :displaced-to s0
                            :displaced-index-offset 2)
        collect (list s (string-downcase s)))
105 106 107 108
  (("aB0cD" "ab0cd") ("aB0cD" "ab0cd") ("aB0cD" "ab0cd")))

(deftest string-downcase.14
  (loop for type in '(standard-char base-char character)
sds's avatar
sds committed
109 110 111 112
        for s = (make-array '(5) :element-type type
                            :adjustable t
                            :initial-contents "aB0cD")
        collect (list s (string-downcase s)))
113 114 115 116
  (("aB0cD" "ab0cd") ("aB0cD" "ab0cd") ("aB0cD" "ab0cd")))

;;; Order of evaluation tests

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
(deftest string-downcase.order.1
  (let ((i 0) a b c (s (copy-seq "ABCDEF")))
    (values
     (string-downcase
      (progn (setf a (incf i)) s)
      :start (progn (setf b (incf i)) 1)
      :end   (progn (setf c (incf i)) 4))
     i a b c))
  "AbcdEF" 3 1 2 3)

(deftest string-downcase.order.2
  (let ((i 0) a b c (s (copy-seq "ABCDEF")))
    (values
     (string-downcase
      (progn (setf a (incf i)) s)
      :end   (progn (setf b (incf i)) 4)
      :start (progn (setf c (incf i)) 1))
     i a b c))
  "AbcdEF" 3 1 2 3)

pfdietz's avatar
pfdietz committed
137 138
(def-fold-test string-downcase.fold.1 (string-downcase "ABCDE"))

139 140 141
;;; Error cases

(deftest string-downcase.error.1
142 143
  (signals-error (string-downcase) program-error)
  t)
144 145

(deftest string-downcase.error.2
146 147
  (signals-error (string-downcase (copy-seq "abc") :bad t) program-error)
  t)
148 149

(deftest string-downcase.error.3
150 151
  (signals-error (string-downcase (copy-seq "abc") :start) program-error)
  t)
152 153

(deftest string-downcase.error.4
154
  (signals-error (string-downcase (copy-seq "abc") :bad t
sds's avatar
sds committed
155
                                      :allow-other-keys nil) program-error)
156
  t)
157 158

(deftest string-downcase.error.5
159 160
  (signals-error (string-downcase (copy-seq "abc") :end) program-error)
  t)
161 162

(deftest string-downcase.error.6
163 164
  (signals-error (string-downcase (copy-seq "abc") 1 2) program-error)
  t)