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