format-conditional.lsp 4.59 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8 9
;-*- 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")

10 11
(def-format-test format.cond.1
  "~[~]" (0) "")
pfdietz's avatar
pfdietz committed
12

13 14
(def-format-test format.cond.2
  "~[a~]" (0) "a")
pfdietz's avatar
pfdietz committed
15

16 17
(def-format-test format.cond.3
  "~[a~]" (-1) "")
pfdietz's avatar
pfdietz committed
18

19 20
(def-format-test format.cond.4
  "~[a~]" ((1- most-negative-fixnum)) "")
pfdietz's avatar
pfdietz committed
21

22 23
(def-format-test format.cond.5
  "~[a~]" (1) "")
pfdietz's avatar
pfdietz committed
24

25 26
(def-format-test format.cond.6
  "~[a~]" ((1+ most-positive-fixnum)) "")
pfdietz's avatar
pfdietz committed
27 28 29

(deftest format.cond.7
  (loop for i from -1 to 10
sds's avatar
sds committed
30
        collect (format nil "~[a~;b~;c~;d~;e~;f~;g~;h~;i~]" i))
pfdietz's avatar
pfdietz committed
31 32
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

pfdietz's avatar
pfdietz committed
33 34 35
(deftest formatter.cond.7
  (let ((fn (formatter "~[a~;b~;c~;d~;e~;f~;g~;h~;i~]")))
    (loop for i from -1 to 10
sds's avatar
sds committed
36
          collect (formatter-call-to-string fn i)))
pfdietz's avatar
pfdietz committed
37 38
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

39
(def-format-test format.cond.8
40
  "~0[a~;b~;c~;d~]" (3) "a" 1)
pfdietz's avatar
pfdietz committed
41

42
(def-format-test format.cond.9
43
  "~-1[a~;b~;c~;d~]" (3) "" 1)
pfdietz's avatar
pfdietz committed
44

45
(def-format-test format.cond.10
46
  "~1[a~;b~;c~;d~]" (3) "b" 1)
pfdietz's avatar
pfdietz committed
47

48
(def-format-test format.cond.11
49
  "~4[a~;b~;c~;d~]" (3) "" 1)
pfdietz's avatar
pfdietz committed
50

51
(def-format-test format.cond.12
52
  "~100000000000000000000000000000000[a~;b~;c~;d~]" (3) "" 1)
pfdietz's avatar
pfdietz committed
53 54 55

(deftest format.cond.13
  (loop for i from -1 to 10
sds's avatar
sds committed
56
        collect (format nil "~v[a~;b~;c~;d~;e~;f~;g~;h~;i~]" i nil))
pfdietz's avatar
pfdietz committed
57 58
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

pfdietz's avatar
pfdietz committed
59 60 61
(deftest formatter.cond.13
  (let ((fn (formatter "~V[a~;b~;c~;d~;e~;f~;g~;h~;i~]")))
    (loop for i from -1 to 10
sds's avatar
sds committed
62
          collect (formatter-call-to-string fn i)))
pfdietz's avatar
pfdietz committed
63 64
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

pfdietz's avatar
pfdietz committed
65 66
(deftest format.cond.14
  (loop for i from -1 to 10
sds's avatar
sds committed
67
        collect (format nil "~v[a~;b~;c~;d~;e~;f~;g~;h~;i~]" nil i))
pfdietz's avatar
pfdietz committed
68 69
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

pfdietz's avatar
pfdietz committed
70 71 72
(deftest formatter.cond.14
  (let ((fn (formatter "~v[a~;b~;c~;d~;e~;f~;g~;h~;i~]")))
    (loop for i from -1 to 10
sds's avatar
sds committed
73
          collect (formatter-call-to-string fn nil i)))
pfdietz's avatar
pfdietz committed
74 75
  ("" "a" "b" "c" "d" "e" "f" "g" "h" "i" "" ""))

76 77
(def-format-test format.cond.15
  "~#[A~;B~]" nil "A")
pfdietz's avatar
pfdietz committed
78

79
(def-format-test format.cond.16
80
  "~#[A~;B~]" (nil) "B" 1)
pfdietz's avatar
pfdietz committed
81 82 83 84 85

;;; ~[ .~:;  ~]

(deftest format.cond\:.1
  (loop for i from -100 to 100
sds's avatar
sds committed
86 87 88
        for s = (format nil "~[~:;a~]" i)
        unless (or (zerop i) (string= s "a"))
        collect (list i s))
pfdietz's avatar
pfdietz committed
89 90
  nil)

pfdietz's avatar
pfdietz committed
91 92 93
(deftest formatter.cond\:.1
  (let ((fn (formatter "~[~:;a~]")))
    (loop for i from -100 to 100
sds's avatar
sds committed
94 95 96
          for s = (formatter-call-to-string fn i)
          unless (or (zerop i) (string= s "a"))
          collect (list i s)))
pfdietz's avatar
pfdietz committed
97 98
  nil)

99 100
(def-format-test format.cond\:.2
  "~[a~:;b~]" (0) "a")
pfdietz's avatar
pfdietz committed
101

102 103
(def-format-test format.cond\:.3
  "~[a~:;b~]" ((1- most-negative-fixnum)) "b")
pfdietz's avatar
pfdietz committed
104

105 106
(def-format-test format.cond\:.4
  "~[a~:;b~]" ((1+ most-positive-fixnum)) "b")
pfdietz's avatar
pfdietz committed
107 108 109

(deftest format.cond\:.5
  (loop for i from -1 to 10
sds's avatar
sds committed
110
        collect (format nil "~[a~;b~;c~;d~:;e~]" i))
pfdietz's avatar
pfdietz committed
111 112
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

pfdietz's avatar
pfdietz committed
113 114 115
(deftest formatter.cond\:.5
  (let ((fn (formatter "~[a~;b~;c~;d~:;e~]")))
    (loop for i from -1 to 10
sds's avatar
sds committed
116
          collect (formatter-call-to-string fn i)))
pfdietz's avatar
pfdietz committed
117 118
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

pfdietz's avatar
pfdietz committed
119 120
(deftest format.cond\:.6
  (loop for i from -1 to 10
sds's avatar
sds committed
121
        collect (format nil "~v[a~;b~;c~;d~:;e~]" i nil))
pfdietz's avatar
pfdietz committed
122 123
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

pfdietz's avatar
pfdietz committed
124 125 126
(deftest formatter.cond\:.6
  (let ((fn (formatter "~v[a~;b~;c~;d~:;e~]")))
    (loop for i from -1 to 10
sds's avatar
sds committed
127
          collect (formatter-call-to-string fn i)))
pfdietz's avatar
pfdietz committed
128 129
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

pfdietz's avatar
pfdietz committed
130 131
(deftest format.cond\:.7
  (loop for i from -1 to 10
sds's avatar
sds committed
132
        collect (format nil "~v[a~;b~;c~;d~:;e~]" nil i))
pfdietz's avatar
pfdietz committed
133 134
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

pfdietz's avatar
pfdietz committed
135 136 137
(deftest formatter.cond\:.7
  (let ((fn (formatter "~v[a~;b~;c~;d~:;e~]")))
    (loop for i from -1 to 10
sds's avatar
sds committed
138
          collect (formatter-call-to-string fn nil i)))
pfdietz's avatar
pfdietz committed
139 140
  ("e" "a" "b" "c" "d" "e" "e" "e" "e" "e" "e" "e"))

141 142
(def-format-test format.cond\:.8
  "~#[A~:;B~]" nil "A")
pfdietz's avatar
pfdietz committed
143

144
(def-format-test format.cond\:.9
145
  "~#[A~:;B~]" (nil nil) "B" 2)
pfdietz's avatar
pfdietz committed
146 147 148

;;; ~:[...~]

149 150
(def-format-test format.\:cond.1
  "~:[a~;b~]" (nil) "a")
pfdietz's avatar
pfdietz committed
151 152 153

(deftest format.\:cond.2
  (loop for x in *mini-universe*
sds's avatar
sds committed
154 155 156
        for s = (format nil "~:[a~;b~]" x)
        when (and x (not (string= s "b")))
        collect (list x s))
pfdietz's avatar
pfdietz committed
157 158
  nil)

pfdietz's avatar
pfdietz committed
159 160 161
(deftest formatter.\:cond.2
  (let ((fn (formatter "~:[a~;b~]")))
    (loop for x in *mini-universe*
sds's avatar
sds committed
162 163 164
          for s = (formatter-call-to-string fn x)
          when (and x (not (string= s "b")))
          collect (list x s)))
pfdietz's avatar
pfdietz committed
165 166
  nil)

pfdietz's avatar
pfdietz committed
167 168
;;; ~@[ ... ~]

169 170
(def-format-test format.@cond.1
  "~@[X~]Y~A" (1) "XY1")
pfdietz's avatar
pfdietz committed
171

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