simple
  1 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-WHO-TEST; Base: 10 -*-
2 ;;; $Header: /usr/local/cvsrep/cl-who/test/simple,v 1.4 2009/01/26 11:10:52 edi Exp $
3
4 ;;; some simple tests for CL-WHO - entered manually and to be read
5 ;;; in the CL-WHO-TEST package; all forms are expected to return a
6 ;;; true value on success when EVALuated
7
8 ;;; 1
9 (string= (with-output-to-string (out)
10 (with-html-output (out)
11 (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
12 ("http://marcusmiller.com/" . "Marcus Miller")
13 ("http://www.milesdavis.com/" . "Miles Davis"))
14 do (htm (:a :href link
15 (:b (str title)))
16 :br))))
17 "<a href='http://zappa.com/'><b>Frank Zappa</b></a><br /><a href='http://marcusmiller.com/'><b>Marcus Miller</b></a><br /><a href='http://www.milesdavis.com/'><b>Miles Davis</b></a><br />")
18
19 ;;; 2
20 (string= (with-output-to-string (out)
21 (with-html-output (out nil)
22 (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
23 ("http://marcusmiller.com/" . "Marcus Miller")
24 ("http://www.milesdavis.com/" . "Miles Davis"))
25 do (htm (:a :href link
26 (:b (str title)))
27 :br))))
28 "<a href='http://zappa.com/'><b>Frank Zappa</b></a><br /><a href='http://marcusmiller.com/'><b>Marcus Miller</b></a><br /><a href='http://www.milesdavis.com/'><b>Miles Davis</b></a><br />")
29
30 ;;; 3
31 (string= (with-output-to-string (foo)
32 (with-html-output (out foo)
33 (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
34 ("http://marcusmiller.com/" . "Marcus Miller")
35 ("http://www.milesdavis.com/" . "Miles Davis"))
36 do (htm (:a :href link
37 (:b (str title)))
38 :br))))
39 "<a href='http://zappa.com/'><b>Frank Zappa</b></a><br /><a href='http://marcusmiller.com/'><b>Marcus Miller</b></a><br /><a href='http://www.milesdavis.com/'><b>Miles Davis</b></a><br />")
40
41 ;;; 4
42 (string= (with-html-output-to-string (out)
43 (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
44 ("http://marcusmiller.com/" . "Marcus Miller")
45 ("http://www.milesdavis.com/" . "Miles Davis"))
46 do (htm (:a :href link
47 (:b (str title)))
48 :br)))
49 "<a href='http://zappa.com/'><b>Frank Zappa</b></a><br /><a href='http://marcusmiller.com/'><b>Marcus Miller</b></a><br /><a href='http://www.milesdavis.com/'><b>Miles Davis</b></a><br />")
50
51 ;;; 5
52 (string= (with-html-output-to-string (out nil)
53 (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
54 ("http://marcusmiller.com/" . "Marcus Miller")
55 ("http://www.milesdavis.com/" . "Miles Davis"))
56 do (htm (:a :href link
57 (:b (str title)))
58 :br)))
59 "<a href='http://zappa.com/'><b>Frank Zappa</b></a><br /><a href='http://marcusmiller.com/'><b>Marcus Miller</b></a><br /><a href='http://www.milesdavis.com/'><b>Miles Davis</b></a><br />")
60
61 ;;; 6
62 (string= (with-html-output-to-string (out nil :prologue nil)
63 (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
64 ("http://marcusmiller.com/" . "Marcus Miller")
65 ("http://www.milesdavis.com/" . "Miles Davis"))
66 do (htm (:a :href link
67 (:b (str title)))
68 :br)))
69 "<a href='http://zappa.com/'><b>Frank Zappa</b></a><br /><a href='http://marcusmiller.com/'><b>Marcus Miller</b></a><br /><a href='http://www.milesdavis.com/'><b>Miles Davis</b></a><br />")
70
71 ;;; 7
72 ;;; XXX this fails uglily on SBCL for some reason that I'm too lazy to
73 ;;; look into
74 ;; (eq (array-element-type
75 ;; (with-html-output-to-string (out nil :element-type 'base-char)
76 ;; (:br)))
77 ;; 'base-char)
78
79 ;;; 8
80 (string= (let ((*attribute-quote-char* #\"))
81 (with-html-output-to-string (out)
82 (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
83 ("http://marcusmiller.com/" . "Marcus Miller")
84 ("http://www.milesdavis.com/" . "Miles Davis"))
85 do (htm (:a :href link
86 (:b (str title)))
87 :br))))
88 "<a href=\"http://zappa.com/\"><b>Frank Zappa</b></a><br /><a href=\"http://marcusmiller.com/\"><b>Marcus Miller</b></a><br /><a href=\"http://www.milesdavis.com/\"><b>Miles Davis</b></a><br />")
89
90 ;;; 9
91 (string= (with-html-output-to-string (out nil :prologue t)
92 (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
93 ("http://marcusmiller.com/" . "Marcus Miller")
94 ("http://www.milesdavis.com/" . "Miles Davis"))
95 do (htm (:a :href link
96 (:b (str title)))
97 :br)))
98 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
99 <a href='http://zappa.com/'><b>Frank Zappa</b></a><br /><a href='http://marcusmiller.com/'><b>Marcus Miller</b></a><br /><a href='http://www.milesdavis.com/'><b>Miles Davis</b></a><br />")
100
101 ;;; 10
102 (string= (with-html-output-to-string
103 (out nil :prologue "<!DOCTYPE math SYSTEM \"http://www.w3.org/Math/DTD/mathml1/mathml.dtd\">")
104 (:apply (:factorial) (:cn "3")))
105 "<!DOCTYPE math SYSTEM \"http://www.w3.org/Math/DTD/mathml1/mathml.dtd\">
106 <apply><factorial></factorial><cn>3</cn></apply>")
107
108 ;;; 11
109 (string= (let ((*prologue* "<!DOCTYPE math SYSTEM \"http://www.w3.org/Math/DTD/mathml1/mathml.dtd\">"))
110 (eval `(with-html-output-to-string (out nil :prologue t)
111 (:apply (:factorial) (:cn "3")))))
112 "<!DOCTYPE math SYSTEM \"http://www.w3.org/Math/DTD/mathml1/mathml.dtd\">
113 <apply><factorial></factorial><cn>3</cn></apply>")
114
115 ;;; 12
116 (string= (with-html-output-to-string (out nil :indent t)
117 (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
118 ("http://marcusmiller.com/" . "Marcus Miller")
119 ("http://www.milesdavis.com/" . "Miles Davis"))
120 do (htm (:a :href link
121 (:b (str title)))
122 :br)))
123 "
124 <a href='http://zappa.com/'>
125 <b>Frank Zappa
126 </b>
127 </a>
128 <br />
129 <a href='http://marcusmiller.com/'>
130 <b>Marcus Miller
131 </b>
132 </a>
133 <br />
134 <a href='http://www.milesdavis.com/'>
135 <b>Miles Davis
136 </b>
137 </a>
138 <br />")
139
140 ;;; 13
141 (string= (with-html-output-to-string (out nil :indent 0)
142 (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
143 ("http://marcusmiller.com/" . "Marcus Miller")
144 ("http://www.milesdavis.com/" . "Miles Davis"))
145 do (htm (:a :href link
146 (:b (str title)))
147 :br)))
148 "
149 <a href='http://zappa.com/'>
150 <b>Frank Zappa
151 </b>
152 </a>
153 <br />
154 <a href='http://marcusmiller.com/'>
155 <b>Marcus Miller
156 </b>
157 </a>
158 <br />
159 <a href='http://www.milesdavis.com/'>
160 <b>Miles Davis
161 </b>
162 </a>
163 <br />")
164
165 ;;; 14
166 (string= (with-html-output-to-string (out nil :indent 3)
167 (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
168 ("http://marcusmiller.com/" . "Marcus Miller")
169 ("http://www.milesdavis.com/" . "Miles Davis"))
170 do (htm (:a :href link
171 (:b (str title)))
172 :br)))
173 "
174 <a href='http://zappa.com/'>
175 <b>Frank Zappa
176 </b>
177 </a>
178 <br />
179 <a href='http://marcusmiller.com/'>
180 <b>Marcus Miller
181 </b>
182 </a>
183 <br />
184 <a href='http://www.milesdavis.com/'>
185 <b>Miles Davis
186 </b>
187 </a>
188 <br />")
189
190 ;;; 15
191 (string= (with-html-output-to-string (out)
192 (:table :border 0 :cellpadding 4
193 (loop for i below 25 by 5
194 do (htm
195 (:tr :align "right"
196 (loop for j from i below (+ i 5)
197 do (htm
198 (:td :bgcolor (if (oddp j)
199 "pink"
200 "green")
201 (fmt "~@R" (1+ j))))))))))
202 "<table border='0' cellpadding='4'><tr align='right'><td bgcolor='green'>I</td><td bgcolor='pink'>II</td><td bgcolor='green'>III</td><td bgcolor='pink'>IV</td><td bgcolor='green'>V</td></tr><tr align='right'><td bgcolor='pink'>VI</td><td bgcolor='green'>VII</td><td bgcolor='pink'>VIII</td><td bgcolor='green'>IX</td><td bgcolor='pink'>X</td></tr><tr align='right'><td bgcolor='green'>XI</td><td bgcolor='pink'>XII</td><td bgcolor='green'>XIII</td><td bgcolor='pink'>XIV</td><td bgcolor='green'>XV</td></tr><tr align='right'><td bgcolor='pink'>XVI</td><td bgcolor='green'>XVII</td><td bgcolor='pink'>XVIII</td><td bgcolor='green'>XIX</td><td bgcolor='pink'>XX</td></tr><tr align='right'><td bgcolor='green'>XXI</td><td bgcolor='pink'>XXII</td><td bgcolor='green'>XXIII</td><td bgcolor='pink'>XXIV</td><td bgcolor='green'>XXV</td></tr></table>")
203
204 ;;; 16
205 (string= (with-html-output-to-string (out)
206 (:h4 "Look at the character entities generated by this example")
207 (loop for i from 0
208 for string in '("Fete" "Sorensen" "naive" "Huhner" "Strasse")
209 do (htm
210 (:p :style (conc "background-color:" (case (mod i 3)
211 ((0) "red")
212 ((1) "orange")
213 ((2) "blue")))
214 (htm (esc string))))))
215 "<h4>Look at the character entities generated by this example</h4><p style='background-color:red'>Fete</p><p style='background-color:orange'>Sorensen</p><p style='background-color:blue'>naive</p><p style='background-color:red'>Huhner</p><p style='background-color:orange'>Strasse</p>")
216
217 ;;; 17
218 (flet ((checkbox (stream name checked &optional value)
219 (with-html-output (stream)
220 (:input :type "checkbox" :name name :checked checked :value value))))
221 (and (string= (with-output-to-string (s) (checkbox s "foo" t))
222 "<input type='checkbox' name='foo' checked='checked' />")
223 (string= (with-output-to-string (s) (checkbox s "foo" nil))
224 "<input type='checkbox' name='foo' />")
225 (string= (with-output-to-string (s) (checkbox s "foo" nil "bar"))
226 "<input type='checkbox' name='foo' value='bar' />")
227 (string= (with-output-to-string (s) (checkbox s "foo" t "bar"))
228 "<input type='checkbox' name='foo' checked='checked' value='bar' />")))
229
230 ;;; 18
231 (string= (with-html-output-to-string (out)
232 (:p))
233 "<p></p>")
234
235 ;;; 19
236 (string= (let ((cl-who:*html-empty-tag-aware-p* nil))
237 (eval `(with-html-output-to-string (out)
238 (:p))))
239 "<p />")
240
241 ;;; 20
242 (string= (let ((*html-empty-tag-aware-p* t)
243 (*html-empty-tags* '(:p)))
244 (eval `(with-html-output-to-string (out)
245 (:p))))
246 "<p />")
247
248 ;;; 21
249 (string= (with-html-output-to-string (out)
250 (:|Foo| :bar 42))
251 "<foo bar='42'></foo>")
252
253 ;;; 22
254 (string= (let ((*downcase-tokens-p* nil))
255 (eval `(with-html-output-to-string (out)
256 (:|Foo| :bar 42))))
257 "<Foo BAR='42'></Foo>")
258
259 ;;; 23
260 (string= (let* ((list (list (make-string-output-stream) (make-string-output-stream)))
261 (stream (first list)))
262 (with-html-output (var (pop list))
263 (progn (htm (:br))))
264 (get-output-stream-string stream))
265 "<br />")
266
267 ;;; 24
268 (string= (with-html-output-to-string (out)
269 (:div (:pre "Foo")))
270 "<div><pre>Foo</pre></div>")
271
272 ;;; 25
273 (string= (with-html-output-to-string (out nil :indent t)
274 (:div (:pre "Foo")))
275 "
276 <div>
277 <pre>Foo</pre>
278 </div>")
279
280 ;;; 26
281 (string= (with-html-output-to-string (out nil :indent t)
282 (:div (:p "Bar")))
283 "
284 <div>
285 <p>Bar
286 </p>
287 </div>")
288
289 ;;; 27
290 (string= (let ((*html-no-indent-tags* (cons :p *html-no-indent-tags*)))
291 (eval `(with-html-output-to-string (out nil :indent t)
292 (:div (:p "Bar")))))
293 "
294 <div>
295 <p>Bar</p>
296 </div>")