source: trunk/source/tests/ansi-tests/format-brace.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.7 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Wed Aug 25 22:08:51 2004
4;;;; Contains: Tests of the ~"{ ... ~} format directives
5
6(in-package :cl-test)
7
8(compile-and-load "printer-aux.lsp")
9
10(def-format-test format.{.1
11  (concatenate 'string "~{~" (string #\Newline) "~}")
12  (nil) "")
13
14(def-format-test format.{.1a
15  "~{~}" ("" nil) "")
16
17(def-format-test format.{.1b
18  "~0{~}" ("" '(1 2 3)) "")
19
20(def-format-test format.{.2
21  "~{ ~}" (nil) "")
22
23(def-format-test format.{.3
24  "~{X Y Z~}" (nil) "")
25
26(def-format-test format.{.4
27  "~{~A~}" ('(1 2 3 4)) "1234")
28
29(def-format-test format.{.5
30  "~{~{~A~}~}" ('((1 2 3)(4 5)(6 7 8))) "12345678")
31
32(def-format-test format.{.6
33  "~{~1{~A~}~}" ('((1 2 3)(4 5)(6 7 8))) "146")
34
35(def-format-test format.{.7
36  (concatenate 'string "~1{~" (string #\Newline) "~}") (nil) "")
37
38(deftest format.{.8
39  (loop for i from 0 to 10
40        for s = (format nil "~v{~A~}" i '(1 2 3 4 5 6 7 8 9 0))
41        unless (string= s (subseq "1234567890" 0 i))
42        collect (list i s))
43  nil)
44
45(deftest formatter.{.8
46  (let ((fn (formatter "~V{~A~}")))
47    (loop for i from 0 to 10
48          for s = (formatter-call-to-string fn i '(1 2 3 4 5 6 7 8 9 0))
49          unless (string= s (subseq "1234567890" 0 i))
50          collect (list i s)))
51  nil)
52
53(def-format-test format.{.9
54  "~#{~A~}" ('(1 2 3 4 5 6 7) nil nil nil) "1234" 3)
55
56;;; (missing tests involved ~^ and have been moved to format-circumflex.lsp
57;;;  and renamed.)
58
59(def-format-test format.{.15
60  "~0{~}" ("~A" '(1 2 3)) "")
61
62(def-format-test format.{.16
63  "~1{~}" ("~A" '(4 5 6)) "4")
64
65(deftest format.{.17
66  (format nil "~{~}" (formatter "") nil)
67  "")
68
69(deftest format.{.18
70  (format nil "~1{~}" (formatter "") '(1 2 3 4))
71  "")
72
73(deftest format.{.19
74  (format nil "~{~}" (formatter "~A") '(1 2 3 4))
75  "1234")
76
77(deftest format.{.20
78  (format nil "~3{~}" (formatter "~A") '(1 2 3 4))
79  "123")
80
81(def-format-test format.{.21
82  "~V{~}" (2 "~A" '(1 2 3 4 5)) "12")
83
84(def-format-test format.{.22
85  "~#{~}" ("~A" '(1 2 3 4 5)) "12")
86
87(def-format-test format.{.23
88  "~{FOO~:}" (nil) "FOO")
89
90(def-format-test format.{.24
91  "~{~A~:}" ('(1)) "1")
92
93(def-format-test format.{.25
94  "~{~A~:}" ('(1 2)) "12")
95
96(def-format-test format.{.26
97  "~{~A~:}" ('(1 2 3)) "123")
98
99(def-format-test format.{.27
100  "~0{FOO~:}" (nil) "")
101
102(def-format-test format.{.28
103  "~V{FOO~:}" (0 nil) "")
104
105(def-format-test format.{.29
106  "~1{FOO~:}" (nil) "FOO")
107
108(def-format-test format.{.30
109  "~2{FOO~:}" (nil) "FOO")
110
111(def-format-test format.{.31
112  (concatenate 'string "~2{~" (string #\Newline) "~:}")
113  (nil) "")
114
115(def-format-test format.{.32
116  "~2{FOO~}" (nil) "")
117
118(def-format-test format.{.33
119  "~v{~a~}" (nil '(1 2 3 4 5 6 7)) "1234567")
120
121;;; ~:{ ... ~}
122
123(def-format-test format.\:{.1
124  "~:{(~A ~A)~}" ('((1 2 3)(4 5)(6 7 8))) "(1 2)(4 5)(6 7)")
125
126(def-format-test format.\:{.2
127  (concatenate 'string "~:{~" (string #\Newline) "~}")
128  (nil) "")
129
130(def-format-test format.\:{.3
131  "~:{~}" ("" nil) "")
132
133(def-format-test format.\:{.4
134  "~:{~}" ("~A" nil) "")
135
136(def-format-test format.\:{.5
137  "~:{~}" ("X" '(nil (1 2) (3))) "XXX")
138
139(deftest format.\:{.6
140  (format nil "~:{~}" (formatter "~A") '((1 2) (3) (4 5 6)))
141  "134")
142
143(def-format-test format.\:{.7
144  "~0:{XYZ~}" ('((1))) "")
145         
146(def-format-test format.\:{.8
147  "~2:{XYZ~}" ('((1))) "XYZ")
148         
149(def-format-test format.\:{.9
150  "~2:{~A~}" ('((1) (2))) "12")
151         
152(def-format-test format.\:{.10
153  "~2:{~A~}" ('((1 X) (2 Y) (3 Z))) "12")
154
155(deftest format.\:{.11
156  (loop for i from 0 to 10 collect
157        (format nil "~v:{~A~}" i '((1) (2) (3 X) (4 Y Z) (5) (6))))
158  ("" "1" "12" "123" "1234" "12345"
159   "123456" "123456" "123456" "123456" "123456"))
160
161(deftest formatter.\:{.11
162  (let ((fn (formatter "~v:{~A~}")))
163    (loop for i from 0 to 10 collect
164          (formatter-call-to-string fn i '((1) (2) (3 X) (4 Y Z) (5) (6)))))
165  ("" "1" "12" "123" "1234" "12345"
166   "123456" "123456" "123456" "123456" "123456"))
167
168(def-format-test format.\:{.12
169  "~V:{X~}" (nil '((1) (2) (3) nil (5))) "XXXXX")
170
171(def-format-test format.\:{.13
172  "~#:{~A~}" ('((1) (2) (3) (4) (5)) 'foo 'bar) "123" 2)
173
174(def-format-test format.\:{.14
175  "~:{~A~:}" ('((1 X) (2 Y) (3) (4 A B))) "1234")
176
177(deftest format.\:{.15
178  (loop for i from 0 to 10 collect
179        (format nil "~v:{~A~:}" i '((1 X) (2 Y) (3) (4 A B))))
180  ("" "1" "12" "123" "1234" "1234"
181   "1234" "1234" "1234" "1234" "1234"))
182
183(deftest formatter.\:{.15
184  (let ((fn (formatter "~v:{~A~:}")))
185    (loop for i from 0 to 10 collect
186          (formatter-call-to-string fn i '((1 X) (2 Y) (3) (4 A B)))))
187  ("" "1" "12" "123" "1234" "1234"
188   "1234" "1234" "1234" "1234" "1234"))
189
190(def-format-test format.\:{.16
191  "~:{ABC~:}" ('(nil)) "ABC")
192
193(def-format-test format.\:{.17
194  "~v:{ABC~:}" (nil '(nil)) "ABC")
195
196
197;;; Tests of ~@{ ... ~}
198
199(def-format-test format.@{.1
200  (concatenate 'string "~@{~" (string #\Newline) "~}")
201  nil "")
202
203(def-format-test format.@{.1A
204  "~@{~}" ("") "")
205
206(def-format-test format.@{.2
207  "~@{ ~}" nil "")
208
209(def-format-test format.@{.3
210  "~@{X ~A Y Z~}" (nil) "X NIL Y Z")
211
212(def-format-test format.@{.4
213  "~@{~A~}" (1 2 3 4) "1234")
214
215(def-format-test format.@{.5
216  "~@{~{~A~}~}" ('(1 2 3) '(4 5) '(6 7 8)) "12345678")
217
218(def-format-test format.@{.6
219  "~@{~1{~A~}~}" ('(1 2 3) '(4 5) '(6 7 8)) "146")
220
221(def-format-test format.@{.7
222  "~1@{FOO~}" nil "")
223
224(def-format-test format.@{.8
225  "~v@{~A~}" (nil 1 4 7) "147")
226
227(def-format-test format.@{.9
228  "~#@{~A~}" (1 2 3) "123")
229
230(deftest format.@{.10
231  (loop for i from 0 to 10
232        for x = nil then (cons i x)
233        collect (apply #'format nil "~v@{~A~}" i (reverse x)))
234  ("" "1" "12" "123" "1234" "12345"
235   "123456" "1234567" "12345678" "123456789" "12345678910"))
236
237(deftest formatter.@{.10
238  (let ((fn (formatter "~v@{~A~}")))
239    (loop for i from 0 to 10
240          for x = nil then (cons i x)
241          for rest = (list 'a 'b 'c)
242          collect
243          (with-output-to-string
244            (s)
245            (assert (equal (apply fn s i (append (reverse x) rest)) rest)))))
246  ("" "1" "12" "123" "1234" "12345"
247   "123456" "1234567" "12345678" "123456789" "12345678910"))
248
249(def-format-test format.@{.11
250  "~@{X~:}" nil "X")
251
252(def-format-test format.@{.12
253  "~@{~}" ((formatter "X~AY") 1) "X1Y")
254
255(def-format-test format.@{.13
256  "~v@{~}" (1 (formatter "X") 'foo) "X" 1)
257
258;;; ~:@{
259
260(def-format-test format.\:@{.1
261  (concatenate 'string "~:@{~" (string #\Newline) "~}")
262  nil "")
263
264(def-format-test format.\:@{.2
265  "~:@{~A~}" ('(1 2) '(3) '(4 5 6)) "134")
266
267(def-format-test format.\:@{.3
268  "~:@{(~A ~A)~}" ('(1 2 4) '(3 7) '(4 5 6)) "(1 2)(3 7)(4 5)")
269
270(def-format-test format.\:@{.4
271  "~:@{~}" ("(~A ~A)" '(1 2 4) '(3 7) '(4 5 6)) "(1 2)(3 7)(4 5)")
272
273(def-format-test format.\:@{.5
274  "~:@{~}" ((formatter "(~A ~A)") '(1 2 4) '(3 7) '(4 5 6)) "(1 2)(3 7)(4 5)")
275
276(def-format-test format.\:@.6
277  "~:@{~A~:}" ('(1 A) '(2 B) '(3) '(4 C D)) "1234")
278
279(def-format-test format.\:@.7
280  "~0:@{~A~:}" ('(1 A) '(2 B) '(3) '(4 C D)) "" 4)
281
282(def-format-test format.\:@.8
283  "~#:@{A~:}" (nil nil nil) "AAA")
284
285(def-format-test format.\:@.9
286  "~v:@{~A~}" (nil '(1) '(2) '(3)) "123")
287
288(deftest format.\:@.10
289  (loop for i from 0 to 10
290        for x = nil then (cons (list i) x)
291        collect
292        (apply #'format nil "~V:@{~A~}" i (reverse x)))
293  ("" "1" "12" "123" "1234" "12345" "123456" "1234567" "12345678"
294   "123456789" "12345678910"))
295
296(deftest formatter.\:@.10
297  (let ((fn (formatter "~V@:{~A~}")))
298    (loop for i from 0 to 10
299          for x = nil then (cons (list i) x)
300          for rest = (list 'a 'b)
301          collect
302          (with-output-to-string
303            (s)
304            (assert (equal (apply fn s i (append (reverse x) rest)) rest)))))
305  ("" "1" "12" "123" "1234" "12345" "123456" "1234567" "12345678"
306   "123456789" "12345678910"))
307
308;;; Error tests
309
310(deftest format.{.error.1
311  (signals-type-error x 'A (format nil "~{~A~}" x))
312  t)
313
314(deftest format.{.error.2
315  (signals-type-error x 1 (format nil "~{~A~}" x))
316  t)
317
318(deftest format.{.error.3
319  (signals-type-error x "foo" (format nil "~{~A~}" x))
320  t)
321
322(deftest format.{.error.4
323  (signals-type-error x #*01101 (format nil "~{~A~}" x))
324  t)
325
326(deftest format.{.error.5
327  (signals-error (format nil "~{~A~}" '(x y . z)) type-error)
328  t)
329
330(deftest format.\:{.error.1
331  (signals-error (format nil "~:{~A~}" '(x)) type-error)
332  t)
333
334(deftest format.\:{.error.2
335  (signals-type-error x 'x (format nil "~:{~A~}" x))
336  t)
337 
338(deftest format.\:{.error.3
339  (signals-error (format nil "~:{~A~}" '((x) . y)) type-error)
340  t)
341
342(deftest format.\:{.error.4
343  (signals-error (format nil "~:{~A~}" '("X")) type-error)
344  t)
345
346(deftest format.\:{.error.5
347  (signals-error (format nil "~:{~A~}" '(#(X Y Z))) type-error)
348  t)
349
350(deftest format.\:@{.error.1
351  (signals-type-error x 'x (format nil "~:@{~A~}" x))
352  t)
353
354(deftest format.\:@{.error.2
355  (signals-type-error x 0 (format nil "~:@{~A~}" x))
356  t)
357
358(deftest format.\:@{.error.3
359  (signals-type-error x #*01101 (format nil "~:@{~A~}" x))
360  t)
361
362(deftest format.\:@{.error.4
363  (signals-type-error x "abc" (format nil "~:@{~A~}" x))
364  t)
365
366(deftest format.\:@{.error.5
367  (signals-error (format nil "~:@{~A ~A~}" '(x . y)) type-error)
368  t)
Note: See TracBrowser for help on using the repository browser.