source: trunk/source/tests/ansi-tests/format-t.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: 8.4 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat Aug 21 12:45:22 2004
4;;;; Contains: Tests of the ~T format directive
5
6(in-package :cl-test)
7
8(compile-and-load "printer-aux.lsp")
9
10(def-pprint-test format.t.1
11  (format nil "~0,0T")
12  "")
13
14(def-pprint-test format.t.2
15  (format nil "~1,0T")
16  " ")
17
18(def-pprint-test format.t.3
19  (format nil "~0,1T")
20  " ")
21
22(def-pprint-test format.t.4
23  (loop for i from 0 to 20
24        for s = (format nil "~0,vT" i)
25        unless (string= s (make-string i :initial-element #\Space))
26        collect (list i s))
27  nil)
28
29(def-pprint-test format.t.5
30  (loop for i from 0 to 20
31        for s = (format nil "~v,0T" i)
32        unless (string= s (make-string i :initial-element #\Space))
33        collect (list i s))
34  nil)
35
36(def-pprint-test format.t.6
37  (loop for n1 = (random 30)
38        for s1 = (make-string n1 :initial-element #\X)
39        for n2 = (random 30)
40        for inc = (random 20)
41        for s2 = (cond
42                  ((< n1 n2)
43                   (concatenate 'string s1 (make-string (- n2 n1)
44                                                        :initial-element #\Space)))
45                  ((= inc 0) s1)
46                  (t (loop do (incf n2 inc) while (<= n2 n1))
47                     (concatenate 'string s1 (make-string (- n2 n1)
48                                                          :initial-element #\Space))))
49        for pretty = (coin)
50        for result = (let ((*print-pretty* pretty))
51                       (format nil (format nil "~A~~~D,~DT" s1 n2 inc)))
52        repeat 100
53        unless (string= s2 result)
54        collect (list n1 n2 inc pretty s2 result))
55  nil)
56
57(def-pprint-test format.t.7
58  (loop for n1 = (random 30)
59        for s1 = (make-string n1 :initial-element #\X)
60        for n2 = (random 30)
61        for inc = (random 20)
62        for s2 = (cond
63                  ((< n1 n2)
64                   (concatenate 'string s1 (make-string (- n2 n1)
65                                                        :initial-element #\Space)))
66                  ((= inc 0) s1)
67                  (t (loop do (incf n2 inc) while (<= n2 n1))
68                     (concatenate 'string s1 (make-string (- n2 n1)
69                                                          :initial-element #\Space))))
70        for pretty = (coin)
71        for result = (let ((*print-pretty* pretty))
72                       (format nil "~A~v,vt" s1 n2 inc))
73        repeat 100
74        unless (string= s2 result)
75        collect (list n1 n2 inc pretty s2 result))
76  nil)
77
78(def-pprint-test format.t.8
79  (loop for i from 1 to 20
80        for s = (format nil " ~v,vT" nil i)
81        unless (string= s (make-string (1+ i) :initial-element #\Space))
82        collect (list i s))
83  nil)
84
85(def-pprint-test format.t.9
86  (loop for i from 1 to 20
87        for s = (format nil "~v,vT" i nil)
88        unless (string= s (make-string i :initial-element #\Space))
89        collect (list i s))
90  nil)
91
92(def-pprint-test format.t.10
93  (format nil "XXXXX~2,0T")
94  "XXXXX")
95
96;;; @t
97
98(def-pprint-test format.@t.1
99  (format nil "~1,1@t")
100  " ")
101
102(def-pprint-test format.@t.2
103  (loop for colnum from 0 to 20
104        for s1 = (format nil "~v,1@t" colnum)
105        for s2 = (make-string colnum :initial-element #\Space)
106        unless (string= s1 s2)
107        collect (list colnum s1 s2))
108  nil)
109
110(def-pprint-test format.@t.3
111  (loop for colnum = (random 50)
112        for colinc = (1+ (random 20))
113        for s1 = (format nil "~v,v@t" colnum colinc)
114        for s2 = (make-string (* colinc (ceiling colnum colinc))
115                              :initial-element #\Space)
116        repeat 100
117        unless (string= s1 s2)
118        collect (list colnum colinc s1 s2))
119  nil)
120
121(def-pprint-test format.@t.4
122  (loop for colnum = (random 50)
123        for colinc = (1+ (random 20))
124        for s1 = (format nil "~v,1@T~0,v@t" colnum colinc)
125        for s2 = (make-string (* colinc (ceiling colnum colinc))
126                              :initial-element #\Space)
127        repeat 100
128        unless (string= s1 s2)
129        collect (list colnum colinc s1 s2))
130  nil)
131
132(def-pprint-test format.@t.5
133  (loop for colnum = (random 50)
134        for colinc = (1+ (random 20))
135        for pretty = (coin)
136        for s1 = (let ((*pretty* pretty))
137                   (format nil (format nil "~~~d,~d@t" colnum colinc)))
138        for s2 = (make-string (* colinc (ceiling colnum colinc))
139                              :initial-element #\Space)
140        repeat 100
141        unless (string= s1 s2)
142        collect (list colnum colinc pretty s1 s2))
143  nil)
144
145;;; Pretty printing (colon modifier)
146
147;;; Not a pretty printing stream
148
149(def-pprint-test format.\:t.1
150  (format nil "XX~10:tYY")
151  "XXYY")
152
153;;; A pretty printing stream, but *print-pretty* is nil
154
155(def-pprint-test format.\:t.2
156  (with-output-to-string
157   (s)
158   (pprint-logical-block
159    (s '(a b c))
160    (format s "XX~10:tYY")))
161  "XXYY"
162  :pretty nil)
163
164(def-pprint-test format.\:t.3
165  (with-output-to-string
166   (s)
167   (pprint-logical-block
168    (s '(a b c))
169    (let ((*print-pretty* nil))
170      (format s "XX~10:tYY"))))
171  "XXYY")
172
173;;; Positive tests
174
175(def-pprint-test format.\:t.4
176  (format nil "~<[~;~0,0:T~;]~:>" '(a))
177  "[]")
178
179(def-pprint-test format.\:t.5
180  (format nil "~<[~;~1,0:T~;]~:>" '(a))
181  "[ ]")
182
183(def-pprint-test format.\:t.5a
184  (format nil "~<[~;~,0:T~;]~:>" '(a))
185  "[ ]")
186
187(def-pprint-test format.\:t.6
188  (format nil "~<[~;~0,1:T~;]~:>" '(a))
189  "[ ]")
190
191(def-pprint-test format.\:t.6a
192  (format nil "~<[~;~0,:T~;]~:>" '(a))
193  "[ ]")
194
195(def-pprint-test format.\:t.6b
196  (format nil "~<[~;~0:T~;]~:>" '(a))
197  "[ ]")
198
199(def-pprint-test format.\:t.7
200  (loop for i from 0 to 20
201        for s = (format nil "~<X~;~0,v:T~;Y~:>" (list i))
202        unless (string= s (concatenate 'string "X" (make-string i :initial-element #\Space) "Y"))
203        collect (list i s))
204  nil)
205
206(def-pprint-test format.\:t.8
207  (loop for i from 0 to 20
208        for s = (format nil "~<ABC~;~v,0:T~;DEF~:>" (list i))
209        unless (string= s (concatenate 'string "ABC" (make-string i :initial-element #\Space) "DEF"))
210        collect (list i s))
211  nil)
212
213(def-pprint-test format.\:t.9
214  (loop
215   for n0 = (random 10)
216   for s0 = (make-string n0 :initial-element #\Space)
217   for n1 = (random 30)
218   for s1 = (make-string n1 :initial-element #\X)
219   for n2 = (random 30)
220   for inc = (random 20)
221   for s2 = (cond
222             ((< n1 n2)
223              (concatenate 'string s0 s1 (make-string (- n2 n1)
224                                                      :initial-element #\Space)))
225             ((= inc 0) (concatenate 'string s0 s1))
226             (t (loop do (incf n2 inc) while (<= n2 n1))
227                (concatenate 'string s0 s1 (make-string (- n2 n1)
228                                                        :initial-element #\Space))))
229   for result = (format nil (format nil "~A~~<~A~~~D,~D:T~~:>" s0 s1 n2 inc) '(a))
230   repeat 100
231   unless (string= s2 result)
232   collect (list n0 n1 n2 inc s2 result))
233  nil)
234
235(def-pprint-test format.\:t.10
236  (format nil "~<[~;~2,0:T~;]~:>" '(a))
237  "[  ]")
238
239(def-pprint-test format.\:t.11
240  (format nil "~<[~;XXXX~2,0:T~;]~:>" '(a))
241  "[XXXX]")
242
243(def-pprint-test format.\:t.12
244  (loop for n0 = (random 20)
245        for s0 = (make-string n0 :initial-element #\Space)
246        for n1 = (random 30)
247        for s1 = (make-string n1 :initial-element #\X)
248        for n2 = (random 30)
249        for inc = (random 20)
250        for s2 = (cond
251                  ((< n1 n2)
252                   (concatenate 'string s0 s1 (make-string (- n2 n1)
253                                                           :initial-element #\Space)))
254                  ((= inc 0) (concatenate 'string s0 s1))
255                  (t (loop do (incf n2 inc) while (<= n2 n1))
256                     (concatenate 'string s0 s1 (make-string (- n2 n1)
257                                                             :initial-element #\Space))))
258        for result = (format nil "~A~<~A~v,v:t~:>" s0 (list s1 n2 inc))
259        repeat 100
260        unless (string= s2 result)
261        collect (list n1 n2 inc s2 result))
262  nil)
263
264;;; see 22.3.5.2
265
266(deftest format.\:t.error.1
267  (signals-error-always (format nil "~<XXX~1,1:TYYY~>") error)
268  t t)
269
270(deftest format.\:t.error.2
271  (signals-error-always (format nil "~<XXX~:;YYY~>ZZZ~4,5:tWWW") error)
272  t t)
273
274(deftest format.\:t.error.3
275  (signals-error-always (format nil "AAAA~1,1:TBBB~<XXX~:;YYY~>ZZZ") error)
276  t t)
277
278;;; ~:@t
279
280(def-pprint-test format.\:@t.1
281  (format nil "~<XXX~;~1,1:@t~;YYY~:>" '(a))
282  "XXX YYY")
283
284(def-pprint-test format.\:@t.1a
285  (format nil "~<XXX~;~,1:@t~;YYY~:>" '(a))
286  "XXX YYY")
287
288(def-pprint-test format.\:@t.1b
289  (format nil "~<XXX~;~1,:@t~;YYY~:>" '(a))
290  "XXX YYY")
291
292(def-pprint-test format.\:@t.1c
293  (format nil "~<XXX~;~1:@t~;YYY~:>" '(a))
294  "XXX YYY")
295
296(def-pprint-test format.\:@t.1d
297  (format nil "~<XXX~;~:@t~;YYY~:>" '(a))
298  "XXX YYY")
299
300(def-pprint-test format.\:@t.2
301  (loop for colnum from 0 to 20
302        for s1 = (format nil "~<XXXX~;~v,1:@t~:>" (list colnum))
303        for s2 = (concatenate 'string "XXXX" (make-string colnum :initial-element #\Space))
304        unless (string= s1 s2)
305        collect (list colnum s1 s2))
306  nil)
307
308(def-pprint-test format.\:@t.3
309  (loop for s0 = (make-string (random 20) :initial-element #\M)
310        for colnum = (random 50)
311        for colinc = (1+ (random 20))
312        for s1 = (format nil "~A~<~v,v:@t~:>" s0 (list colnum colinc))
313        for s2 = (concatenate 'string
314                              s0
315                              (make-string (* colinc (ceiling colnum colinc))
316                                           :initial-element #\Space))
317        repeat 100
318        unless (string= s1 s2)
319        collect (list colnum colinc s1 s2))
320  nil)
321
322;;; Turned off if not pretty printing
323
324(def-pprint-test format.\:@t.4
325  (format nil "XX~10,20:@tYY")
326  "XXYY"
327  :pretty nil)
328
329(def-pprint-test format.\:@t.5
330  (with-output-to-string
331   (s)
332   (pprint-logical-block
333    (s '(a b c))
334    (format s "XX~10,20@:tYY")))
335  "XXYY"
336  :pretty nil)
Note: See TracBrowser for help on using the repository browser.