source: trunk/source/tests/ansi-tests/string-downcase.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 11 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 4.4 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Mon Sep 30 21:41:59 2002
4;;;; Contains: Tests for STRING-DOWNCASE
5
6(in-package :cl-test)
7
8(deftest string-downcase.1
9  (let ((s "A"))
10    (values (string-downcase s) s))
11  "a" "A")
12
13(deftest string-downcase.2
14  (let ((s "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))
15    (values (string-downcase s) s))
16  "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
17  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
18
19(deftest string-downcase.3
20  (let ((s "0123456789!@#$%^&*()_-+=|\\{}[]:\";'<>?,./ "))
21    (values (string-downcase s) s))
22  "0123456789!@#$%^&*()_-+=|\\{}[]:\";'<>?,./ "
23  "0123456789!@#$%^&*()_-+=|\\{}[]:\";'<>?,./ ")
24
25(deftest string-downcase.4
26  (string-downcase #\A)
27  "a")
28
29(deftest string-downcase.5
30  (let ((sym '|A|))
31    (values (string-downcase sym) sym))
32  "a" |A|)
33
34(deftest string-downcase.6
35  (let ((s (make-array 6 :element-type 'character
36                       :initial-contents '(#\A #\B #\C #\D #\E #\F))))
37    (values (string-downcase s) s))
38  "abcdef"
39  "ABCDEF")
40
41(deftest string-downcase.7
42  (let ((s (make-array 6 :element-type 'standard-char
43                       :initial-contents '(#\A #\B #\7 #\D #\E #\F))))
44    (values (string-downcase s) s))
45  "ab7def"
46  "AB7DEF")
47
48;; Tests with :start, :end
49
50(deftest string-downcase.8
51  (let ((s "ABCDEF"))
52    (values
53     (loop for i from 0 to 6
54           collect (string-downcase s :start i))
55     s))
56  ("abcdef" "Abcdef" "ABcdef" "ABCdef" "ABCDef" "ABCDEf" "ABCDEF")
57  "ABCDEF")
58
59(deftest string-downcase.9
60  (let ((s "ABCDEF"))
61    (values
62     (loop for i from 0 to 6
63           collect (string-downcase s :start i :end nil))
64     s))
65  ("abcdef" "Abcdef" "ABcdef" "ABCdef" "ABCDef" "ABCDEf" "ABCDEF")
66  "ABCDEF")
67
68(deftest string-downcase.10
69  (let ((s "ABCDE"))
70    (values
71     (loop for i from 0 to 4
72           collect (loop for j from i to 5
73                         collect (string-invertcase
74                                  (string-downcase s :start i :end j))))
75     s))
76  (("abcde" "Abcde" "ABcde" "ABCde" "ABCDe" "ABCDE")
77   ("abcde" "aBcde" "aBCde" "aBCDe" "aBCDE")
78   ("abcde" "abCde" "abCDe" "abCDE")
79   ("abcde" "abcDe" "abcDE")
80   ("abcde" "abcdE"))
81  "ABCDE")
82
83(deftest string-downcase.11
84  :notes (:nil-vectors-are-strings)
85  (string-downcase (make-array '(0) :element-type nil))
86  "")
87
88(deftest string-downcase.12
89  (loop for type in '(standard-char base-char character)
90        for s = (make-array '(10) :element-type type
91                            :fill-pointer 5
92                            :initial-contents "aB0cDefGHi")
93        collect (list s (string-downcase s)))
94  (("aB0cD" "ab0cd") ("aB0cD" "ab0cd") ("aB0cD" "ab0cd")))
95
96
97(deftest string-downcase.13
98  (loop for type in '(standard-char base-char character)
99        for s0 = (make-array '(10) :element-type type
100                             :initial-contents "zZaB0cDefG")
101        for s = (make-array '(5) :element-type type
102                            :displaced-to s0
103                            :displaced-index-offset 2)
104        collect (list s (string-downcase s)))
105  (("aB0cD" "ab0cd") ("aB0cD" "ab0cd") ("aB0cD" "ab0cd")))
106
107(deftest string-downcase.14
108  (loop for type in '(standard-char base-char character)
109        for s = (make-array '(5) :element-type type
110                            :adjustable t
111                            :initial-contents "aB0cD")
112        collect (list s (string-downcase s)))
113  (("aB0cD" "ab0cd") ("aB0cD" "ab0cd") ("aB0cD" "ab0cd")))
114
115;;; Order of evaluation tests
116
117(deftest string-downcase.order.1
118  (let ((i 0) a b c (s (copy-seq "ABCDEF")))
119    (values
120     (string-downcase
121      (progn (setf a (incf i)) s)
122      :start (progn (setf b (incf i)) 1)
123      :end   (progn (setf c (incf i)) 4))
124     i a b c))
125  "AbcdEF" 3 1 2 3)
126
127(deftest string-downcase.order.2
128  (let ((i 0) a b c (s (copy-seq "ABCDEF")))
129    (values
130     (string-downcase
131      (progn (setf a (incf i)) s)
132      :end   (progn (setf b (incf i)) 4)
133      :start (progn (setf c (incf i)) 1))
134     i a b c))
135  "AbcdEF" 3 1 2 3)
136
137(def-fold-test string-downcase.fold.1 (string-downcase "ABCDE"))
138
139;;; Error cases
140
141(deftest string-downcase.error.1
142  (signals-error (string-downcase) program-error)
143  t)
144
145(deftest string-downcase.error.2
146  (signals-error (string-downcase (copy-seq "abc") :bad t) program-error)
147  t)
148
149(deftest string-downcase.error.3
150  (signals-error (string-downcase (copy-seq "abc") :start) program-error)
151  t)
152
153(deftest string-downcase.error.4
154  (signals-error (string-downcase (copy-seq "abc") :bad t
155                                      :allow-other-keys nil) program-error)
156  t)
157
158(deftest string-downcase.error.5
159  (signals-error (string-downcase (copy-seq "abc") :end) program-error)
160  t)
161
162(deftest string-downcase.error.6
163  (signals-error (string-downcase (copy-seq "abc") 1 2) program-error)
164  t)
Note: See TracBrowser for help on using the repository browser.