/[gcl]/gcl/ansi-tests/format-d.lsp
ViewVC logotype

Diff of /gcl/ansi-tests/format-d.lsp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by pfdietz, Sat Nov 27 19:36:18 2004 UTC revision 1.3 by pfdietz, Mon Dec 6 14:04:21 2004 UTC
# Line 21  Line 21 
21           collect (list i s1 j)))           collect (list i s1 j)))
22    nil)    nil)
23    
24    (deftest formatter.d.1
25      (let ((fn (formatter "~D")))
26        (with-standard-io-syntax
27         (loop for x = (ash 1 (+ 2 (random 80)))
28               for i = (- (random (+ x x)) x)
29               for s1 = (formatter-call-to-string fn i)
30               for j = (read-from-string s1)
31               repeat 1000
32               when (or (/= i j)
33                        (find #\. s1)
34                        (find #\+ s1)
35                        (find-if #'alpha-char-p s1))
36               collect (list i s1 j))))
37      nil)
38    
39  (deftest format.d.2  (deftest format.d.2
40    (with-standard-io-syntax    (with-standard-io-syntax
41     (loop for x = (ash 1 (+ 2 (random 80)))     (loop for x = (ash 1 (+ 2 (random 80)))
# Line 35  Line 50 
50           collect (list i s1 j)))           collect (list i s1 j)))
51    nil)    nil)
52    
53    (deftest formatter.d.2
54      (let ((fn (formatter "~@D")))
55        (with-standard-io-syntax
56         (loop for x = (ash 1 (+ 2 (random 80)))
57               for i = (- (random (+ x x)) x)
58               for s1 = (formatter-call-to-string fn i)
59               for j = (read-from-string s1)
60               repeat 1000
61               when (or (/= i j)
62                        (find #\. s1)
63                        ;; (find #\+ s1)
64                        (find-if #'alpha-char-p s1))
65               collect (list i s1 j))))
66      nil)
67    
68  (deftest format.d.3  (deftest format.d.3
69    (with-standard-io-syntax    (with-standard-io-syntax
70     (loop for x = (ash 1 (+ 2 (random 80)))     (loop for x = (ash 1 (+ 2 (random 80)))
# Line 52  Line 82 
82           collect (list i mincol s1 s2 pos)))           collect (list i mincol s1 s2 pos)))
83    nil)    nil)
84    
85    (deftest formatter.d.3
86      (with-standard-io-syntax
87       (loop for x = (ash 1 (+ 2 (random 80)))
88             for mincol = (random 30)
89             for i = (- (random (+ x x)) x)
90             for s1 = (format nil "~d" i)
91             for format-string = (format nil "~~~dd" mincol)
92             ; for s2 = (format nil format-string i)
93             for fn = (eval `(formatter ,format-string))
94             for s2 = (formatter-call-to-string fn i)
95             for pos = (search s1 s2)
96             repeat 100
97             when (or (null pos)
98                      (and (> mincol (length s1))
99                           (or (/= (length s2) mincol)
100                               (not (eql (position #\Space s2 :test-not #'eql)
101                                         (- (length s2) (length s1)))))))
102             collect (list i mincol s1 s2 pos)))
103      nil)
104    
105  (deftest format.d.4  (deftest format.d.4
106    (with-standard-io-syntax    (with-standard-io-syntax
107     (loop for x = (ash 1 (+ 2 (random 80)))     (loop for x = (ash 1 (+ 2 (random 80)))
# Line 70  Line 120 
120           collect (list i mincol s1 s2 pos)))           collect (list i mincol s1 s2 pos)))
121    nil)    nil)
122    
123  (deftest format.d.5  (deftest formatter.d.4
124    (with-standard-io-syntax    (with-standard-io-syntax
125     (loop for x = (ash 1 (+ 2 (random 80)))     (loop for x = (ash 1 (+ 2 (random 80)))
126           for mincol = (random 30)           for mincol = (random 30)
          for padchar = (random-from-seq +standard-chars+)  
127           for i = (- (random (+ x x)) x)           for i = (- (random (+ x x)) x)
128           for s1 = (format nil "~d" i)           for s1 = (format nil "~@D" i)
129           for s2 = (format nil (format nil "~~~d,'~cd" mincol padchar) i)           for format-string = (format nil "~~~d@d" mincol)
130             for fn = (eval `(formatter ,format-string))
131             for s2 = (formatter-call-to-string fn i)
132           for pos = (search s1 s2)           for pos = (search s1 s2)
133           repeat 1000           repeat 100
134           when (or (null pos)           when (or (null pos)
135                      (and (>= i 0) (not (eql (elt s1 0) #\+)))
136                    (and (> mincol (length s1))                    (and (> mincol (length s1))
137                         (or (/= (length s2) mincol)                         (or (/= (length s2) mincol)
138                             (find padchar s2 :end (- (length s2) (length s1))                             (not (eql (position #\Space s2 :test-not #'eql)
139                                   :test-not #'eql))))                                       (- (length s2) (length s1)))))))
140           collect (list i mincol s1 s2 pos)))           collect (list i mincol s1 s2 pos)))
141    nil)    nil)
142    
143  (deftest format.d.6  (deftest format.d.5
144    (with-standard-io-syntax    (with-standard-io-syntax
145     (loop for x = (ash 1 (+ 2 (random 80)))     (loop for x = (ash 1 (+ 2 (random 80)))
146           for mincol = (random 30)           for mincol = (random 30)
147           for padchar = (random-from-seq +standard-chars+)           for padchar = (random-from-seq +standard-chars+)
148           for i = (- (random (+ x x)) x)           for i = (- (random (+ x x)) x)
149           for s1 = (format nil "~d" i)           for s1 = (format nil "~d" i)
150           for s2 = (format nil "~v,vD" mincol padchar i)           for s2 = (format nil (format nil "~~~d,'~cd" mincol padchar) i)
151           for pos = (search s1 s2)           for pos = (search s1 s2)
152           repeat 1000           repeat 1000
153           when (or (null pos)           when (or (null pos)
# Line 106  Line 158 
158           collect (list i mincol s1 s2 pos)))           collect (list i mincol s1 s2 pos)))
159    nil)    nil)
160    
161  (deftest format.d.7  (deftest formatter.d.5
162    (with-standard-io-syntax    (with-standard-io-syntax
163     (loop for x = (ash 1 (+ 2 (random 80)))     (loop for x = (ash 1 (+ 2 (random 80)))
164           for mincol = (random 30)           for mincol = (random 30)
165           for padchar = (random-from-seq +standard-chars+)           for padchar = (random-from-seq +standard-chars+)
166           for i = (- (random (+ x x)) x)           for i = (- (random (+ x x)) x)
167           for s1 = (format nil "~@d" i)           for s1 = (format nil "~d" i)
168           for s2 = (format nil "~v,v@d" mincol padchar i)           for format-string = (format nil "~~~d,'~cd" mincol padchar)
169             for fn = (eval `(formatter ,format-string))
170             for s2 = (formatter-call-to-string fn i)
171           for pos = (search s1 s2)           for pos = (search s1 s2)
172           repeat 1000           repeat 100
173           when (or (null pos)           when (or (null pos)
                   (and (>= i 0) (not (eql (elt s1 0) #\+)))  
174                    (and (> mincol (length s1))                    (and (> mincol (length s1))
175                         (or (/= (length s2) mincol)                         (or (/= (length s2) mincol)
176                             (find padchar s2 :end (- (length s2) (length s1))                             (find padchar s2 :end (- (length s2) (length s1))
# Line 125  Line 178 
178           collect (list i mincol s1 s2 pos)))           collect (list i mincol s1 s2 pos)))
179    nil)    nil)
180    
181    (deftest format.d.6
182      (let ((fn (formatter "~v,vd")))
183        (with-standard-io-syntax
184         (loop for x = (ash 1 (+ 2 (random 80)))
185               for mincol = (random 30)
186               for padchar = (random-from-seq +standard-chars+)
187               for i = (- (random (+ x x)) x)
188               for s1 = (format nil "~d" i)
189               for s2 = (format nil "~v,vD" mincol padchar i)
190               for s3 = (formatter-call-to-string fn mincol padchar i)
191               for pos = (search s1 s2)
192               repeat 1000
193               when (or (null pos)
194                        (not (string= s2 s3))
195                        (and (> mincol (length s1))
196                             (or (/= (length s2) mincol)
197                                 (find padchar s2 :end (- (length s2) (length s1))
198                                       :test-not #'eql))))
199               collect (list i mincol s1 s2 s3 pos))))
200      nil)
201    
202    (deftest format.d.7
203      (let ((fn (formatter "~v,v@D")))
204        (with-standard-io-syntax
205         (loop for x = (ash 1 (+ 2 (random 80)))
206               for mincol = (random 30)
207               for padchar = (random-from-seq +standard-chars+)
208               for i = (- (random (+ x x)) x)
209               for s1 = (format nil "~@d" i)
210               for s2 = (format nil "~v,v@d" mincol padchar i)
211               for s3 = (formatter-call-to-string fn mincol padchar i)
212               for pos = (search s1 s2)
213               repeat 1000
214               when (or (null pos)
215                        (not (string= s2 s3))
216                        (and (>= i 0) (not (eql (elt s1 0) #\+)))
217                        (and (> mincol (length s1))
218                             (or (/= (length s2) mincol)
219                                 (find padchar s2 :end (- (length s2) (length s1))
220                                       :test-not #'eql))))
221               collect (list i mincol s1 s2 pos))))
222      nil)
223    
224  ;;; Comma tests  ;;; Comma tests
225    
226  (deftest format.d.8  (deftest format.d.8
227    (loop for i from -999 to 999    (let ((fn1 (formatter "~d"))
228          for s1 = (format nil "~d" i)          (fn2 (formatter "~:d")))
229          for s2 = (format nil "~:d" i)      (loop for i from -999 to 999
230          unless (string= s1 s2)            for s1 = (format nil "~d" i)
231          collect (list i s1 s2))            for s2 = (format nil "~:d" i)
232              for s3 = (formatter-call-to-string fn1 i)
233              for s4 = (formatter-call-to-string fn2 i)
234              unless (and (string= s1 s2) (string= s1 s3) (string= s1 s4))
235              collect (list i s1 s2 s3 s4)))
236    nil)    nil)
237    
238  (deftest format.d.9  (deftest format.d.9
239    (with-standard-io-syntax    (let ((fn1 (formatter "~d"))
240     (loop for x = (ash 1 (+ 2 (random 80)))          (fn2 (formatter "~:d")))
241           for i = (- (random (+ x x)) x)      (with-standard-io-syntax
242           for commachar = #\,       (loop for x = (ash 1 (+ 2 (random 80)))
243           for s1 = (format nil "~d" i)             for i = (- (random (+ x x)) x)
244           for s2 = (format nil "~:d" i)             for commachar = #\,
245           repeat 1000             for s1 = (format nil "~d" i)
246           unless (and (string= s1 (remove commachar s2))             for s2 = (format nil "~:d" i)
247                       (not (eql (elt s2 0) commachar))             for s3 = (formatter-call-to-string fn1 i)
248                       (or (>= i 0) (not (eql (elt s2 1) commachar)))             for s4 = (formatter-call-to-string fn2 i)
249                       (let ((len (length s2))             repeat 1000
250                             (ci+1 4))             unless (and (string= s1 s3)
251                         (loop for i from (if (< i 0) 2 1) below len                         (string= s2 s4)
252                               always (if (= (mod (- len i) ci+1) 0)                         (string= s1 (remove commachar s2))
253                                          (eql (elt s2 i) commachar)                         (not (eql (elt s2 0) commachar))
254                                        (find (elt s2 i) "0123456789")))))                         (or (>= i 0) (not (eql (elt s2 1) commachar)))
255           collect (list x i commachar s1 s2)))                         (let ((len (length s2))
256                                 (ci+1 4))
257                             (loop for i from (if (< i 0) 2 1) below len
258                                   always (if (= (mod (- len i) ci+1) 0)
259                                              (eql (elt s2 i) commachar)
260                                            (find (elt s2 i) "0123456789")))))
261               collect (list x i commachar s1 s2 s3 s4))))
262    nil)    nil)
263    
264  (deftest format.d.10  (deftest format.d.10
265      (let ((fn (formatter "~,,v:d")))
266        (with-standard-io-syntax
267         (loop for x = (ash 1 (+ 2 (random 80)))
268               for i = (- (random (+ x x)) x)
269               for commachar = (random-from-seq +standard-chars+)
270               for s1 = (format nil "~d" i)
271               for s2 = (format nil "~,,v:d" commachar i)
272               for s3 = (formatter-call-to-string fn commachar i)
273               repeat 1000
274               unless (and
275                       (string= s2 s3)
276                       (eql (elt s1 0) (elt s2 0))
277                       (if (< i 0) (eql (elt s1 1) (elt s2 1)) t)
278                       (let ((len (length s2))
279                             (ci+1 4)
280                             (j (if (< i 0) 1 0)))
281                         (loop for i from (if (< i 0) 2 1) below len
282                               always (if (= (mod (- len i) ci+1) 0)
283                                          (eql (elt s2 i) commachar)
284                                        (eql (elt s1 (incf j)) (elt s2 i))))))
285               collect (list x i commachar s1 s2 s3))))
286      nil)
287    
288    (deftest format.d.11
289    (with-standard-io-syntax    (with-standard-io-syntax
290     (loop for x = (ash 1 (+ 2 (random 80)))     (loop for x = (ash 1 (+ 2 (random 80)))
291           for i = (- (random (+ x x)) x)           for i = (- (random (+ x x)) x)
292           for commachar = (random-from-seq +standard-chars+)           for commachar = (random-from-seq +standard-chars+)
293           for s1 = (format nil "~d" i)           for s1 = (format nil "~d" i)
294           for s2 = (format nil "~,,v:d" commachar i)           for format-string = (format nil "~~,,'~c:d" commachar)
295             for s2 = (format nil format-string i)
296           repeat 1000           repeat 1000
297           unless (and           unless (and
298                   (eql (elt s1 0) (elt s2 0))                   (eql (elt s1 0) (elt s2 0))
# Line 176  Line 307 
307           collect (list x i commachar s1 s2)))           collect (list x i commachar s1 s2)))
308    nil)    nil)
309    
310  (deftest format.d.11  (deftest formatter.d.11
311    (with-standard-io-syntax    (with-standard-io-syntax
312     (loop for x = (ash 1 (+ 2 (random 80)))     (loop for x = (ash 1 (+ 2 (random 80)))
313           for i = (- (random (+ x x)) x)           for i = (- (random (+ x x)) x)
314           for commachar = (random-from-seq +standard-chars+)           for commachar = (random-from-seq +standard-chars+)
315           for s1 = (format nil "~d" i)           for s1 = (format nil "~d" i)
316           for s2 = (format nil (format nil "~~,,'~c:d" commachar) i)           for format-string = (format nil "~~,,'~c:d" commachar)
317           repeat 1000           for fn = (eval `(formatter ,format-string))
318             ; for s2 = (format nil format-string i)
319             for s2 = (formatter-call-to-string fn i)
320             repeat 100
321           unless (and           unless (and
322                   (eql (elt s1 0) (elt s2 0))                   (eql (elt s1 0) (elt s2 0))
323                   (if (< i 0) (eql (elt s1 1) (elt s2 1)) t)                   (if (< i 0) (eql (elt s1 1) (elt s2 1)) t)
# Line 198  Line 332 
332    nil)    nil)
333    
334  (deftest format.d.12  (deftest format.d.12
335    (with-standard-io-syntax    (let ((fn (formatter "~,,v,v:d")))
336     (loop for x = (ash 1 (+ 2 (random 80)))      (with-standard-io-syntax
337           for i = (- (random (+ x x)) x)       (loop for x = (ash 1 (+ 2 (random 80)))
338           for commachar = (random-from-seq +standard-chars+)             for i = (- (random (+ x x)) x)
339           for commaint = (1+ (random 20))             for commachar = (random-from-seq +standard-chars+)
340           for s1 = (format nil "~d" i)             for commaint = (1+ (random 20))
341           for s2 = (format nil "~,,v,v:D" commachar commaint i)             for s1 = (format nil "~d" i)
342           repeat 1000             for s2 = (format nil "~,,v,v:D" commachar commaint i)
343           unless (and             for s3 = (formatter-call-to-string fn commachar commaint i)
344                   (eql (elt s1 0) (elt s2 0))             repeat 1000
345                   (if (< i 0) (eql (elt s1 1) (elt s2 1)) t)             unless (and
346                   (let ((len (length s2))                     (string= s2 s3)
347                         (ci+1 (1+ commaint))                     (eql (elt s1 0) (elt s2 0))
348                         (j (if (< i 0) 1 0)))                     (if (< i 0) (eql (elt s1 1) (elt s2 1)) t)
349                     (loop for i from (if (< i 0) 2 1) below len                     (let ((len (length s2))
350                           always (if (= (mod (- len i) ci+1) 0)                           (ci+1 (1+ commaint))
351                                      (eql (elt s2 i) commachar)                           (j (if (< i 0) 1 0)))
352                                    (eql (elt s1 (incf j)) (elt s2 i))))))                       (loop for i from (if (< i 0) 2 1) below len
353           collect (list x i commachar s1 s2)))                             always (if (= (mod (- len i) ci+1) 0)
354                                          (eql (elt s2 i) commachar)
355                                        (eql (elt s1 (incf j)) (elt s2 i))))))
356               collect (list x i commachar s1 s2 s3))))
357    nil)    nil)
358    
359  (deftest format.d.13  (deftest format.d.13
360    (with-standard-io-syntax    (let ((fn (formatter "~,,v,v:@D")))
361     (loop for x = (ash 1 (+ 2 (random 80)))      (with-standard-io-syntax
362           for i = (- (random (+ x x)) x)       (loop for x = (ash 1 (+ 2 (random 80)))
363           for commachar = (random-from-seq +standard-chars+)             for i = (- (random (+ x x)) x)
364           for commaint = (1+ (random 20))             for commachar = (random-from-seq +standard-chars+)
365           for s1 = (format nil "~@d" i)             for commaint = (1+ (random 20))
366           for s2 = (format nil "~,,v,v:@d" commachar commaint i)             for s1 = (format nil "~@d" i)
367           repeat 1000             for s2 = (format nil "~,,v,v:@d" commachar commaint i)
368           unless (and             for s3 = (formatter-call-to-string fn commachar commaint i)
369                   (eql (elt s1 0) (elt s2 0))             repeat 1000
370                   (eql (elt s1 1) (elt s2 1))             unless (and
371                   (let ((len (length s2))                     (eql (elt s1 0) (elt s2 0))
372                         (ci+1 (1+ commaint))                     (eql (elt s1 1) (elt s2 1))
373                         (j 1))                     (let ((len (length s2))
374                     (loop for i from 2 below len                           (ci+1 (1+ commaint))
375                           always (if (= (mod (- len i) ci+1) 0)                           (j 1))
376                                      (eql (elt s2 i) commachar)                       (loop for i from 2 below len
377                                    (eql (elt s1 (incf j)) (elt s2 i))))))                             always (if (= (mod (- len i) ci+1) 0)
378           collect (list x i commachar s1 s2)))                                        (eql (elt s2 i) commachar)
379                                        (eql (elt s1 (incf j)) (elt s2 i))))))
380               collect (list x i commachar s1 s2 s3))))
381    nil)    nil)
382    
383  ;;; NIL arguments  ;;; NIL arguments
# Line 315  Line 454 
454    "     12345"    "     12345"
455    "      12345")    "      12345")
456    
457    (deftest formatter.d.22
458      (apply
459       #'values
460       (let ((fn (formatter "~#D")))
461         (loop for i from 0 to 10
462               for args = (make-list i)
463               ; for s = (apply #'format nil "~#d" 12345 args)
464               for s = (with-output-to-string
465                         (stream)
466                         (assert (equal (apply fn stream 12345 args) args)))
467               collect s)))
468      "12345"
469      "12345"
470      "12345"
471      "12345"
472      "12345"
473      " 12345"
474      "  12345"
475      "   12345"
476      "    12345"
477      "     12345"
478      "      12345")
479    
480  (deftest format.d.23  (deftest format.d.23
481    (apply    (apply
482     #'values     #'values
483     (loop for i from 0 to 10     (let ((fn (formatter "~,,,#:D")))
484           for args = (make-list i)       (loop for i from 0 to 10
485           for s = (apply #'format nil "~,,,#:d" 1234567890 args)             for args = (make-list i)
486           collect s))             for s = (apply #'format nil "~,,,#:d" 1234567890 args)
487               for s2 = (with-output-to-string
488                          (stream)
489                          (assert (equal (apply fn stream 1234567890 args) args)))
490               do (assert (string= s s2))
491               collect s)))
492    "1,2,3,4,5,6,7,8,9,0"    "1,2,3,4,5,6,7,8,9,0"
493    "12,34,56,78,90"    "12,34,56,78,90"
494    "1,234,567,890"    "1,234,567,890"
# Line 337  Line 504 
504  (deftest format.d.24  (deftest format.d.24
505    (apply    (apply
506     #'values     #'values
507     (loop for i from 0 to 10     (let ((fn (formatter "~,,,#:@d")))
508           for args = (make-list i)       (loop for i from 0 to 10
509           for s = (apply #'format nil "~,,,#@:D" 1234567890 args)             for args = (make-list i)
510           collect s))             for s = (apply #'format nil "~,,,#@:D" 1234567890 args)
511               for s2 = (with-output-to-string
512                          (stream)
513                          (assert (equal (apply fn stream 1234567890 args) args)))
514               do (assert (string= s s2))
515               collect s)))
516    "+1,2,3,4,5,6,7,8,9,0"    "+1,2,3,4,5,6,7,8,9,0"
517    "+12,34,56,78,90"    "+12,34,56,78,90"
518    "+1,234,567,890"    "+1,234,567,890"
# Line 371  Line 543 
543  ;;; Randomized test  ;;; Randomized test
544    
545  (deftest format.d.30  (deftest format.d.30
546    (loop    (let ((fn (formatter "~v,v,v,vD")))
547     for mincol = (and (coin) (random 50))      (loop
548     for padchar = (and (coin)       for mincol = (and (coin) (random 50))
549                        (random-from-seq +standard-chars+))       for padchar = (and (coin)
    for commachar = (and (coin)  
550                          (random-from-seq +standard-chars+))                          (random-from-seq +standard-chars+))
551     for commaint = (and (coin) (1+ (random 10)))       for commachar = (and (coin)
552     for k = (ash 1 (+ 2 (random 30)))                            (random-from-seq +standard-chars+))
553     for x = (- (random (+ k k)) k)       for commaint = (and (coin) (1+ (random 10)))
554     for fmt = (concatenate       for k = (ash 1 (+ 2 (random 30)))
555                'string       for x = (- (random (+ k k)) k)
556                (if mincol (format nil "~~~d," mincol) "~,")       for fmt = (concatenate
557                (if padchar (format nil "'~c," padchar) ",")                  'string
558                (if commachar (format nil "'~c," commachar) ",")                  (if mincol (format nil "~~~d," mincol) "~,")
559                (if commaint (format nil "~dd" commaint) "d"))                  (if padchar (format nil "'~c," padchar) ",")
560     for s1 = (format nil fmt x)                  (if commachar (format nil "'~c," commachar) ",")
561     for s2 = (format nil "~v,v,v,vd" mincol padchar commachar commaint x)                  (if commaint (format nil "~dd" commaint) "d"))
562     repeat 2000       for s1 = (format nil fmt x)
563     unless (string= s1 s2)       for s2 = (format nil "~v,v,v,vd" mincol padchar commachar commaint x)
564     collect (list mincol padchar commachar commaint fmt x s1 s2))       for s3 = (formatter-call-to-string fn mincol padchar commachar commaint x)
565         repeat 2000
566         unless (and (string= s1 s2) (string= s2 s3))
567         collect (list mincol padchar commachar commaint fmt x s1 s2 s3)))
568    nil)    nil)

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26