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