source: trunk/source/tests/ansi-tests/string-capitalize.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.3 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Thu Oct  3 20:08:26 2002
4;;;; Contains: Tests for STRING-CAPITALIZE
5
6(in-package :cl-test)
7
8(deftest string-capitalize.1
9  (let ((s "abCd"))
10    (values (string-capitalize s) s))
11  "Abcd"
12  "abCd")
13
14
15(deftest string-capitalize.2
16  (let ((s "0adA2Cdd3wXy"))
17    (values (string-capitalize s) s))
18  "0ada2cdd3wxy"
19  "0adA2Cdd3wXy")
20
21(deftest string-capitalize.3
22  (let ((s "1a"))
23    (values (string-capitalize s) s))
24  "1a"
25  "1a")
26
27(deftest string-capitalize.4
28  (let ((s "a1a"))
29    (values (string-capitalize s) s))
30  "A1a"
31  "a1a")
32
33(deftest string-capitalize.5
34  (let ((s #\a))
35    (values (string-capitalize s) s))
36  "A"
37  #\a)
38
39(deftest string-capitalize.6
40  (let ((s '|abcDe|))
41    (values (string-capitalize s) (symbol-name s)))
42  "Abcde"
43  "abcDe")
44
45(deftest string-capitalize.7
46  (let ((s "ABCDEF"))
47    (values
48     (loop for i from 0 to 5
49           collect (string-capitalize s :start i))
50     s))
51  ("Abcdef" "ABcdef" "ABCdef" "ABCDef" "ABCDEf" "ABCDEF")
52  "ABCDEF")
53
54(deftest string-capitalize.8
55  (let ((s "ABCDEF"))
56    (values
57     (loop for i from 0 to 5
58           collect (string-capitalize s :start i :end nil))
59     s))
60  ("Abcdef" "ABcdef" "ABCdef" "ABCDef" "ABCDEf" "ABCDEF")
61  "ABCDEF")
62
63(deftest string-capitalize.9
64  (let ((s "ABCDEF"))
65    (values
66     (loop for i from 0 to 6
67           collect (string-capitalize s :end i))
68     s))
69  ("ABCDEF" "ABCDEF" "AbCDEF" "AbcDEF" "AbcdEF" "AbcdeF" "Abcdef")
70  "ABCDEF")
71
72(deftest string-capitalize.10
73  (let ((s "ABCDEF"))
74    (values
75     (loop for i from 0 to 5
76           collect (loop for j from i to 6
77                         collect (string-capitalize s :start i :end j)))
78     s))
79  (("ABCDEF" "ABCDEF" "AbCDEF" "AbcDEF" "AbcdEF" "AbcdeF" "Abcdef")
80   ("ABCDEF" "ABCDEF" "ABcDEF" "ABcdEF" "ABcdeF" "ABcdef")
81   ("ABCDEF" "ABCDEF" "ABCdEF" "ABCdeF" "ABCdef")
82   ("ABCDEF" "ABCDEF" "ABCDeF" "ABCDef")
83   ("ABCDEF" "ABCDEF" "ABCDEf")
84   ("ABCDEF" "ABCDEF"))
85  "ABCDEF")
86
87(deftest string-capitalize.11
88  :notes (:nil-vectors-are-strings)
89  (string-capitalize (make-array '(0) :element-type nil))
90  "")
91
92(deftest string-capitalize.12
93  (loop for type in '(standard-char base-char character)
94        for s = (make-array '(10) :element-type type
95                            :fill-pointer 5
96                            :initial-contents "aB0cDefGHi")
97        collect (list s (string-capitalize s)))
98  (("aB0cD" "Ab0cd") ("aB0cD" "Ab0cd") ("aB0cD" "Ab0cd")))
99
100
101(deftest string-capitalize.13
102  (loop for type in '(standard-char base-char character)
103        for s0 = (make-array '(10) :element-type type
104                             :initial-contents "zZaB0cDefG")
105        for s = (make-array '(5) :element-type type
106                            :displaced-to s0
107                            :displaced-index-offset 2)
108        collect (list s (string-capitalize s)))
109  (("aB0cD" "Ab0cd") ("aB0cD" "Ab0cd") ("aB0cD" "Ab0cd")))
110
111(deftest string-capitalize.14
112  (loop for type in '(standard-char base-char character)
113        for s = (make-array '(5) :element-type type
114                            :adjustable t
115                            :initial-contents "aB0cD")
116        collect (list s (string-capitalize s)))
117  (("aB0cD" "Ab0cd") ("aB0cD" "Ab0cd") ("aB0cD" "Ab0cd")))
118
119;;; Order of evaluation tests
120
121(deftest string-capitalize.order.1
122  (let ((i 0) a b c (s (copy-seq "abcdef")))
123    (values
124     (string-capitalize
125      (progn (setf a (incf i)) s)
126      :start (progn (setf b (incf i)) 1)
127      :end   (progn (setf c (incf i)) 4))
128     i a b c))
129  "aBcdef" 3 1 2 3)
130
131(deftest string-capitalize.order.2
132  (let ((i 0) a b c (s (copy-seq "abcdef")))
133    (values
134     (string-capitalize
135      (progn (setf a (incf i)) s)
136      :end   (progn (setf b (incf i)) 4)
137      :start (progn (setf c (incf i)) 1))
138     i a b c))
139  "aBcdef" 3 1 2 3)
140
141(def-fold-test string-capitalize.fold.1 (string-capitalize "ABCDE"))
142
143;;; Error cases
144
145(deftest string-capitalize.error.1
146  (signals-error (string-capitalize) program-error)
147  t)
148
149(deftest string-capitalize.error.2
150  (signals-error (string-capitalize (copy-seq "abc") :bad t) program-error)
151  t)
152
153(deftest string-capitalize.error.3
154  (signals-error (string-capitalize (copy-seq "abc") :start) program-error)
155  t)
156
157(deftest string-capitalize.error.4
158  (signals-error (string-capitalize (copy-seq "abc") :bad t
159                                      :allow-other-keys nil) program-error)
160  t)
161
162(deftest string-capitalize.error.5
163  (signals-error (string-capitalize (copy-seq "abc") :end) program-error)
164  t)
165
166(deftest string-capitalize.error.6
167  (signals-error (string-capitalize (copy-seq "abc") 1 2) program-error)
168  t)
Note: See TracBrowser for help on using the repository browser.