source: trunk/source/tests/ansi-tests/make-string.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.0 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat Oct  5 12:32:20 2002
4;;;; Contains: Tests for MAKE-STRING
5
6(in-package :cl-test)
7
8(deftest make-string.1
9  (let ((s (make-string 10)))
10    (and (stringp s)
11         #+:ansi-tests-strict-initial-element
12         (string-all-the-same s)
13         (eqlt (length s) 10)
14         ))
15  t)
16
17(deftest make-string.2
18  (let ((s (make-string 10 :initial-element #\a)))
19    (and (stringp s)
20         (eql (length s) 10)
21         s))
22  "aaaaaaaaaa")
23
24(deftest make-string.3
25  (let ((s (make-string 10 :initial-element #\a
26                        :element-type 'character)))
27    (and (stringp s)
28         (eql (length s) 10)
29         s))
30  "aaaaaaaaaa")
31
32(deftest make-string.4
33  (let ((s (make-string 10 :initial-element #\a
34                        :element-type 'standard-char)))
35    (and (stringp s)
36         (eql (length s) 10)
37         s))
38  "aaaaaaaaaa")
39
40(deftest make-string.5
41  (let ((s (make-string 10 :initial-element #\a
42                        :element-type 'base-char)))
43    (and (stringp s)
44         (eql (length s) 10)
45         s))
46  "aaaaaaaaaa")
47
48(deftest make-string.6
49  (make-string 0)
50  "")
51
52(deftest make-string.7
53  (let ((s (make-string 10 :element-type 'character)))
54    (and (stringp s)
55         (eqlt (length s) 10)
56         #+:ansi-tests-strict-initial-element
57         (string-all-the-same s)
58         ))
59  t)
60
61(deftest make-string.8
62  (let ((s (make-string 10 :element-type 'standard-char)))
63    (and (stringp s)
64         (eqlt (length s) 10)
65         #+:ansi-tests-strict-initial-element
66         (string-all-the-same s)
67         ))
68  t)
69
70(deftest make-string.9
71  (let ((s (make-string 10 :element-type 'base-char)))
72    (and (stringp s)
73         (eqlt (length s) 10)
74         #+:ansi-tests-strict-initial-element
75         (string-all-the-same s)
76         ))
77  t)
78
79(deftest make-string.10
80  :notes (:nil-vectors-are-strings)
81  (let ((s (make-string 0 :element-type nil)))
82    (values
83     (notnot (stringp s))
84     (eqlt (length s) 0)
85     (equalt s "")))
86  t t t)
87
88(def-fold-test make-string.fold.1 (make-string 5 :initial-element #\a))
89
90;;; Keyword tests
91;
92(deftest make-string.allow-other-keys.1
93  (make-string 5 :allow-other-keys t :initial-element #\a)
94  "aaaaa")
95
96(deftest make-string.allow-other-keys.2
97  (make-string 5 :initial-element #\a :allow-other-keys t)
98  "aaaaa")
99
100(deftest make-string.allow-other-keys.3
101  (make-string 5 :initial-element #\a :allow-other-keys t
102               :bad t)
103  "aaaaa")
104
105(deftest make-string.allow-other-keys.4
106  (make-string 5 :bad t :allow-other-keys t :allow-other-keys nil
107               :initial-element #\a)
108  "aaaaa")
109
110(deftest make-string.allow-other-keys.5
111  (make-string 5 :allow-other-keys t :bad t :allow-other-keys nil
112               :initial-element #\a)
113  "aaaaa")
114
115(deftest make-string.allow-other-keys.6
116  (make-string 5 :allow-other-keys t :allow-other-keys nil :bad nil
117               :initial-element #\a)
118  "aaaaa")
119
120(deftest make-string.keywords.7
121  (make-string 5 :initial-element #\a :initial-element #\b)
122  "aaaaa")
123
124;; Error cases
125
126(deftest make-string.error.1
127  (signals-error (make-string) program-error)
128  t)
129
130(deftest make-string.error.2
131  (signals-error (make-string 10 :bad t) program-error)
132  t)
133
134(deftest make-string.error.3
135  (signals-error (make-string 10 :bad t :allow-other-keys nil)
136                 program-error)
137  t)
138
139(deftest make-string.error.4
140  (signals-error (make-string 10 :initial-element) program-error)
141  t)
142
143(deftest make-string.error.5
144  (signals-error (make-string 10 1 1) program-error)
145  t)
146
147(deftest make-string.error.6
148  (signals-error (make-string 10 :element-type) program-error)
149  t)
150
151;;; Order of evaluation
152
153(deftest make-string.order.1
154  (let ((i 0) a b)
155    (values
156     (make-string (progn (setf a (incf i)) 4)
157                  :initial-element (progn (setf b (incf i)) #\a))
158     i a b))
159  "aaaa" 2 1 2)
160
161(deftest make-string.order.2
162  (let ((i 0) a b c)
163    (values
164     (make-string (progn (setf a (incf i)) 4)
165                  :initial-element (progn (setf b (incf i)) #\a)
166                  :element-type (progn (setf c (incf i)) 'base-char))
167     i a b c))
168  "aaaa" 3 1 2 3)
169
170(deftest make-string.order.3
171  (let ((i 0) a b c)
172    (values
173     (make-string (progn (setf a (incf i)) 4)
174                  :element-type (progn (setf b (incf i)) 'base-char)
175                  :initial-element (progn (setf c (incf i)) #\a))
176     i a b c))
177  "aaaa" 3 1 2 3)
178
179
Note: See TracBrowser for help on using the repository browser.