3 # t/xhtml01.t - check basic output from Pod::Simple::XHTML
11 use Test::More tests => 60;
12 #use Test::More 'no_plan';
14 use_ok('Pod::Simple::XHTML') or exit;
16 isa_ok my $parser = Pod::Simple::XHTML->new, 'Pod::Simple::XHTML';
17 my $header = $parser->html_header;
18 my $footer = $parser->html_footer;
21 [ 'foo' => 'foo', 'foo' ],
22 [ '12foo' => 'foo1', 'foo' ],
23 [ 'fo$bar' => 'fo-bar', 'fo-bar' ],
24 [ 'f12' => 'f12', 'f12' ],
25 [ '13' => 'pod13', 'pod13' ],
26 [ '**.:' => 'pod', 'pod' ],
28 is $parser->idify( $spec->[0] ), $spec->[1],
29 qq{ID for "$spec->[0]" should be "$spec->[1]"};
30 is $parser->idify( $spec->[0], 1 ), $spec->[2],
31 qq{Non-unique ID for "$spec->[0]" should be "$spec->[2]"};
36 initialize($parser, $results);
37 $parser->html_header($header);
38 $parser->html_footer($footer);
39 ok $parser->parse_string_document( '=head1 Foo' ), 'Parse one header';
40 is $results, <<'EOF', 'Should have the index';
45 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
51 <li><a href="#Foo">Foo</a></li>
61 initialize($parser, $results);
62 ok $parser->parse_string_document( '=head1 Foo Bar' ), 'Parse multiword header';
63 is $results, <<'EOF', 'Should have the index';
65 <li><a href="#Foo-Bar">Foo Bar</a></li>
68 <h1 id="Foo-Bar">Foo Bar</h1>
72 initialize($parser, $results);
73 ok $parser->parse_string_document( "=head1 Foo B<Bar>\n\n=head1 Foo B<Baz>" ),
74 'Parse two multiword headers';
75 is $results, <<'EOF', 'Should have the index';
77 <li><a href="#Foo-Bar">Foo Bar</a></li>
78 <li><a href="#Foo-Baz">Foo Baz</a></li>
81 <h1 id="Foo-Bar">Foo <b>Bar</b></h1>
83 <h1 id="Foo-Baz">Foo <b>Baz</b></h1>
87 initialize($parser, $results);
88 ok $parser->parse_string_document( "=head1 Foo\n\n=head1 Bar" ), 'Parse two headers';
89 is $results, <<'EOF', 'Should have both and the index';
91 <li><a href="#Foo">Foo</a></li>
92 <li><a href="#Bar">Bar</a></li>
101 initialize($parser, $results);
102 ok $parser->parse_string_document( "=head1 Foo C<Bar>\n\n=head1 C<Baz>" ),
103 'Parse two headers with C<> formatting';
104 is $results, <<'EOF', 'Should have the index';
106 <li><a href="#Foo-Bar">Foo Bar</a></li>
107 <li><a href="#Baz">Baz</a></li>
110 <h1 id="Foo-Bar">Foo <code>Bar</code></h1>
112 <h1 id="Baz"><code>Baz</code></h1>
116 initialize($parser, $results);
117 ok $parser->parse_string_document( "=head1 Foo\n\n=head1 Bar\n\n=head1 Baz" ),
118 'Parse three headers';
119 is $results, <<'EOF', 'Should have all three and the index';
121 <li><a href="#Foo">Foo</a></li>
122 <li><a href="#Bar">Bar</a></li>
123 <li><a href="#Baz">Baz</a></li>
126 <h1 id="Foo">Foo</h1>
128 <h1 id="Bar">Bar</h1>
130 <h1 id="Baz">Baz</h1>
134 initialize($parser, $results);
135 ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar" ), 'Parse two levels';
136 is $results, <<'EOF', 'Should have the dual-level index';
138 <li><a href="#Foo">Foo</a>
140 <li><a href="#Bar">Bar</a></li>
145 <h1 id="Foo">Foo</h1>
147 <h2 id="Bar">Bar</h2>
151 initialize($parser, $results);
152 ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head3 Baz" ),
153 'Parse three levels';
154 is $results, <<'EOF', 'Should have the three-level index';
156 <li><a href="#Foo">Foo</a>
158 <li><a href="#Bar">Bar</a>
160 <li><a href="#Baz">Baz</a></li>
167 <h1 id="Foo">Foo</h1>
169 <h2 id="Bar">Bar</h2>
171 <h3 id="Baz">Baz</h3>
175 initialize($parser, $results);
176 ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head3 Baz\n\n=head4 Howdy" ),
178 is $results, <<'EOF', 'Should have the four-level index';
180 <li><a href="#Foo">Foo</a>
182 <li><a href="#Bar">Bar</a>
184 <li><a href="#Baz">Baz</a>
186 <li><a href="#Howdy">Howdy</a></li>
195 <h1 id="Foo">Foo</h1>
197 <h2 id="Bar">Bar</h2>
199 <h3 id="Baz">Baz</h3>
201 <h4 id="Howdy">Howdy</h4>
205 initialize($parser, $results);
206 ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head2 Baz" ),
208 is $results, <<'EOF', 'Should have the 1/s index';
210 <li><a href="#Foo">Foo</a>
212 <li><a href="#Bar">Bar</a></li>
213 <li><a href="#Baz">Baz</a></li>
218 <h1 id="Foo">Foo</h1>
220 <h2 id="Bar">Bar</h2>
222 <h2 id="Baz">Baz</h2>
226 initialize($parser, $results);
227 ok $parser->parse_string_document( "=head1 Foo\n\n=head3 Bar" ), 'Parse jump from one to three';
228 is $results, <<'EOF', 'Should have the 1-3 index';
230 <li><a href="#Foo">Foo</a>
234 <li><a href="#Bar">Bar</a></li>
241 <h1 id="Foo">Foo</h1>
243 <h3 id="Bar">Bar</h3>
247 initialize($parser, $results);
248 ok $parser->parse_string_document( "=head1 Foo\n\n=head4 Bar" ), 'Parse jump from one to four';
249 is $results, <<'EOF', 'Should have the 1-4 index';
251 <li><a href="#Foo">Foo</a>
257 <li><a href="#Bar">Bar</a></li>
266 <h1 id="Foo">Foo</h1>
268 <h4 id="Bar">Bar</h4>
272 initialize($parser, $results);
273 ok $parser->parse_string_document( "=head2 Foo\n\n=head1 Bar" ),
274 'Parse two down to 1';
275 is $results, <<'EOF', 'Should have the 2-1 index';
279 <li><a href="#Foo">Foo</a></li>
282 <li><a href="#Bar">Bar</a></li>
285 <h2 id="Foo">Foo</h2>
287 <h1 id="Bar">Bar</h1>
291 initialize($parser, $results);
292 ok $parser->parse_string_document( "=head2 Foo\n\n=head1 Bar\n\n=head4 Four\n\n=head4 Four2" ),
293 'Parse two down to 1';
294 is $results, <<'EOF', 'Should have the 2-1 index';
298 <li><a href="#Foo">Foo</a></li>
301 <li><a href="#Bar">Bar</a>
307 <li><a href="#Four">Four</a></li>
308 <li><a href="#Four2">Four2</a></li>
317 <h2 id="Foo">Foo</h2>
319 <h1 id="Bar">Bar</h1>
321 <h4 id="Four">Four</h4>
323 <h4 id="Four2">Four2</h4>
327 initialize($parser, $results);
328 ok $parser->parse_string_document( "=head4 Foo" ),
330 is $results, <<'EOF', 'Should have the 2-1 index';
338 <li><a href="#Foo">Foo</a></li>
347 <h4 id="Foo">Foo</h4>
351 initialize($parser, $results);
352 ok $parser->parse_string_document( <<'EOF' ), 'Parse a mixture';
368 is $results, <<'EOF', 'And it should work!';
372 <li><a href="#Foo">Foo</a>
374 <li><a href="#Bar">Bar</a></li>
379 <li><a href="#Baz">Baz</a>
385 <li><a href="#Drink">Drink</a></li>
388 <li><a href="#Sip">Sip</a>
390 <li><a href="#Ouch">Ouch</a></li>
397 <li><a href="#Drip">Drip</a></li>
400 <h2 id="Foo">Foo</h2>
402 <h3 id="Bar">Bar</h3>
404 <h1 id="Baz">Baz</h1>
406 <h4 id="Drink">Drink</h4>
408 <h3 id="Sip">Sip</h3>
410 <h4 id="Ouch">Ouch</h4>
412 <h1 id="Drip">Drip</h1>
416 initialize($parser, $results);
417 $parser->html_header($header);
418 $parser->html_footer($footer);
419 $parser->backlink(1);
420 ok $parser->parse_string_document( '=head1 Foo' ), 'Parse a header';
421 is $results, <<'EOF', 'Should have the index and a backlink';
426 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
432 <li><a href="#Foo">Foo</a></li>
435 <a href="#_podtop_"><h1 id="Foo">Foo</h1></a>
442 initialize($parser, $results);
443 $parser->html_header($header);
444 $parser->html_footer($footer);
445 $parser->backlink(1);
446 ok $parser->parse_string_document( "=head1 Foo \n\n=head2 Bar \n\n=head1 Baz" ), 'Parse headers';
447 is $results, <<'EOF', 'Should have the index and backlinks';
452 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
458 <li><a href="#Foo">Foo</a>
460 <li><a href="#Bar">Bar</a></li>
463 <li><a href="#Baz">Baz</a></li>
466 <a href="#_podtop_"><h1 id="Foo">Foo</h1></a>
468 <h2 id="Bar">Bar</h2>
470 <a href="#_podtop_"><h1 id="Baz">Baz</h1></a>
477 initialize($parser, $results);
478 $parser->html_header($header);
479 $parser->html_footer($footer);
481 $parser->backlink(1);
482 ok $parser->parse_string_document( "=head1 Foo \n\n=head1 Bar" ), 'Parse headers';
483 is $results, <<'EOF', 'Should have backlinks but no index';
488 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
493 <a href="#_podtop_"><h1 id="Foo">Foo</h1></a>
495 <a href="#_podtop_"><h1 id="Bar">Bar</h1></a>
502 initialize($parser, $results);
503 $parser->html_header($header);
504 $parser->html_footer($footer);
505 $parser->backlink(1);
506 $parser->html_h_level(2);
507 ok $parser->parse_string_document( "=head1 Foo \n\n=head1 Bar" ), 'Parse headers';
508 is $results, <<'EOF', 'Should have index and backlinks around h2 elements';
513 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
521 <li><a href="#Foo">Foo</a></li>
522 <li><a href="#Bar">Bar</a></li>
527 <a href="#_podtop_"><h2 id="Foo">Foo</h2></a>
529 <a href="#_podtop_"><h2 id="Bar">Bar</h2></a>
536 initialize($parser, $results);
537 $parser->anchor_items(1);
538 ok $parser->parse_string_document( <<'EOPOD' ), 'Parse POD';
568 is $results, <<'EOF', 'Anchor =item directives';
570 <li><a href="#Foo">Foo</a></li>
573 <h1 id="Foo">Foo</h1>
577 <dt id="test">test</dt>
581 <dt id="Test-2">Test 2</dt>
591 <li><p>not anchored</p>
598 <li><p>still not anchored</p>
605 initialize($parser, $results);
606 $parser->anchor_items(0);
607 ok $parser->parse_string_document( <<'EOPOD' ), 'Parse POD';
636 is $results, <<'EOF', 'Do not anchor =item directives';
638 <li><a href="#Foo">Foo</a></li>
641 <h1 id="Foo">Foo</h1>
659 <li><p>not anchored</p>
666 <li><p>still not anchored</p>
675 initialize($parser, $results);
676 ok $parser->parse_string_document( <<'EOPOD' ), 'Parse POD';
679 Test links from perlpodspec: L</"About LE<lt>...E<gt> Codes">
681 =head1 About LE<lt>...E<gt> Codes
686 my $id = 'About-L...-Codes'; # what should this be?
688 is $results, <<EOF, 'anchor and h1 use same section id for complex sections';
690 <li><a href="#Foo">Foo</a></li>
691 <li><a href="#$id">About L<...> Codes</a></li>
694 <h1 id="Foo">Foo</h1>
696 <p>Test links from perlpodspec: <a href="#$id">"About L<...> Codes"</a></p>
698 <h1 id="$id">About L<...> Codes</h1>
705 $_[0] = Pod::Simple::XHTML->new;
706 $_[0]->html_header('');
707 $_[0]->html_footer('');
709 $_[0]->output_string( \$results ); # Send the resulting output to a string