Commit | Line | Data |
69473a20 |
1 | #!/usr/bin/perl -w |
2 | |
3 | # t/xhtml01.t - check basic output from Pod::Simple::XHTML |
4 | |
5 | BEGIN { |
6 | chdir 't' if -d 't'; |
7 | } |
8 | |
9 | use strict; |
10 | use lib '../lib'; |
9d65762f |
11 | use Test::More tests => 33; |
69473a20 |
12 | |
13 | use_ok('Pod::Simple::XHTML') or exit; |
14 | |
15 | my $parser = Pod::Simple::XHTML->new (); |
16 | isa_ok ($parser, 'Pod::Simple::XHTML'); |
17 | |
18 | my $results; |
19 | |
20 | my $PERLDOC = "http://search.cpan.org/perldoc?"; |
21 | |
22 | initialize($parser, $results); |
23 | $parser->parse_string_document( "=head1 Poit!" ); |
9d65762f |
24 | is($results, qq{<h1 id="Poit-">Poit!</h1>\n\n}, "head1 level output"); |
69473a20 |
25 | |
26 | initialize($parser, $results); |
27 | $parser->parse_string_document( "=head2 I think so Brain." ); |
9d65762f |
28 | is($results, qq{<h2 id="I-think-so-Brain.">I think so Brain.</h2>\n\n}, "head2 level output"); |
69473a20 |
29 | |
30 | initialize($parser, $results); |
31 | $parser->parse_string_document( "=head3 I say, Brain..." ); |
9d65762f |
32 | is($results, qq{<h3 id="I-say-Brain...">I say, Brain...</h3>\n\n}, "head3 level output"); |
69473a20 |
33 | |
34 | initialize($parser, $results); |
9d65762f |
35 | $parser->parse_string_document( "=head4 Zort & Zog!" ); |
36 | is($results, qq{<h4 id="Zort-Zog-">Zort & Zog!</h4>\n\n}, "head4 level output"); |
69473a20 |
37 | |
38 | |
39 | initialize($parser, $results); |
40 | $parser->parse_string_document(<<'EOPOD'); |
41 | =pod |
42 | |
43 | Gee, Brain, what do you want to do tonight? |
44 | EOPOD |
45 | |
46 | is($results, <<'EOHTML', "simple paragraph"); |
47 | <p>Gee, Brain, what do you want to do tonight?</p> |
48 | |
49 | EOHTML |
50 | |
51 | |
52 | initialize($parser, $results); |
53 | $parser->parse_string_document(<<'EOPOD'); |
54 | =pod |
55 | |
56 | B: Now, Pinky, if by any chance you are captured during this mission, |
57 | remember you are Gunther Heindriksen from Appenzell. You moved to |
58 | Grindelwald to drive the cog train to Murren. Can you repeat that? |
59 | |
60 | P: Mmmm, no, Brain, don't think I can. |
61 | EOPOD |
62 | |
63 | is($results, <<'EOHTML', "multiple paragraphs"); |
64 | <p>B: Now, Pinky, if by any chance you are captured during this mission, remember you are Gunther Heindriksen from Appenzell. You moved to Grindelwald to drive the cog train to Murren. Can you repeat that?</p> |
65 | |
9d65762f |
66 | <p>P: Mmmm, no, Brain, don't think I can.</p> |
69473a20 |
67 | |
68 | EOHTML |
69 | |
70 | initialize($parser, $results); |
71 | $parser->parse_string_document(<<'EOPOD'); |
72 | =over |
73 | |
74 | =item * |
75 | |
76 | P: Gee, Brain, what do you want to do tonight? |
77 | |
78 | =item * |
79 | |
80 | B: The same thing we do every night, Pinky. Try to take over the world! |
81 | |
82 | =back |
83 | |
84 | EOPOD |
85 | |
86 | is($results, <<'EOHTML', "simple bulleted list"); |
87 | <ul> |
88 | |
9d65762f |
89 | <li><p>P: Gee, Brain, what do you want to do tonight?</p> |
69473a20 |
90 | |
9d65762f |
91 | </li> |
92 | <li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p> |
69473a20 |
93 | |
9d65762f |
94 | </li> |
69473a20 |
95 | </ul> |
96 | |
97 | EOHTML |
98 | |
99 | |
100 | initialize($parser, $results); |
101 | $parser->parse_string_document(<<'EOPOD'); |
102 | =over |
103 | |
104 | =item 1 |
105 | |
106 | P: Gee, Brain, what do you want to do tonight? |
107 | |
108 | =item 2 |
109 | |
110 | B: The same thing we do every night, Pinky. Try to take over the world! |
111 | |
112 | =back |
113 | |
114 | EOPOD |
115 | |
116 | is($results, <<'EOHTML', "numbered list"); |
117 | <ol> |
118 | |
9d65762f |
119 | <li><p>P: Gee, Brain, what do you want to do tonight?</p> |
69473a20 |
120 | |
9d65762f |
121 | </li> |
122 | <li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p> |
69473a20 |
123 | |
9d65762f |
124 | </li> |
69473a20 |
125 | </ol> |
126 | |
127 | EOHTML |
128 | |
129 | |
130 | initialize($parser, $results); |
131 | $parser->parse_string_document(<<'EOPOD'); |
132 | =over |
133 | |
134 | =item Pinky |
135 | |
136 | Gee, Brain, what do you want to do tonight? |
137 | |
138 | =item Brain |
139 | |
140 | The same thing we do every night, Pinky. Try to take over the world! |
141 | |
142 | =back |
143 | |
144 | EOPOD |
145 | |
146 | is($results, <<'EOHTML', "list with text headings"); |
9d65762f |
147 | <dl> |
148 | |
149 | <dt>Pinky</dt> |
150 | <dd> |
151 | |
152 | <p>Gee, Brain, what do you want to do tonight?</p> |
153 | |
154 | </dd> |
155 | <dt>Brain</dt> |
156 | <dd> |
157 | |
158 | <p>The same thing we do every night, Pinky. Try to take over the world!</p> |
159 | |
160 | </dd> |
161 | </dl> |
162 | |
163 | EOHTML |
164 | |
165 | initialize($parser, $results); |
166 | $parser->parse_string_document(<<'EOPOD'); |
167 | =over |
168 | |
169 | =item * Pinky |
170 | |
171 | Gee, Brain, what do you want to do tonight? |
172 | |
173 | =item * Brain |
174 | |
175 | The same thing we do every night, Pinky. Try to take over the world! |
176 | |
177 | =back |
178 | |
179 | EOPOD |
180 | |
181 | is($results, <<'EOHTML', "list with bullet and text headings"); |
69473a20 |
182 | <ul> |
183 | |
9d65762f |
184 | <li><p>Pinky</p> |
69473a20 |
185 | |
186 | <p>Gee, Brain, what do you want to do tonight?</p> |
187 | |
9d65762f |
188 | </li> |
189 | <li><p>Brain</p> |
69473a20 |
190 | |
191 | <p>The same thing we do every night, Pinky. Try to take over the world!</p> |
192 | |
9d65762f |
193 | </li> |
194 | </ul> |
195 | |
196 | EOHTML |
197 | |
198 | initialize($parser, $results); |
199 | $parser->parse_string_document(<<'EOPOD'); |
200 | =over |
201 | |
202 | =item * Brain <brain@binkyandthebrain.com> |
203 | |
204 | =item * Pinky <pinky@binkyandthebrain.com> |
205 | |
206 | =back |
207 | |
208 | EOPOD |
209 | |
210 | is($results, <<'EOHTML', "bulleted author list"); |
211 | <ul> |
212 | |
213 | <li><p>Brain <brain@binkyandthebrain.com></p> |
214 | |
215 | </li> |
216 | <li><p>Pinky <pinky@binkyandthebrain.com></p> |
217 | |
218 | </li> |
69473a20 |
219 | </ul> |
220 | |
221 | EOHTML |
222 | |
223 | |
224 | initialize($parser, $results); |
225 | $parser->parse_string_document(<<'EOPOD'); |
226 | =pod |
227 | |
228 | 1 + 1 = 2; |
229 | 2 + 2 = 4; |
230 | |
231 | EOPOD |
232 | |
233 | is($results, <<'EOHTML', "code block"); |
234 | <pre><code> 1 + 1 = 2; |
235 | 2 + 2 = 4;</code></pre> |
236 | |
237 | EOHTML |
238 | |
239 | |
240 | initialize($parser, $results); |
241 | $parser->parse_string_document(<<'EOPOD'); |
242 | =pod |
243 | |
244 | A plain paragraph with a C<functionname>. |
245 | EOPOD |
246 | is($results, <<"EOHTML", "code entity in a paragraph"); |
247 | <p>A plain paragraph with a <code>functionname</code>.</p> |
248 | |
249 | EOHTML |
250 | |
251 | |
252 | initialize($parser, $results); |
253 | $parser->html_header("<html>\n<body>"); |
254 | $parser->html_footer("</body>\n</html>"); |
255 | $parser->parse_string_document(<<'EOPOD'); |
256 | =pod |
257 | |
258 | A plain paragraph with body tags turned on. |
259 | EOPOD |
260 | is($results, <<"EOHTML", "adding html body tags"); |
261 | <html> |
262 | <body> |
263 | |
264 | <p>A plain paragraph with body tags turned on.</p> |
265 | |
266 | </body> |
267 | </html> |
268 | |
269 | EOHTML |
270 | |
271 | |
272 | initialize($parser, $results); |
273 | $parser->html_css('style.css'); |
274 | $parser->html_header(undef); |
275 | $parser->html_footer(undef); |
276 | $parser->parse_string_document(<<'EOPOD'); |
277 | =pod |
278 | |
279 | A plain paragraph with body tags and css tags turned on. |
280 | EOPOD |
281 | like($results, qr/<link rel='stylesheet' href='style.css' type='text\/css'>/, |
282 | "adding html body tags and css tags"); |
283 | |
284 | |
285 | initialize($parser, $results); |
286 | $parser->parse_string_document(<<'EOPOD'); |
287 | =pod |
288 | |
289 | A plain paragraph with S<non breaking text>. |
290 | EOPOD |
291 | is($results, <<"EOHTML", "Non breaking text in a paragraph"); |
292 | <p>A plain paragraph with <nobr>non breaking text</nobr>.</p> |
293 | |
294 | EOHTML |
295 | |
296 | initialize($parser, $results); |
297 | $parser->parse_string_document(<<'EOPOD'); |
298 | =pod |
299 | |
300 | A plain paragraph with a L<Newlines>. |
301 | EOPOD |
302 | is($results, <<"EOHTML", "Link entity in a paragraph"); |
303 | <p>A plain paragraph with a <a href="${PERLDOC}Newlines">Newlines</a>.</p> |
304 | |
305 | EOHTML |
306 | |
307 | initialize($parser, $results); |
308 | $parser->parse_string_document(<<'EOPOD'); |
309 | =pod |
310 | |
311 | A plain paragraph with a L<perlport/Newlines>. |
312 | EOPOD |
313 | is($results, <<"EOHTML", "Link entity in a paragraph"); |
9d65762f |
314 | <p>A plain paragraph with a <a href="${PERLDOC}perlport/Newlines">"Newlines" in perlport</a>.</p> |
69473a20 |
315 | |
316 | EOHTML |
317 | |
318 | initialize($parser, $results); |
319 | $parser->parse_string_document(<<'EOPOD'); |
320 | =pod |
321 | |
322 | A plain paragraph with a L<Boo|http://link.included.here>. |
323 | EOPOD |
324 | is($results, <<"EOHTML", "A link in a paragraph"); |
325 | <p>A plain paragraph with a <a href="http://link.included.here">Boo</a>.</p> |
326 | |
327 | EOHTML |
328 | |
329 | initialize($parser, $results); |
330 | $parser->parse_string_document(<<'EOPOD'); |
331 | =pod |
332 | |
333 | A plain paragraph with a L<http://link.included.here>. |
334 | EOPOD |
335 | is($results, <<"EOHTML", "A link in a paragraph"); |
336 | <p>A plain paragraph with a <a href="http://link.included.here">http://link.included.here</a>.</p> |
337 | |
338 | EOHTML |
339 | |
340 | initialize($parser, $results); |
341 | $parser->parse_string_document(<<'EOPOD'); |
342 | =pod |
343 | |
344 | A plain paragraph with B<bold text>. |
345 | EOPOD |
346 | is($results, <<"EOHTML", "Bold text in a paragraph"); |
347 | <p>A plain paragraph with <b>bold text</b>.</p> |
348 | |
349 | EOHTML |
350 | |
351 | initialize($parser, $results); |
352 | $parser->parse_string_document(<<'EOPOD'); |
353 | =pod |
354 | |
355 | A plain paragraph with I<italic text>. |
356 | EOPOD |
357 | is($results, <<"EOHTML", "Italic text in a paragraph"); |
358 | <p>A plain paragraph with <i>italic text</i>.</p> |
359 | |
360 | EOHTML |
361 | |
362 | initialize($parser, $results); |
363 | $parser->parse_string_document(<<'EOPOD'); |
364 | =pod |
365 | |
366 | A plain paragraph with a F<filename>. |
367 | EOPOD |
368 | is($results, <<"EOHTML", "File name in a paragraph"); |
369 | <p>A plain paragraph with a <i>filename</i>.</p> |
370 | |
371 | EOHTML |
372 | |
9d65762f |
373 | # It's not important that 's (apostrophes) be encoded for XHTML output. |
69473a20 |
374 | initialize($parser, $results); |
375 | $parser->parse_string_document(<<'EOPOD'); |
376 | =pod |
377 | |
9d65762f |
378 | # this header is very important & dont you forget it |
69473a20 |
379 | my $text = "File is: " . <FILE>; |
380 | EOPOD |
381 | is($results, <<"EOHTML", "Verbatim text with encodable entities"); |
9d65762f |
382 | <pre><code> # this header is very important & dont you forget it |
69473a20 |
383 | my \$text = "File is: " . <FILE>;</code></pre> |
384 | |
385 | EOHTML |
386 | |
9d65762f |
387 | initialize($parser, $results); |
388 | $parser->parse_string_document(<<'EOPOD'); |
389 | =pod |
390 | |
391 | A text paragraph using E<sol> and E<verbar> special POD entities. |
392 | |
393 | EOPOD |
394 | is($results, <<"EOHTML", "Text with decodable entities"); |
395 | <p>A text paragraph using / and | special POD entities.</p> |
396 | |
397 | EOHTML |
398 | |
399 | initialize($parser, $results); |
400 | $parser->parse_string_document(<<'EOPOD'); |
401 | =pod |
402 | |
403 | A text paragraph using numeric POD entities: E<60>, E<62>. |
404 | |
405 | EOPOD |
406 | is($results, <<"EOHTML", "Text with numeric entities"); |
407 | <p>A text paragraph using numeric POD entities: <, >.</p> |
408 | |
409 | EOHTML |
410 | |
8737ae4d |
411 | SKIP: for my $use_html_entities (0, 1) { |
412 | if ($use_html_entities and not $Pod::Simple::XHTML::HAS_HTML_ENTITIES) { |
413 | skip("HTML::Entities not installed", 1); |
414 | } |
415 | local $Pod::Simple::XHTML::HAS_HTML_ENTITIES = $use_html_entities; |
416 | initialize($parser, $results); |
417 | $parser->parse_string_document(<<'EOPOD'); |
69473a20 |
418 | =pod |
419 | |
9d65762f |
420 | # this header is very important & dont you forget it |
69473a20 |
421 | B<my $file = <FILEE<gt> || 'Blank!';> |
422 | my $text = "File is: " . <FILE>; |
423 | EOPOD |
424 | is($results, <<"EOHTML", "Verbatim text with markup and embedded formatting"); |
9d65762f |
425 | <pre><code> # this header is very important & dont you forget it |
69473a20 |
426 | <b>my \$file = <FILE> || 'Blank!';</b> |
427 | my \$text = "File is: " . <FILE>;</code></pre> |
428 | |
429 | EOHTML |
8737ae4d |
430 | } |
69473a20 |
431 | |
9d65762f |
432 | |
433 | ok $parser = Pod::Simple::XHTML->new, 'Construct a new parser'; |
434 | $results = ''; |
435 | $parser->output_string( \$results ); # Send the resulting output to a string |
436 | ok $parser->parse_string_document( "=head1 Poit!" ), 'Parse with headers'; |
437 | like $results, qr{<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />}, |
438 | 'Should have proper http-equiv meta tag'; |
439 | |
69473a20 |
440 | ###################################### |
441 | |
442 | sub initialize { |
443 | $_[0] = Pod::Simple::XHTML->new (); |
444 | $_[0]->html_header(""); |
445 | $_[0]->html_footer(""); |
446 | $_[0]->output_string( \$results ); # Send the resulting output to a string |
447 | $_[1] = ''; |
448 | return; |
449 | } |