format-logical-block.lsp 7.53 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Aug  8 12:17:31 2004
;;;; Contains: Tests of the ~< ~:> format directives

(in-package :cl-test)

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

;;; Error cases

;;; Prefix and suffix cannot contain format directives

(deftest format.logical-block.error.1
15 16
  (signals-error-always (format nil "~<foo~A~;~A~;bar~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
17 18

(deftest format.logical-block.error.2
19 20
  (signals-error-always (format nil "~<foo~A~@;~A~;bar~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
21 22

(deftest format.logical-block.error.3
23 24
  (signals-error-always (format nil "~<foo~;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
25 26

(deftest format.logical-block.error.4
27 28
  (signals-error-always (format nil "~<foo~@;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
29 30

(deftest format.logical-block.error.5
31 32
  (signals-error-always (format nil "~<foo~A~;~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
33 34

(deftest format.logical-block.error.6
35 36
  (signals-error-always (format nil "~<foo~A~@;~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
37 38

(deftest format.logical-block.error.7
39 40
  (signals-error-always (format nil "~<~;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
41 42

(deftest format.logical-block.error.8
43 44
  (signals-error-always (format nil "~<~@;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
45 46

(deftest format.logical-block.error.9
47 48
  (signals-error-always (format nil "~:<foo~A~;~A~;bar~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
49 50

(deftest format.logical-block.error.10
51 52
  (signals-error-always (format nil "~:<foo~A~@;~A~;bar~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
53 54

(deftest format.logical-block.error.11
55 56
  (signals-error-always (format nil "~:<foo~;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
57 58

(deftest format.logical-block.error.12
59 60
  (signals-error-always (format nil "~:<foo~@;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
61 62

(deftest format.logical-block.error.13
63 64
  (signals-error-always (format nil "~:<foo~A~;~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
65 66

(deftest format.logical-block.error.14
67 68
  (signals-error-always (format nil "~:<foo~A~@;~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
69 70

(deftest format.logical-block.error.15
71 72
  (signals-error-always (format nil "~:<~;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
73 74

(deftest format.logical-block.error.16
75 76
  (signals-error-always (format nil "~:<~@;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
77 78

(deftest format.logical-block.error.17
79 80
  (signals-error-always (format nil "~@<foo~A~;~A~;bar~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
81 82

(deftest format.logical-block.error.18
83 84
  (signals-error-always (format nil "~@<foo~A~@;~A~;bar~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
85 86

(deftest format.logical-block.error.19
87 88
  (signals-error-always (format nil "~@<foo~;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
89 90

(deftest format.logical-block.error.20
91 92
  (signals-error-always (format nil "~@<foo~@;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
93 94

(deftest format.logical-block.error.21
95 96
  (signals-error-always (format nil "~@<foo~A~;~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
97 98

(deftest format.logical-block.error.22
99 100
  (signals-error-always (format nil "~@<foo~A~@;~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
101 102

(deftest format.logical-block.error.23
103 104
  (signals-error-always (format nil "~@<~;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
105 106

(deftest format.logical-block.error.24
107 108
  (signals-error-always (format nil "~@<~@;~A~;bar~A~:>" '(X) '(Y)) error)
  t t)
pfdietz's avatar
pfdietz committed
109

pfdietz's avatar
pfdietz committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
(deftest format.logical-block.error.25
  (signals-error-always (format nil "1~<X~<Y~:>Z~>2" nil nil nil) error)
  t t)

;;; "an error is also signaled if the ~<...~:;...~> form of ~<...~> is used
;;; in the same format string with ~W, ~_, ~<...~:>, ~I, or ~:T."

(deftest format.logical-block.error.26
  (signals-error-always (format nil "~<~:;~>~<~:>" nil nil nil) error)
  t t)

(deftest format.logical-block.error.27
  (signals-error-always (format nil "~<~:>~<~:;~>" nil nil nil) error)
  t t)

pfdietz's avatar
pfdietz committed
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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
;;; Non-error tests

(def-pprint-test format.logical-block.1
  (format nil "~<~A~:>" '(nil))
  "NIL")

(def-pprint-test format.logical-block.2
  (format nil "~@<~A~:>" nil)
  "NIL")

(def-pprint-test format.logical-block.3
  (format nil "~:<~A~:>" '(nil))
  "(NIL)")

(def-pprint-test format.logical-block.4
  (format nil "~:@<~A~:>" nil)
  "(NIL)")

(def-pprint-test format.logical-block.5
  (format nil "~@:<~A~:>" nil)
  "(NIL)")

(def-pprint-test format.logical-block.6
  (format nil "~<~@{~A~^*~}~:>" '(1 2 3))
  "1*2*3")

(def-pprint-test format.logical-block.7
  (format nil "~:<~@{~A~^*~}~:>" '(1 2 3))
  "(1*2*3)")

(def-pprint-test format.logical-block.8
  (format nil "~:<~@{~A~^*~}~:>" 1)
  "1")

(def-pprint-test format.logical-block.9
  (format nil "~<~;~A~;~:>" '(1 2 3))
  "1")

(def-pprint-test format.logical-block.10
  (format nil "~<~;~A~:>" '(1 2 3))
  "1")

(def-pprint-test format.logical-block.11
  (format nil "~@<~;~A~;~:>" '(1 2 3))
  "(1 2 3)")

(def-pprint-test format.logical-block.12
  (format nil "~@<~;~A~:>" '(1 2 3))
  "(1 2 3)")

(def-pprint-test format.logical-block.13
  (format nil "~:<[~;~@{~A~^/~}~:>" '(1 2 3))
  "[1/2/3)")

(def-pprint-test format.logical-block.14
  (format nil "~:<~;~@{~A~^/~}~;]~:>" '(1 2 3))
  "1/2/3]")

(def-pprint-test format.logical-block.15
  (format nil "~:<[~;~@{~A~^/~}~;]~:>" '(1 2 3))
  "[1/2/3]")

(def-pprint-test format.logical-block.16
  (format nil "~@<~@{~A~^*~}~:>" 1 2 3)
  "1*2*3")

(def-pprint-test format.logical-block.17
  (format nil "~@<~@{~A~^ ~_~}~:>" 1 2 3)
  "1 2 3")

(def-pprint-test format.logical-block.18
  (format nil "~@<~@{~A~^ ~_~}~:>" 1 2 3)
  "1
2
3"
  :margin 2)

(def-pprint-test format.logical-block.19
  (format nil "~:@<~@{~A~^ ~_~}~:>" 1 2 3)
  "(1
 2
 3)"
  :margin 2)

(def-pprint-test format.logical-block.20
  (format nil "~@:<~@{~A~^ ~}~:>" 1 2 3)
  "(1 2 3)"
  :margin 2)

(def-pprint-test format.logical-block.21
  (format nil "~@:<~@{~A~^ ~:_~}~:>" 1 2 3)
  "(1
 2
 3)"
  :margin 2)

(def-pprint-test format.logical-block.22
  (format nil "~:@<~@{~A~^ ~}~:@>" 1 2 3)
  "(1
 2
 3)"
  :margin 2)

(def-pprint-test format.logical-block.23
  (format nil "~:@<~@{~A~^/~
                   ~}~:@>" 1 2 3)
  "(1/2/3)"
  :margin 2)

(def-pprint-test format.logical-block.24
  (format nil "~:@<~@{~A~^            ~:_~}~:>" 1 2 3)
  "(1
 2
 3)"
  :margin 2)

(def-pprint-test format.logical-block.25
  (format nil "~:@<~@{~A~^            ~}~:@>" 1 2 3)
  "(1
 2
 3)"
  :margin 2)

248 249 250 251 252
(def-pprint-test format.logical-block.26
  (format nil "~:@<~@{~A~^~}~:@>" "1 2 3")
  "(1 2 3)"
  :margin 2)

253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
(def-pprint-test format.logical-block.27
  (format nil "~@<**~@;~@{~A~^       ~}~:@>" 1 2 3)
  "**1
**2
**3"
  :margin 3)

(def-pprint-test format.logical-block.28
  (format nil "~@<**~@;~@{~A~^       ~}~;XX~:@>" 1 2 3)
  "**1
**2
**3XX"
  :margin 3)

(def-pprint-test format.logical-block.29
  (format nil "~:@<**~@;~@{~A~^       ~}~:@>" 1 2 3)
  "**1
**2
**3)"
  :margin 3)


pfdietz's avatar
pfdietz committed
275 276
;;; Circularity detection

277
(def-pprint-test format.logical-block.circle.1
pfdietz's avatar
pfdietz committed
278 279 280 281
  (format nil "~:<~@{~A~^ ~}~:>" (let ((x (list 0))) (list x x)))
  "(#1=(0) #1#)"
  :circle t)

282
(def-pprint-test format.logical-block.circle.2
pfdietz's avatar
pfdietz committed
283 284 285 286
  (format nil "~:<~@{~A~^ ~}~:>" (let ((x (list 0))) (cons x x)))
  "(#1=(0) . #1#)"
  :circle t)

287
(def-pprint-test format.logical-block.circle.3
pfdietz's avatar
pfdietz committed
288
  (format nil "~:<~@{~A~^ ~}~:>" (let ((x (list 0)))
sds's avatar
sds committed
289 290
                                   (setf (cdr x) x)
                                   x))
pfdietz's avatar
pfdietz committed
291
  "#1=(0 . #1#)"
292
  :circle t
pfdietz's avatar
pfdietz committed
293
  :len 500)
pfdietz's avatar
pfdietz committed
294

295
(def-pprint-test format.logical-block.circle.4
pfdietz's avatar
pfdietz committed
296 297 298
  (format nil "~:<~@{~A~^ ~}~:>" (let ((x (list 0))) (list x x)))
  "((0) (0))")

299
(def-pprint-test format.logical-block.circle.5
pfdietz's avatar
pfdietz committed
300 301
  (format nil "~:<~@{~A~^ ~}~:>" (let ((x (list 0))) (cons x x)))
  "((0) 0)")
pfdietz's avatar
pfdietz committed
302 303 304 305 306 307 308 309 310 311

;;; ~^ terminates a logical block

(def-pprint-test format.logical-block.escape.1
  (format nil "~<~A~^xxxx~:>" '(1))
  "1")

(def-pprint-test format.logical-block.escape.2
  (format nil "~<~<~A~^xxx~:>yyy~:>" '((1)))
  "1yyy")