source: trunk/source/tests/ansi-tests/format-justify.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: 6.7 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sun Aug 22 18:09:49 2004
4;;;; Contains: Tests of the ~< ~> directive
5
6(in-package :cl-test)
7
8(compile-and-load "printer-aux.lsp")
9
10(def-pprint-test format.justify.1
11  (format nil "~<~>")
12  "")
13
14(def-pprint-test format.justify.2
15  (loop for i from 1 to 20
16        for s1 = (make-string i :initial-element #\x)
17        for s2 = (format nil "~<~A~>" s1)
18        unless (string= s1 s2)
19        collect (list i s1 s2))
20  nil)
21
22(def-pprint-test format.justify.3
23  (loop for i from 1 to 20
24        for s1 = (make-string i :initial-element #\x)
25        for s2 = (format nil "~<~A~;~A~>" s1 s1)
26        unless (string= s2 (concatenate 'string s1 s1))
27        collect (list i s1 s2))
28  nil)
29
30(def-pprint-test format.justify.4
31  (loop for i from 1 to 20
32        for s1 = (make-string i :initial-element #\x)
33        for expected = (concatenate 'string s1 " " s1)
34        for s2 = (format nil "~,,1<~A~;~A~>" s1 s1)
35        unless (string= s2 expected)
36        collect (list i expected s2))
37  nil)
38
39(def-pprint-test format.justify.5
40  (loop for i from 1 to 20
41        for s1 = (make-string i :initial-element #\x)
42        for expected = (concatenate 'string s1 "," s1)
43        for s2 = (format nil "~,,1,',<~A~;~A~>" s1 s1)
44        unless (string= s2 expected)
45        collect (list i expected s2))
46  nil)
47
48(def-pprint-test format.justify.6
49  (loop for i from 1 to 20
50        for s1 = (make-string i :initial-element #\x)
51        for expected = (concatenate 'string s1 "  " s1)
52        for s2 = (format nil "~,,2<~A~;~A~>" s1 s1)
53        unless (string= s2 expected)
54        collect (list i expected s2))
55  nil)
56
57(def-pprint-test format.justify.7
58  (loop for mincol = (random 50)
59        for len = (random 50)
60        for s1 = (make-string len :initial-element #\x)
61        for s2 = (format nil "~v<~A~>" mincol s1)
62        for expected = (if (< len mincol)
63                           (concatenate 'string
64                                        (make-string (- mincol len) :initial-element #\Space)
65                                        s1)
66                         s1)
67        repeat 100
68        unless (string= s2 expected)
69        collect (list mincol len s1 s2 expected))
70  nil)
71
72(def-pprint-test format.justify.8
73  (loop for mincol = (random 50)
74        for minpad = (random 10)
75        for len = (random 50)
76        for s1 = (make-string len :initial-element #\x)
77        for s2 = (format nil "~v,,v<~A~>" mincol minpad s1)
78        for expected = (if (< len mincol)
79                           (concatenate 'string
80                                        (make-string (- mincol len) :initial-element #\Space)
81                                        s1)
82                         s1)
83        repeat 100
84        unless (string= s2 expected)
85        collect (list mincol minpad len s1 s2 expected))
86  nil)
87
88(def-pprint-test format.justify.9
89  (loop for mincol = (random 50)
90        for padchar = (random-from-seq +standard-chars+)
91        for len = (random 50)
92        for s1 = (make-string len :initial-element #\x)
93        for s2 = (format nil "~v,,,v<~A~>" mincol padchar s1)
94        for expected = (if (< len mincol)
95                           (concatenate 'string
96                                        (make-string (- mincol len) :initial-element padchar)
97                                        s1)
98                         s1)
99        repeat 100
100        unless (string= s2 expected)
101        collect (list mincol padchar len s1 s2 expected))
102  nil)
103
104(def-pprint-test format.justify.10
105  (loop for mincol = (random 50)
106        for padchar = (random-from-seq +standard-chars+)
107        for len = (random 50)
108        for s1 = (make-string len :initial-element #\x)
109        for s2 = (format nil (format nil "~~~d,,,'~c<~~A~~>" mincol padchar) s1)
110        for expected = (if (< len mincol)
111                           (concatenate 'string
112                                        (make-string (- mincol len) :initial-element padchar)
113                                        s1)
114                         s1)
115        repeat 500
116        unless (string= s2 expected)
117        collect (list mincol padchar len s1 s2 expected))
118  nil)
119
120(def-pprint-test format.justify.11
121  (loop for i = (1+ (random 20))
122        for colinc = (1+ (random 10))
123        for s1 = (make-string i :initial-element #\x)
124        for s2 = (format nil "~,v<~A~>" colinc s1)
125        for expected-len = (* colinc (ceiling i colinc))
126        for expected = (concatenate 'string
127                                    (make-string (- expected-len i) :initial-element #\Space)
128                                    s1)
129        repeat 10
130        unless (string= expected s2)
131        collect (list i colinc expected s2))
132  nil)
133
134(def-pprint-test format.justify.12
135  (format nil "~<XXXXXX~^~>")
136  "")
137
138(def-pprint-test format.justify.13
139  (format nil "~<XXXXXX~;YYYYYYY~^~>")
140  "XXXXXX")
141
142(def-pprint-test format.justify.13a
143  (format nil "~<~<XXXXXX~;YYYYYYY~^~>~>")
144  "XXXXXX")
145
146(def-pprint-test format.justify.14
147  (format nil "~<XXXXXX~;YYYYYYY~^~;ZZZZZ~>")
148  "XXXXXX")
149
150(def-pprint-test format.justify.15
151  (format nil "~13,,2<aaa~;bbb~;ccc~>")
152  "aaa  bbb  ccc")
153
154(def-pprint-test format.justify.16
155  (format nil "~10@<abcdef~>")
156  "abcdef    ")
157
158(def-pprint-test format.justify.17
159  (format nil "~10:@<abcdef~>")
160  "  abcdef  ")
161
162(def-pprint-test format.justify.18
163  (format nil "~10:<abcdef~>")
164  "    abcdef")
165
166(def-pprint-test format.justify.19
167  (format nil "~4@<~>")
168  "    ")
169
170(def-pprint-test format.justify.20
171  (format nil "~5:@<~>")
172  "     ")
173
174(def-pprint-test format.justify.21
175  (format nil "~6:<~>")
176  "      ")
177
178(def-pprint-test format.justify.22
179  (format nil "~v<~A~>" nil "XYZ")
180  "XYZ")
181
182(def-pprint-test format.justify.23
183  (format nil "~,v<~A~;~A~>" nil "ABC" "DEF")
184  "ABCDEF")
185
186(def-pprint-test format.justify.24
187  (format nil "~,,v<~A~;~A~>" nil "ABC" "DEF")
188  "ABCDEF")
189
190(def-pprint-test format.justify.25
191  (format nil "~,,1,v<~A~;~A~>" nil "ABC" "DEF")
192  "ABC DEF")
193
194(def-pprint-test format.justify.26
195  (format nil "~,,1,v<~A~;~A~>" #\, "ABC" "DEF")
196  "ABC,DEF")
197
198(def-pprint-test format.justify.27
199  (format nil "~6<abc~;def~^~>")
200  "   abc")
201
202(def-pprint-test format.justify.28
203  (format nil "~6@<abc~;def~^~>")
204  "abc   ")
205
206;;; ~:; tests
207
208(def-pprint-test format.justify.29
209  (format nil "~%X ~,,1<~%X ~:;AAA~;BBB~;CCC~>")
210  "
211X AAA BBB CCC")
212
213(def-pprint-test format.justify.30
214  (format nil "~%X ~<~%X ~0,3:;AAA~>~<~%X ~0,3:;BBB~>~<~%X ~0,3:;CCC~>")
215  "
216X
217X AAA
218X BBB
219X CCC")
220
221(def-pprint-test format.justify.31
222  (format nil "~%X ~<~%X ~0,30:;AAA~>~<~%X ~0,30:;BBB~>~<~%X ~0,30:;CCC~>")
223  "
224X AAABBBCCC")
225
226(def-pprint-test format.justify.32
227  (format nil "~%X ~<~%X ~0,3:;AAA~>,~<~%X ~0,3:;BBB~>,~<~%X ~0,3:;CCC~>")
228  "
229X
230X AAA,
231X BBB,
232X CCC")
233
234;;; Error cases
235
236;;; See 22.3.5.2
237
238;;; Interaction with ~W
239
240(deftest format.justify.error.w.1
241  (signals-error-always (format nil "~< ~W ~>" nil) error)
242  t t)
243
244(deftest format.justify.error.w.2
245  (signals-error-always (format nil "~<X~:;Y~>~W" nil) error)
246  t t)
247
248(deftest format.justify.error.w.3
249  (signals-error-always (format nil "~w~<X~:;Y~>" nil) error)
250  t t)
251
252;;; Interaction with ~_
253
254(deftest format.justify.error._.1
255  (signals-error-always (format nil "~< ~_ ~>") error)
256  t t)
257
258(deftest format.justify.error._.2
259  (signals-error-always (format nil "~<X~:;Y~>~_") error)
260  t t)
261
262(deftest format.justify.error._.3
263  (signals-error-always (format nil "~_~<X~:;Y~>") error)
264  t t)
265
266;;; Interaction with ~I
267
268(deftest format.justify.error.i.1
269  (signals-error-always (format nil "~< ~i ~>") error)
270  t t)
271
272(deftest format.justify.error.i.2
273  (signals-error-always (format nil "~<X~:;Y~>~I") error)
274  t t)
275
276(deftest format.justify.error.i.3
277  (signals-error-always (format nil "~i~<X~:;Y~>") error)
278  t t)
279
Note: See TracBrowser for help on using the repository browser.