source: trunk/source/tests/ansi-tests/format-conditional.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: 4.4 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Wed Aug 25 19:27:25 2004
4;;;; Contains: Tests of the ~[ ~] forms
5
6(in-package :cl-test)
7
8(compile-and-load "printer-aux.lsp")
9
10(def-format-test format.cond.1
11  "~[~]" (0) "")
12
13(def-format-test format.cond.2
14  "~[a~]" (0) "a")
15
16(def-format-test format.cond.3
17  "~[a~]" (-1) "")
18
19(def-format-test format.cond.4
20  "~[a~]" ((1- most-negative-fixnum)) "")
21
22(def-format-test format.cond.5
23  "~[a~]" (1) "")
24
25(def-format-test format.cond.6
26  "~[a~]" ((1+ most-positive-fixnum)) "")
27
28(deftest format.cond.7
29  (loop for i from -1 to 10
30        collect (format nil "~[a~;b~;c~;d~;e~;f~;g~;h~;i~]" i))
31  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))
32
33(deftest formatter.cond.7
34  (let ((fn (formatter "~[a~;b~;c~;d~;e~;f~;g~;h~;i~]")))
35    (loop for i from -1 to 10
36          collect (formatter-call-to-string fn i)))
37  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))
38
39(def-format-test format.cond.8
40  "~0[a~;b~;c~;d~]" (3) "a" 1)
41
42(def-format-test format.cond.9
43  "~-1[a~;b~;c~;d~]" (3) "" 1)
44
45(def-format-test format.cond.10
46  "~1[a~;b~;c~;d~]" (3) "b" 1)
47
48(def-format-test format.cond.11
49  "~4[a~;b~;c~;d~]" (3) "" 1)
50
51(def-format-test format.cond.12
52  "~100000000000000000000000000000000[a~;b~;c~;d~]" (3) "" 1)
53
54(deftest format.cond.13
55  (loop for i from -1 to 10
56        collect (format nil "~v[a~;b~;c~;d~;e~;f~;g~;h~;i~]" i nil))
57  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))
58
59(deftest formatter.cond.13
60  (let ((fn (formatter "~V[a~;b~;c~;d~;e~;f~;g~;h~;i~]")))
61    (loop for i from -1 to 10
62          collect (formatter-call-to-string fn i)))
63  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))
64
65(deftest format.cond.14
66  (loop for i from -1 to 10
67        collect (format nil "~v[a~;b~;c~;d~;e~;f~;g~;h~;i~]" nil i))
68  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))
69
70(deftest formatter.cond.14
71  (let ((fn (formatter "~v[a~;b~;c~;d~;e~;f~;g~;h~;i~]")))
72    (loop for i from -1 to 10
73          collect (formatter-call-to-string fn nil i)))
74  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))
75
76(def-format-test format.cond.15
77  "~#[A~;B~]" nil "A")
78
79(def-format-test format.cond.16
80  "~#[A~;B~]" (nil) "B" 1)
81
82;;; ~[ .~:;  ~]
83
84(deftest format.cond\:.1
85  (loop for i from -100 to 100
86        for s = (format nil "~[~:;a~]" i)
87        unless (or (zerop i) (string= s "a"))
88        collect (list i s))
89  nil)
90
91(deftest formatter.cond\:.1
92  (let ((fn (formatter "~[~:;a~]")))
93    (loop for i from -100 to 100
94          for s = (formatter-call-to-string fn i)
95          unless (or (zerop i) (string= s "a"))
96          collect (list i s)))
97  nil)
98
99(def-format-test format.cond\:.2
100  "~[a~:;b~]" (0) "a")
101
102(def-format-test format.cond\:.3
103  "~[a~:;b~]" ((1- most-negative-fixnum)) "b")
104
105(def-format-test format.cond\:.4
106  "~[a~:;b~]" ((1+ most-positive-fixnum)) "b")
107
108(deftest format.cond\:.5
109  (loop for i from -1 to 10
110        collect (format nil "~[a~;b~;c~;d~:;e~]" i))
111  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))
112
113(deftest formatter.cond\:.5
114  (let ((fn (formatter "~[a~;b~;c~;d~:;e~]")))
115    (loop for i from -1 to 10
116          collect (formatter-call-to-string fn i)))
117  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))
118
119(deftest format.cond\:.6
120  (loop for i from -1 to 10
121        collect (format nil "~v[a~;b~;c~;d~:;e~]" i nil))
122  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))
123
124(deftest formatter.cond\:.6
125  (let ((fn (formatter "~v[a~;b~;c~;d~:;e~]")))
126    (loop for i from -1 to 10
127          collect (formatter-call-to-string fn i)))
128  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))
129
130(deftest format.cond\:.7
131  (loop for i from -1 to 10
132        collect (format nil "~v[a~;b~;c~;d~:;e~]" nil i))
133  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))
134
135(deftest formatter.cond\:.7
136  (let ((fn (formatter "~v[a~;b~;c~;d~:;e~]")))
137    (loop for i from -1 to 10
138          collect (formatter-call-to-string fn nil i)))
139  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))
140
141(def-format-test format.cond\:.8
142  "~#[A~:;B~]" nil "A")
143
144(def-format-test format.cond\:.9
145  "~#[A~:;B~]" (nil nil) "B" 2)
146
147;;; ~:[...~]
148
149(def-format-test format.\:cond.1
150  "~:[a~;b~]" (nil) "a")
151
152(deftest format.\:cond.2
153  (loop for x in *mini-universe*
154        for s = (format nil "~:[a~;b~]" x)
155        when (and x (not (string= s "b")))
156        collect (list x s))
157  nil)
158
159(deftest formatter.\:cond.2
160  (let ((fn (formatter "~:[a~;b~]")))
161    (loop for x in *mini-universe*
162          for s = (formatter-call-to-string fn x)
163          when (and x (not (string= s "b")))
164          collect (list x s)))
165  nil)
166
167;;; ~@[ ... ~]
168
169(def-format-test format.@cond.1
170  "~@[X~]Y~A" (1) "XY1")
171
172(def-format-test format.@cond.2
173  "~@[X~]Y~A" (nil 2) "Y2")
Note: See TracBrowser for help on using the repository browser.