File: format-conditional.lsp

package info (click to toggle)
cl-ansi-tests 20071218-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,000 kB
  • ctags: 22,025
  • sloc: lisp: 134,798; makefile: 144
file content (173 lines) | stat: -rw-r--r-- 4,532 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed Aug 25 19:27:25 2004
;;;; Contains: Tests of the ~[ ~] forms

(in-package :cl-test)

(compile-and-load "printer-aux.lsp")

(def-format-test format.cond.1
  "~[~]" (0) "")

(def-format-test format.cond.2
  "~[a~]" (0) "a")

(def-format-test format.cond.3
  "~[a~]" (-1) "")

(def-format-test format.cond.4
  "~[a~]" ((1- most-negative-fixnum)) "")

(def-format-test format.cond.5
  "~[a~]" (1) "")

(def-format-test format.cond.6
  "~[a~]" ((1+ most-positive-fixnum)) "")

(deftest format.cond.7
  (loop for i from -1 to 10
	collect (format nil "~[a~;b~;c~;d~;e~;f~;g~;h~;i~]" i))
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

(deftest formatter.cond.7
  (let ((fn (formatter "~[a~;b~;c~;d~;e~;f~;g~;h~;i~]")))
    (loop for i from -1 to 10
	  collect (formatter-call-to-string fn i)))
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

(def-format-test format.cond.8
  "~0[a~;b~;c~;d~]" (3) "a" 1)

(def-format-test format.cond.9
  "~-1[a~;b~;c~;d~]" (3) "" 1)

(def-format-test format.cond.10
  "~1[a~;b~;c~;d~]" (3) "b" 1)

(def-format-test format.cond.11
  "~4[a~;b~;c~;d~]" (3) "" 1)

(def-format-test format.cond.12
  "~100000000000000000000000000000000[a~;b~;c~;d~]" (3) "" 1)

(deftest format.cond.13
  (loop for i from -1 to 10
	collect (format nil "~v[a~;b~;c~;d~;e~;f~;g~;h~;i~]" i nil))
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

(deftest formatter.cond.13
  (let ((fn (formatter "~V[a~;b~;c~;d~;e~;f~;g~;h~;i~]")))
    (loop for i from -1 to 10
	  collect (formatter-call-to-string fn i)))
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

(deftest format.cond.14
  (loop for i from -1 to 10
	collect (format nil "~v[a~;b~;c~;d~;e~;f~;g~;h~;i~]" nil i))
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

(deftest formatter.cond.14
  (let ((fn (formatter "~v[a~;b~;c~;d~;e~;f~;g~;h~;i~]")))
    (loop for i from -1 to 10
	  collect (formatter-call-to-string fn nil i)))
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

(def-format-test format.cond.15
  "~#[A~;B~]" nil "A")

(def-format-test format.cond.16
  "~#[A~;B~]" (nil) "B" 1)

;;; ~[ .~:;  ~]

(deftest format.cond\:.1
  (loop for i from -100 to 100
	for s = (format nil "~[~:;a~]" i)
	unless (or (zerop i) (string= s "a"))
	collect (list i s))
  nil)

(deftest formatter.cond\:.1
  (let ((fn (formatter "~[~:;a~]")))
    (loop for i from -100 to 100
	  for s = (formatter-call-to-string fn i)
	  unless (or (zerop i) (string= s "a"))
	  collect (list i s)))
  nil)

(def-format-test format.cond\:.2
  "~[a~:;b~]" (0) "a")

(def-format-test format.cond\:.3
  "~[a~:;b~]" ((1- most-negative-fixnum)) "b")

(def-format-test format.cond\:.4
  "~[a~:;b~]" ((1+ most-positive-fixnum)) "b")

(deftest format.cond\:.5
  (loop for i from -1 to 10
	collect (format nil "~[a~;b~;c~;d~:;e~]" i))
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

(deftest formatter.cond\:.5
  (let ((fn (formatter "~[a~;b~;c~;d~:;e~]")))
    (loop for i from -1 to 10
	  collect (formatter-call-to-string fn i)))
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

(deftest format.cond\:.6
  (loop for i from -1 to 10
	collect (format nil "~v[a~;b~;c~;d~:;e~]" i nil))
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

(deftest formatter.cond\:.6
  (let ((fn (formatter "~v[a~;b~;c~;d~:;e~]")))
    (loop for i from -1 to 10
	  collect (formatter-call-to-string fn i)))
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

(deftest format.cond\:.7
  (loop for i from -1 to 10
	collect (format nil "~v[a~;b~;c~;d~:;e~]" nil i))
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

(deftest formatter.cond\:.7
  (let ((fn (formatter "~v[a~;b~;c~;d~:;e~]")))
    (loop for i from -1 to 10
	  collect (formatter-call-to-string fn nil i)))
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

(def-format-test format.cond\:.8
  "~#[A~:;B~]" nil "A")

(def-format-test format.cond\:.9
  "~#[A~:;B~]" (nil nil) "B" 2)

;;; ~:[...~]

(def-format-test format.\:cond.1
  "~:[a~;b~]" (nil) "a")

(deftest format.\:cond.2
  (loop for x in *mini-universe*
	for s = (format nil "~:[a~;b~]" x)
	when (and x (not (string= s "b")))
	collect (list x s))
  nil)

(deftest formatter.\:cond.2
  (let ((fn (formatter "~:[a~;b~]")))
    (loop for x in *mini-universe*
	  for s = (formatter-call-to-string fn x)
	  when (and x (not (string= s "b")))
	  collect (list x s)))
  nil)

;;; ~@[ ... ~]

(def-format-test format.@cond.1
  "~@[X~]Y~A" (1) "XY1")

(def-format-test format.@cond.2
  "~@[X~]Y~A" (nil 2) "Y2")