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

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

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

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