source: trunk/source/tests/ansi-tests/format-s.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: 8.0 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Tue Aug  3 11:55:07 2004
4;;;; Contains: Test of the ~S format directive
5
6(in-package :cl-test)
7(compile-and-load "printer-aux.lsp")
8
9(deftest format.s.1
10  (let ((*print-readably* nil)
11        (*print-case* :upcase))
12    (format nil "~s" nil))
13  "NIL")
14
15(deftest formatter.s.1
16  (let ((*print-readably* nil)
17        (*print-case* :upcase))
18    (formatter-call-to-string (formatter "~s") nil))
19  "NIL")
20
21(def-format-test format.s.2
22  "~:s" (nil) "()")
23
24(deftest format.s.3
25  (let ((*print-readably* nil)
26        (*print-case* :upcase))
27    (format nil "~:s" '(nil)))
28  "(NIL)")
29
30(deftest formatter.s.3
31  (let ((*print-readably* nil)
32        (*print-case* :upcase))
33    (formatter-call-to-string (formatter "~:s") '(nil)))
34  "(NIL)")
35
36(deftest format.s.4
37  (let ((*print-readably* nil)
38        (*print-case* :downcase))
39    (format nil "~s" 'nil))
40  "nil")
41
42(deftest formatter.s.4
43  (let ((*print-readably* nil)
44        (*print-case* :downcase))
45    (formatter-call-to-string (formatter "~s") 'nil))
46  "nil")
47
48(deftest format.s.5
49  (let ((*print-readably* nil)
50        (*print-case* :capitalize))
51    (format nil "~s" 'nil))
52  "Nil")
53
54(deftest formatter.s.5
55  (let ((*print-readably* nil)
56        (*print-case* :capitalize))
57    (formatter-call-to-string (formatter "~s") 'nil))
58  "Nil")
59
60(def-format-test format.s.6
61  "~:s" (#(nil)) "#(NIL)")
62
63(deftest format.s.7
64  (let ((fn (formatter "~S")))
65    (with-standard-io-syntax
66     (let ((*print-readably* nil))
67       (loop for c across +standard-chars+
68             for s = (format nil "~S" c)
69             for s2 = (formatter-call-to-string fn c)
70             for c2 = (read-from-string s)
71             unless (and (eql c c2) (string= s s2))
72             collect (list c s c2 s2)))))
73  nil)
74
75(deftest format.s.8
76  (let ((fn (formatter "~s")))
77    (with-standard-io-syntax
78     (let ((*print-readably* nil))
79       (loop with count = 0
80             for i from 0 below (min #x10000 char-code-limit)
81             for c = (code-char i)
82             for s1 = (and c (format nil "#\\~:c" c))
83             for s2 = (and c (format nil "~S" c))
84             for s3 = (formatter-call-to-string fn c)
85             unless (or (null c)
86                        (graphic-char-p c)
87                        (and (string= s1 s2) (string= s2 s3)))
88              do (incf count) and collect (list c s1 s2)
89             when (> count 100)
90              collect "count limit exceeded"
91              and do (loop-finish)))))
92  nil)
93
94(deftest format.s.9
95  (with-standard-io-syntax
96   (let ((*print-readably* nil))
97     (apply
98      #'values
99      (loop for i from 1 to 10
100            for fmt = (format nil "~~~d@s" i)
101            for s = (format nil fmt nil)
102            for fn = (eval `(formatter ,fmt))
103            for s2 = (formatter-call-to-string fn nil)
104            do (assert (string= s s2))
105            collect s))))
106  "NIL"
107  "NIL"
108  "NIL"
109  " NIL"
110  "  NIL"
111  "   NIL"
112  "    NIL"
113  "     NIL"
114  "      NIL"
115  "       NIL")
116
117(deftest format.s.10
118  (with-standard-io-syntax
119   (let ((*print-readably* nil))
120     (apply
121      #'values
122      (loop for i from 1 to 10
123            for fmt = (format nil "~~~dS" i)
124            for s = (format nil fmt nil)
125            for fn = (eval `(formatter ,fmt))
126            for s2 = (formatter-call-to-string fn nil)
127            do (assert (string= s s2))
128            collect s))))
129  "NIL"
130  "NIL"
131  "NIL"
132  "NIL "
133  "NIL  "
134  "NIL   "
135  "NIL    "
136  "NIL     "
137  "NIL      "
138  "NIL       ")
139
140(deftest format.s.11
141  (with-standard-io-syntax
142   (let ((*print-readably* nil))
143     (apply
144      #'values
145      (loop for i from 1 to 10
146            for fmt = (format nil "~~~d@:S" i)
147            for s = (format nil fmt nil)
148            for fn = (eval `(formatter ,fmt))
149            for s2 = (formatter-call-to-string fn nil)
150            do (assert (string= s s2))
151            collect s))))
152  "()"
153  "()"
154  " ()"
155  "  ()"
156  "   ()"
157  "    ()"
158  "     ()"
159  "      ()"
160  "       ()"
161  "        ()")
162
163(deftest format.s.12
164  (with-standard-io-syntax
165   (let ((*print-readably* nil))
166     (apply
167      #'values
168      (loop for i from 1 to 10
169            for fmt = (format nil "~~~d:s" i)
170            for s = (format nil fmt nil)
171            for fn = (eval `(formatter ,fmt))
172            for s2 = (formatter-call-to-string fn nil)
173            do (assert (string= s s2))
174            collect s))))
175  "()"
176  "()"
177  "() "
178  "()  "
179  "()   "
180  "()    "
181  "()     "
182  "()      "
183  "()       "
184  "()        ")
185
186(deftest format.s.13
187  (with-standard-io-syntax
188   (let ((*print-readably* nil)
189         (fn (formatter "~V:s")))
190     (apply
191      #'values
192      (loop for i from 1 to 10
193            for s = (format nil "~v:S" i nil)
194            for s2 = (formatter-call-to-string fn i nil)
195            do (assert (string= s s2))
196            collect s))))
197  "()"
198  "()"
199  "() "
200  "()  "
201  "()   "
202  "()    "
203  "()     "
204  "()      "
205  "()       "
206  "()        ")
207
208(deftest format.s.14
209  (with-standard-io-syntax
210   (let ((*print-readably* nil)
211         (fn (formatter "~V@:s")))
212     (apply
213      #'values
214      (loop for i from 1 to 10
215            for s = (format nil "~v:@s" i nil)
216            for s2 = (formatter-call-to-string fn i nil)
217            do (assert (string= s s2))
218            collect s))))
219  "()"
220  "()"
221  " ()"
222  "  ()"
223  "   ()"
224  "    ()"
225  "     ()"
226  "      ()"
227  "       ()"
228  "        ()")
229
230(def-format-test format.s.15
231  "~vS" (nil nil) "NIL")
232
233(def-format-test format.s.16
234  "~v:S" (nil nil) "()")
235
236(def-format-test format.s.17
237  "~@S" (nil) "NIL")
238
239(def-format-test format.s.18
240  "~v@S" (nil nil) "NIL")
241
242(def-format-test format.s.19
243  "~v:@s" (nil nil) "()")
244
245(def-format-test format.s.20
246  "~v@:s" (nil nil) "()")
247
248;;; With colinc specified
249
250(def-format-test format.s.21
251  "~3,1s" (nil) "NIL")
252
253(def-format-test format.s.22
254  "~4,3s" (nil) "NIL   ")
255
256(def-format-test format.s.23
257  "~3,3@s" (nil) "NIL")
258
259(def-format-test format.s.24
260  "~4,4@s" (nil) "    NIL")
261
262(def-format-test format.s.25
263  "~5,3@s" (nil) "   NIL")
264
265(def-format-test format.s.26
266  "~5,3S" (nil) "NIL   ")
267
268(def-format-test format.s.27
269  "~7,3@s" (nil) "      NIL")
270
271(def-format-test format.s.28
272  "~7,3S" (nil) "NIL      ")
273
274;;; With minpad
275
276(deftest format.s.29
277  (with-standard-io-syntax
278   (let ((*print-readably* nil)
279         (*package* (find-package :cl-test))
280         (fn (formatter "~V,,2s")))
281     (loop for i from -4 to 10
282           for s = (format nil "~v,,2S" i 'ABC)
283           for s2 = (formatter-call-to-string fn i 'ABC)
284           do (assert (string= s s2))
285           collect s)))
286  ("ABC  "
287   "ABC  "
288   "ABC  "
289   "ABC  "
290   "ABC  "
291   "ABC  "
292   "ABC  "
293   "ABC  "
294   "ABC  "
295   "ABC  "
296   "ABC   "
297   "ABC    "
298   "ABC     "
299   "ABC      "
300   "ABC       "))
301
302(def-format-test format.s.30
303  "~3,,+2S" ('ABC) "ABC  ")
304
305(def-format-test format.s.31
306  "~3,,0S" ('ABC) "ABC")
307
308(def-format-test format.s.32
309  "~3,,-1S" ('ABC) "ABC")
310
311(def-format-test format.s.33
312  "~3,,0S" ('ABCD) "ABCD")
313
314(def-format-test format.s.34
315  "~3,,-1S" ('ABCD) "ABCD")
316
317;;; With padchar
318
319(def-format-test format.s.35
320  "~4,,,'XS" ('AB) "ABXX")
321
322(def-format-test format.s.36
323  "~4,,,s" ('AB) "AB  ")
324
325(def-format-test format.s.37
326  "~4,,,'X@s" ('AB) "XXAB")
327
328(def-format-test format.s.38
329  "~4,,,@S" ('AB) "  AB")
330
331(def-format-test format.s.39
332  "~10,,,vS" (nil 'ABCDE) "ABCDE     ")
333
334(def-format-test format.s.40
335  "~10,,,v@S" (nil 'ABCDE) "     ABCDE")
336
337(def-format-test format.s.41
338  "~10,,,vs" (#\* 'ABCDE) "ABCDE*****")
339
340(def-format-test format.s.42
341  "~10,,,v@s" (#\* 'ABCDE) "*****ABCDE")
342
343;;; Other tests
344
345(def-format-test format.s.43
346  "~3,,vS" (nil 246) "246")
347
348(deftest format.s.44
349  (with-standard-io-syntax
350   (let ((*print-readably* nil)
351         (*package* (find-package :cl-test))
352         (fn (formatter "~3,,vs")))
353     (loop for i from 0 to 6
354           for s = (format nil "~3,,vS" i 'ABC)
355           for s2 = (formatter-call-to-string fn i 'ABC)
356           do (assert (string= s s2))
357           collect s)))
358  ("ABC"
359   "ABC "
360   "ABC  "
361   "ABC   "
362   "ABC    "
363   "ABC     "
364   "ABC      "))
365
366(deftest format.s.44a
367  (with-standard-io-syntax
368   (let ((*print-readably* nil)
369         (*package* (find-package :cl-test))
370         (fn (formatter "~3,,V@S")))
371     (loop for i from 0 to 6
372           for s = (format nil "~3,,v@S" i 'ABC)
373           for s2 = (formatter-call-to-string fn i 'ABC)
374           do (assert (string= s s2))
375           collect s)))
376  ("ABC"
377   " ABC"
378   "  ABC"
379   "   ABC"
380   "    ABC"
381   "     ABC"
382   "      ABC"))
383
384(def-format-test format.s.45
385  "~4,,vs" (-1 1234) "1234")
386
387(def-format-test format.s.46
388  "~5,vS" (nil 123) "123  ")
389
390(def-format-test format.s.47
391  "~5,vS" (3 456) "456   ")
392
393(def-format-test format.s.48
394  "~5,v@S" (3 789) "   789")
Note: See TracBrowser for help on using the repository browser.