format-underscore.lsp 6.67 KB
Newer Older
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
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed Aug  4 03:36:50 2004
;;;; Contains: Tests of the ~_ format directive

(in-package :cl-test)

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

(def-ppblock-test format._.1
  (progn
    (dotimes (i 2) (write "A ") (pprint-newline :fill))
    ;; (write "B ") (pprint-newline :linear)
    (format t "B ~_")
    (dotimes (i 3) (write "A ") (pprint-newline :fill)))
  "A A B
A A A "
  :margin 10)

(def-ppblock-test format._.2
  (progn
   (dotimes (i 2) (write "A ") (pprint-newline :fill))
   ;; (write "B ") (pprint-newline :linear)
   (format t "B ~_")
   (dotimes (i 2) (write "C ") (pprint-newline :fill))
   (format t "D ~_")
   (dotimes (i 3) (write "A ") (pprint-newline :fill)))
  "A A B
C C D
A A A "
  :margin 10)

(def-ppblock-test format._.3
  (format t "A ~_A ~_A ~_A ~_")
  "A A A A "
  :margin 10)

(def-ppblock-test format._.4
  (format t "A ~_A ~_A ~_A ~_")
  "A A A A "
  :margin 10
  :miser 10)

(def-ppblock-test format._.5
  (format t "A ~_A ~_A ~_A ~_A ~_A ~_A ~_A ~_A ~_A ~_")
  "A A A A A A A A A A "
  :margin 10
  :pretty nil)

(def-ppblock-test format._.6
  (dotimes (i 4) (format t "A             ~_"))
  "A
A
A
A
"
  :margin 10)

(def-ppblock-test format._.7
  (format t "A ~_A ~_A ~_A ~_~%A ~_A ~_A ~_A ~_")
  "A
A
A
A

A
A
A
A
"
  :margin 10)

(def-ppblock-test format._.8
  (progn
    (pprint-logical-block (*standard-output* nil)
sds's avatar
sds committed
76
                          (format t "A ~_A ~_A ~_A ~_"))
77 78
    (format t "~_")
    (pprint-logical-block (*standard-output* nil)
sds's avatar
sds committed
79
                          (format t "A ~_A ~_A ~_A ~_")))
80 81 82 83 84
  "A A A A
A A A A "
  :margin 10)

(deftest format._.9
85 86 87 88
  (with-output-to-string
    (s)
    (with-standard-io-syntax
     (let ((*print-readably* nil)
sds's avatar
sds committed
89 90 91 92
           (*print-escape* nil)
           (*print-pretty* t)
           (*print-right-margin* 4)
           (*print-miser-width* nil))
93
       (format s "A ~_A ~_A ~_A ~_A ~_"))))
94 95
  "A A A A A ")

pfdietz's avatar
pfdietz committed
96 97 98
(deftest formatter._.9
  (with-standard-io-syntax
   (let ((*print-readably* nil)
sds's avatar
sds committed
99 100 101 102
         (*print-escape* nil)
         (*print-pretty* t)
         (*print-right-margin* 4)
         (*print-miser-width* nil))
pfdietz's avatar
pfdietz committed
103 104 105 106
     (formatter-call-to-string
      (formatter "A ~_A ~_A ~_A ~_A ~_"))))
  "A A A A A ")

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 174 175 176 177 178 179 180 181 182 183 184 185 186 187
;;; miser

(def-ppblock-test format.@_.1
  (format t "A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_")
  "A A A A A A A A A A "
  :margin 10)

(def-ppblock-test format.@_.2
  (format t "A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_")
  "A A A A A A A A A A "
  :margin 10
  :miser 0)

(def-ppblock-test format.@_.3
  (format t "A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_")
  "A A A A A A A A A A "
  :margin 10
  :miser 9)

(def-ppblock-test format.@_.4
  (format t "A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_")
  "A
A
A
A
A
A
A
A
A
A
"
  :margin 10
  :miser 10)

(def-ppblock-test format.@_.5
  (format t "A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_A ~@_")
  "A A A A A A A A A A "
  :margin 10
  :miser 10
  :pretty nil)

(def-ppblock-test format.@_.6
  (format t "~%A~@_")
  "
A
"
  :margin 20
  :miser 20)

(def-ppblock-test format.@_.7
  (format t "~@_A~%")
  "
A
"
  :margin 20
  :miser 20)

(def-ppblock-test format.@_.8
  (progn
    (format t "AAAA ~_")
    (pprint-logical-block
     (*standard-output* nil)
     (format t "A ~@_A ~@_A ~@_A ~@_")))
  "AAAA
A A A A "
  :margin 10
  :miser 8)

(def-ppblock-test format.@_.9
  (progn
    (format t "AAAA ~:@_")
    (pprint-logical-block
     (*standard-output* nil)
     (format t "A ~@_A ~@_A ~@_A ~@_")))
  "AAAA
A A A A "
  :margin 10
  :miser 8)

(deftest format.@_.10
188 189 190 191
  (with-output-to-string
    (s)
    (with-standard-io-syntax
     (let ((*print-readably* nil)
sds's avatar
sds committed
192 193 194 195
           (*print-escape* nil)
           (*print-pretty* t)
           (*print-right-margin* 4)
           (*print-miser-width* 4))
196
       (format s "A ~@_A ~@_A ~@_A ~@_A ~@_"))))
197 198
  "A A A A A ")

pfdietz's avatar
pfdietz committed
199 200 201
(deftest formatter.@_.10
  (with-standard-io-syntax
   (let ((*print-readably* nil)
sds's avatar
sds committed
202 203 204 205
         (*print-escape* nil)
         (*print-pretty* t)
         (*print-right-margin* 4)
         (*print-miser-width* 4))
pfdietz's avatar
pfdietz committed
206 207 208 209
     (formatter-call-to-string
      (formatter "A ~@_A ~@_A ~@_A ~@_A ~@_"))))
  "A A A A A ")

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 248 249 250 251 252 253 254 255 256 257 258
;;; fill

(def-ppblock-test format.\:_.1
  (format t "A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_")
  "A A A A A
A A A A A "
  :margin 10)

(def-ppblock-test format.\:_.2
  (format t "A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_")
  "A A A
A A A
A A A
A "
  :margin 6)

(def-ppblock-test format.\:_.3
  (format t "A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_")
  "A A A
A A A
A A A
A "
  :margin 7)

(def-ppblock-test format.\:_.4
  (format t "A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_")
  "A A A A A
A A A A A "
  :margin 10
  :miser 9)

(def-ppblock-test format.\:_.5
  (format t "A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_A ~:_")
  "A
A
A
A
A
A
A
A
A
A
"
  :margin 10
  :miser 10)

(def-ppblock-test format.\:_.6
  (format t "~W~W~:_~W~W~:_~W~W~:_~W~W~:_~W~W~:_"
sds's avatar
sds committed
259 260 261 262 263
          '(A B) #\Space
          '(A B) #\Space
          '(A B) #\Space
          '(A B) #\Space
          '(A B) #\Space)
264 265 266 267 268 269
  "(A B) (A B)
(A B) (A B)
(A B) "
  :margin 12)

(deftest format.\:_.7
270 271 272 273
  (with-output-to-string
    (s)
    (with-standard-io-syntax
     (let ((*print-readably* nil)
sds's avatar
sds committed
274 275 276 277
           (*print-escape* nil)
           (*print-right-margin* 4)
           (*print-pretty* t)
           (*print-miser-width* nil))
278
       (format s "A ~:_A ~:_A ~:_A ~:_A ~:_"))))
279 280
  "A A A A A ")

pfdietz's avatar
pfdietz committed
281 282 283
(deftest formatter.\:_.7
  (with-standard-io-syntax
   (let ((*print-readably* nil)
sds's avatar
sds committed
284 285 286 287
         (*print-escape* nil)
         (*print-right-margin* 4)
         (*print-pretty* t)
         (*print-miser-width* nil))
pfdietz's avatar
pfdietz committed
288 289 290 291
     (formatter-call-to-string
      (formatter "A ~:_A ~:_A ~:_A ~:_A ~:_"))))
  "A A A A A ")

292 293
;;; mandatory

294
(def-ppblock-test format.\:@_.1
295 296 297 298 299 300 301
  (format t "A ~:@_A ~:@_A ~:@_A ~:@_")
  "A
A
A
A
")

302
(def-ppblock-test format.\:@_.2
303 304 305 306 307 308 309 310
  (format t "A ~@:_A ~@:_A ~@:_A ~@:_")
  "A
A
A
A
"
  :margin 10)

311
(def-ppblock-test format.\:@_.3
312 313 314 315 316
  (format t "A ~@:_A ")
  "A
A "
  :margin 1)

317
(def-ppblock-test format.\:@_.4
318 319 320 321
  (format t "A ~@:_A ~@:_A ~@:_A ~@:_")
  "A A A A "
  :pretty nil)

322 323 324 325 326
(deftest format.\:@_.5
  (with-output-to-string
    (s)
    (with-standard-io-syntax
     (let ((*print-readably* nil)
sds's avatar
sds committed
327 328 329 330
           (*print-escape* nil)
           (*print-pretty* t)
           (*print-right-margin* 4)
           (*print-miser-width* nil))
331
       (format s "A ~:@_A ~:@_A ~:@_A ~:@_A ~:@_"))))
332
  "A A A A A ")
pfdietz's avatar
pfdietz committed
333 334 335 336

(deftest formatter.\:@_.5
  (with-standard-io-syntax
   (let ((*print-readably* nil)
sds's avatar
sds committed
337 338 339 340
         (*print-escape* nil)
         (*print-pretty* t)
         (*print-right-margin* 4)
         (*print-miser-width* nil))
pfdietz's avatar
pfdietz committed
341 342
     (formatter-call-to-string (formatter "A ~:@_A ~:@_A ~:@_A ~:@_A ~:@_"))))
  "A A A A A ")