Bring Pod::Simple up to 3.09 as on CPAN.
[p5sagit/p5-mst-13.2.git] / cpan / Pod-Simple / t / xhtml01.t
CommitLineData
69473a20 1#!/usr/bin/perl -w
2
3# t/xhtml01.t - check basic output from Pod::Simple::XHTML
4
5BEGIN {
6 chdir 't' if -d 't';
7}
8
9use strict;
10use lib '../lib';
9d65762f 11use Test::More tests => 33;
69473a20 12
13use_ok('Pod::Simple::XHTML') or exit;
14
15my $parser = Pod::Simple::XHTML->new ();
16isa_ok ($parser, 'Pod::Simple::XHTML');
17
18my $results;
19
20my $PERLDOC = "http://search.cpan.org/perldoc?";
21
22initialize($parser, $results);
23$parser->parse_string_document( "=head1 Poit!" );
9d65762f 24is($results, qq{<h1 id="Poit-">Poit!</h1>\n\n}, "head1 level output");
69473a20 25
26initialize($parser, $results);
27$parser->parse_string_document( "=head2 I think so Brain." );
9d65762f 28is($results, qq{<h2 id="I-think-so-Brain.">I think so Brain.</h2>\n\n}, "head2 level output");
69473a20 29
30initialize($parser, $results);
31$parser->parse_string_document( "=head3 I say, Brain..." );
9d65762f 32is($results, qq{<h3 id="I-say-Brain...">I say, Brain...</h3>\n\n}, "head3 level output");
69473a20 33
34initialize($parser, $results);
9d65762f 35$parser->parse_string_document( "=head4 Zort & Zog!" );
36is($results, qq{<h4 id="Zort-Zog-">Zort &amp; Zog!</h4>\n\n}, "head4 level output");
69473a20 37
38
39initialize($parser, $results);
40$parser->parse_string_document(<<'EOPOD');
41=pod
42
43Gee, Brain, what do you want to do tonight?
44EOPOD
45
46is($results, <<'EOHTML', "simple paragraph");
47<p>Gee, Brain, what do you want to do tonight?</p>
48
49EOHTML
50
51
52initialize($parser, $results);
53$parser->parse_string_document(<<'EOPOD');
54=pod
55
56B: Now, Pinky, if by any chance you are captured during this mission,
57remember you are Gunther Heindriksen from Appenzell. You moved to
58Grindelwald to drive the cog train to Murren. Can you repeat that?
59
60P: Mmmm, no, Brain, don't think I can.
61EOPOD
62
63is($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&#39;t think I can.</p>
69473a20 67
68EOHTML
69
70initialize($parser, $results);
71$parser->parse_string_document(<<'EOPOD');
72=over
73
74=item *
75
76P: Gee, Brain, what do you want to do tonight?
77
78=item *
79
80B: The same thing we do every night, Pinky. Try to take over the world!
81
82=back
83
84EOPOD
85
86is($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
97EOHTML
98
99
100initialize($parser, $results);
101$parser->parse_string_document(<<'EOPOD');
102=over
103
104=item 1
105
106P: Gee, Brain, what do you want to do tonight?
107
108=item 2
109
110B: The same thing we do every night, Pinky. Try to take over the world!
111
112=back
113
114EOPOD
115
116is($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
127EOHTML
128
129
130initialize($parser, $results);
131$parser->parse_string_document(<<'EOPOD');
132=over
133
134=item Pinky
135
136Gee, Brain, what do you want to do tonight?
137
138=item Brain
139
140The same thing we do every night, Pinky. Try to take over the world!
141
142=back
143
144EOPOD
145
146is($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
163EOHTML
164
165initialize($parser, $results);
166$parser->parse_string_document(<<'EOPOD');
167=over
168
169=item * Pinky
170
171Gee, Brain, what do you want to do tonight?
172
173=item * Brain
174
175The same thing we do every night, Pinky. Try to take over the world!
176
177=back
178
179EOPOD
180
181is($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
196EOHTML
197
198initialize($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
208EOPOD
209
210is($results, <<'EOHTML', "bulleted author list");
211<ul>
212
213<li><p>Brain &lt;brain@binkyandthebrain.com&gt;</p>
214
215</li>
216<li><p>Pinky &lt;pinky@binkyandthebrain.com&gt;</p>
217
218</li>
69473a20 219</ul>
220
221EOHTML
222
223
224initialize($parser, $results);
225$parser->parse_string_document(<<'EOPOD');
226=pod
227
228 1 + 1 = 2;
229 2 + 2 = 4;
230
231EOPOD
232
233is($results, <<'EOHTML', "code block");
234<pre><code> 1 + 1 = 2;
235 2 + 2 = 4;</code></pre>
236
237EOHTML
238
239
240initialize($parser, $results);
241$parser->parse_string_document(<<'EOPOD');
242=pod
243
244A plain paragraph with a C<functionname>.
245EOPOD
246is($results, <<"EOHTML", "code entity in a paragraph");
247<p>A plain paragraph with a <code>functionname</code>.</p>
248
249EOHTML
250
251
252initialize($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
258A plain paragraph with body tags turned on.
259EOPOD
260is($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
269EOHTML
270
271
272initialize($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
279A plain paragraph with body tags and css tags turned on.
280EOPOD
281like($results, qr/<link rel='stylesheet' href='style.css' type='text\/css'>/,
282"adding html body tags and css tags");
283
284
285initialize($parser, $results);
286$parser->parse_string_document(<<'EOPOD');
287=pod
288
289A plain paragraph with S<non breaking text>.
290EOPOD
291is($results, <<"EOHTML", "Non breaking text in a paragraph");
292<p>A plain paragraph with <nobr>non breaking text</nobr>.</p>
293
294EOHTML
295
296initialize($parser, $results);
297$parser->parse_string_document(<<'EOPOD');
298=pod
299
300A plain paragraph with a L<Newlines>.
301EOPOD
302is($results, <<"EOHTML", "Link entity in a paragraph");
303<p>A plain paragraph with a <a href="${PERLDOC}Newlines">Newlines</a>.</p>
304
305EOHTML
306
307initialize($parser, $results);
308$parser->parse_string_document(<<'EOPOD');
309=pod
310
311A plain paragraph with a L<perlport/Newlines>.
312EOPOD
313is($results, <<"EOHTML", "Link entity in a paragraph");
9d65762f 314<p>A plain paragraph with a <a href="${PERLDOC}perlport/Newlines">&quot;Newlines&quot; in perlport</a>.</p>
69473a20 315
316EOHTML
317
318initialize($parser, $results);
319$parser->parse_string_document(<<'EOPOD');
320=pod
321
322A plain paragraph with a L<Boo|http://link.included.here>.
323EOPOD
324is($results, <<"EOHTML", "A link in a paragraph");
325<p>A plain paragraph with a <a href="http://link.included.here">Boo</a>.</p>
326
327EOHTML
328
329initialize($parser, $results);
330$parser->parse_string_document(<<'EOPOD');
331=pod
332
333A plain paragraph with a L<http://link.included.here>.
334EOPOD
335is($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
338EOHTML
339
340initialize($parser, $results);
341$parser->parse_string_document(<<'EOPOD');
342=pod
343
344A plain paragraph with B<bold text>.
345EOPOD
346is($results, <<"EOHTML", "Bold text in a paragraph");
347<p>A plain paragraph with <b>bold text</b>.</p>
348
349EOHTML
350
351initialize($parser, $results);
352$parser->parse_string_document(<<'EOPOD');
353=pod
354
355A plain paragraph with I<italic text>.
356EOPOD
357is($results, <<"EOHTML", "Italic text in a paragraph");
358<p>A plain paragraph with <i>italic text</i>.</p>
359
360EOHTML
361
362initialize($parser, $results);
363$parser->parse_string_document(<<'EOPOD');
364=pod
365
366A plain paragraph with a F<filename>.
367EOPOD
368is($results, <<"EOHTML", "File name in a paragraph");
369<p>A plain paragraph with a <i>filename</i>.</p>
370
371EOHTML
372
9d65762f 373# It's not important that 's (apostrophes) be encoded for XHTML output.
69473a20 374initialize($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>;
380EOPOD
381is($results, <<"EOHTML", "Verbatim text with encodable entities");
9d65762f 382<pre><code> # this header is very important &amp; dont you forget it
69473a20 383 my \$text = &quot;File is: &quot; . &lt;FILE&gt;;</code></pre>
384
385EOHTML
386
9d65762f 387initialize($parser, $results);
388$parser->parse_string_document(<<'EOPOD');
389=pod
390
391A text paragraph using E<sol> and E<verbar> special POD entities.
392
393EOPOD
394is($results, <<"EOHTML", "Text with decodable entities");
395<p>A text paragraph using / and | special POD entities.</p>
396
397EOHTML
398
399initialize($parser, $results);
400$parser->parse_string_document(<<'EOPOD');
401=pod
402
403A text paragraph using numeric POD entities: E<60>, E<62>.
404
405EOPOD
406is($results, <<"EOHTML", "Text with numeric entities");
407<p>A text paragraph using numeric POD entities: &#60;, &#62;.</p>
408
409EOHTML
410
8737ae4d 411SKIP: 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>;
423EOPOD
424is($results, <<"EOHTML", "Verbatim text with markup and embedded formatting");
9d65762f 425<pre><code> # this header is very important &amp; dont you forget it
69473a20 426 <b>my \$file = &lt;FILE&gt; || &#39;Blank!&#39;;</b>
427 my \$text = &quot;File is: &quot; . &lt;FILE&gt;;</code></pre>
428
429EOHTML
8737ae4d 430}
69473a20 431
9d65762f 432
433ok $parser = Pod::Simple::XHTML->new, 'Construct a new parser';
434$results = '';
435$parser->output_string( \$results ); # Send the resulting output to a string
436ok $parser->parse_string_document( "=head1 Poit!" ), 'Parse with headers';
437like $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
442sub 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}