xref: /openbsd-src/gnu/usr.bin/perl/cpan/Pod-Simple/t/xhtml10.t (revision 5486feefcc8cb79b19e014ab332cc5dfd05b3b33)
1# t/xhtml01.t - check basic output from Pod::Simple::XHTML
2use strict;
3use warnings;
4use Test::More tests => 62;
5
6use_ok('Pod::Simple::XHTML') or exit;
7
8isa_ok my $parser = Pod::Simple::XHTML->new, 'Pod::Simple::XHTML';
9my $header = $parser->html_header;
10my $footer = $parser->html_footer;
11
12for my $spec (
13    [ 'foo'    => 'foo',   'foo'     ],
14    [ '12foo'  => 'foo1',  'foo'     ],
15    [ 'fo$bar' => 'fo-bar', 'fo-bar' ],
16    [ 'f12'    => 'f12',    'f12'    ],
17    [ '13'     => 'pod13',  'pod13'  ],
18    [ '**.:'   => 'pod', 'pod' ],
19) {
20    is $parser->idify( $spec->[0] ), $spec->[1],
21        qq{ID for "$spec->[0]" should be "$spec->[1]"};
22    is $parser->idify( $spec->[0], 1 ), $spec->[2],
23        qq{Non-unique ID for "$spec->[0]" should be "$spec->[2]"};
24}
25
26my $results;
27
28initialize($parser, $results);
29$parser->html_header($header);
30$parser->html_footer($footer);
31ok $parser->parse_string_document( '=head1 Foo' ), 'Parse one header';
32is $results, <<'EOF', 'Should have the index';
33
34<html>
35<head>
36<title></title>
37<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
38</head>
39<body>
40
41
42<ul id="index">
43  <li><a href="#Foo">Foo</a></li>
44</ul>
45
46<h1 id="Foo">Foo</h1>
47
48</body>
49</html>
50
51EOF
52
53initialize($parser, $results);
54ok $parser->parse_string_document( '=head1 Foo Bar' ), 'Parse multiword header';
55is $results, <<'EOF', 'Should have the index';
56<ul id="index">
57  <li><a href="#Foo-Bar">Foo Bar</a></li>
58</ul>
59
60<h1 id="Foo-Bar">Foo Bar</h1>
61
62EOF
63
64initialize($parser, $results);
65ok $parser->parse_string_document( "=head1 Foo B<Bar>\n\n=head1 Foo B<Baz>" ),
66    'Parse two multiword headers';
67is $results, <<'EOF', 'Should have the index';
68<ul id="index">
69  <li><a href="#Foo-Bar">Foo Bar</a></li>
70  <li><a href="#Foo-Baz">Foo Baz</a></li>
71</ul>
72
73<h1 id="Foo-Bar">Foo <b>Bar</b></h1>
74
75<h1 id="Foo-Baz">Foo <b>Baz</b></h1>
76
77EOF
78
79initialize($parser, $results);
80ok $parser->parse_string_document( "=head1 Foo\n\n=head1 Bar" ), 'Parse two headers';
81is $results, <<'EOF', 'Should have both and the index';
82<ul id="index">
83  <li><a href="#Foo">Foo</a></li>
84  <li><a href="#Bar">Bar</a></li>
85</ul>
86
87<h1 id="Foo">Foo</h1>
88
89<h1 id="Bar">Bar</h1>
90
91EOF
92
93initialize($parser, $results);
94ok $parser->parse_string_document( "=head1 Foo C<Bar>\n\n=head1 C<Baz>" ),
95    'Parse two headers with C<> formatting';
96is $results, <<'EOF', 'Should have the index';
97<ul id="index">
98  <li><a href="#Foo-Bar">Foo Bar</a></li>
99  <li><a href="#Baz">Baz</a></li>
100</ul>
101
102<h1 id="Foo-Bar">Foo <code>Bar</code></h1>
103
104<h1 id="Baz"><code>Baz</code></h1>
105
106EOF
107
108initialize($parser, $results);
109ok $parser->parse_string_document( "=head1 Foo\n\n=head1 Bar\n\n=head1 Baz" ),
110    'Parse three headers';
111is $results, <<'EOF', 'Should have all three and the index';
112<ul id="index">
113  <li><a href="#Foo">Foo</a></li>
114  <li><a href="#Bar">Bar</a></li>
115  <li><a href="#Baz">Baz</a></li>
116</ul>
117
118<h1 id="Foo">Foo</h1>
119
120<h1 id="Bar">Bar</h1>
121
122<h1 id="Baz">Baz</h1>
123
124EOF
125
126initialize($parser, $results);
127ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar" ), 'Parse two levels';
128is $results, <<'EOF', 'Should have the dual-level index';
129<ul id="index">
130  <li><a href="#Foo">Foo</a>
131    <ul>
132      <li><a href="#Bar">Bar</a></li>
133    </ul>
134  </li>
135</ul>
136
137<h1 id="Foo">Foo</h1>
138
139<h2 id="Bar">Bar</h2>
140
141EOF
142
143initialize($parser, $results);
144ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head3 Baz" ),
145    'Parse three levels';
146is $results, <<'EOF', 'Should have the three-level index';
147<ul id="index">
148  <li><a href="#Foo">Foo</a>
149    <ul>
150      <li><a href="#Bar">Bar</a>
151        <ul>
152          <li><a href="#Baz">Baz</a></li>
153        </ul>
154      </li>
155    </ul>
156  </li>
157</ul>
158
159<h1 id="Foo">Foo</h1>
160
161<h2 id="Bar">Bar</h2>
162
163<h3 id="Baz">Baz</h3>
164
165EOF
166
167initialize($parser, $results);
168ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head3 Baz\n\n=head4 Howdy" ),
169    'Parse four levels';
170is $results, <<'EOF', 'Should have the four-level index';
171<ul id="index">
172  <li><a href="#Foo">Foo</a>
173    <ul>
174      <li><a href="#Bar">Bar</a>
175        <ul>
176          <li><a href="#Baz">Baz</a>
177            <ul>
178              <li><a href="#Howdy">Howdy</a></li>
179            </ul>
180          </li>
181        </ul>
182      </li>
183    </ul>
184  </li>
185</ul>
186
187<h1 id="Foo">Foo</h1>
188
189<h2 id="Bar">Bar</h2>
190
191<h3 id="Baz">Baz</h3>
192
193<h4 id="Howdy">Howdy</h4>
194
195EOF
196
197initialize($parser, $results);
198ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head3 Baz\n\n=head4 Howdy\n\n=head5 Deep\n\n=head6 Thought" ),
199    'Parse six levels';
200is $results, <<'EOF', 'Should have the six-level index';
201<ul id="index">
202  <li><a href="#Foo">Foo</a>
203    <ul>
204      <li><a href="#Bar">Bar</a>
205        <ul>
206          <li><a href="#Baz">Baz</a>
207            <ul>
208              <li><a href="#Howdy">Howdy</a>
209                <ul>
210                  <li><a href="#Deep">Deep</a>
211                    <ul>
212                      <li><a href="#Thought">Thought</a></li>
213                    </ul>
214                  </li>
215                </ul>
216              </li>
217            </ul>
218          </li>
219        </ul>
220      </li>
221    </ul>
222  </li>
223</ul>
224
225<h1 id="Foo">Foo</h1>
226
227<h2 id="Bar">Bar</h2>
228
229<h3 id="Baz">Baz</h3>
230
231<h4 id="Howdy">Howdy</h4>
232
233<h5 id="Deep">Deep</h5>
234
235<h6 id="Thought">Thought</h6>
236
237EOF
238
239initialize($parser, $results);
240ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head2 Baz" ),
241    'Parse 1/2';
242is $results, <<'EOF', 'Should have the 1/s index';
243<ul id="index">
244  <li><a href="#Foo">Foo</a>
245    <ul>
246      <li><a href="#Bar">Bar</a></li>
247      <li><a href="#Baz">Baz</a></li>
248    </ul>
249  </li>
250</ul>
251
252<h1 id="Foo">Foo</h1>
253
254<h2 id="Bar">Bar</h2>
255
256<h2 id="Baz">Baz</h2>
257
258EOF
259
260initialize($parser, $results);
261ok $parser->parse_string_document( "=head1 Foo\n\n=head3 Bar" ), 'Parse jump from one to three';
262is $results, <<'EOF', 'Should have the 1-3 index';
263<ul id="index">
264  <li><a href="#Foo">Foo</a>
265    <ul>
266      <li>
267        <ul>
268          <li><a href="#Bar">Bar</a></li>
269        </ul>
270      </li>
271    </ul>
272  </li>
273</ul>
274
275<h1 id="Foo">Foo</h1>
276
277<h3 id="Bar">Bar</h3>
278
279EOF
280
281initialize($parser, $results);
282ok $parser->parse_string_document( "=head1 Foo\n\n=head4 Bar" ), 'Parse jump from one to four';
283is $results, <<'EOF', 'Should have the 1-4 index';
284<ul id="index">
285  <li><a href="#Foo">Foo</a>
286    <ul>
287      <li>
288        <ul>
289          <li>
290            <ul>
291              <li><a href="#Bar">Bar</a></li>
292            </ul>
293          </li>
294        </ul>
295      </li>
296    </ul>
297  </li>
298</ul>
299
300<h1 id="Foo">Foo</h1>
301
302<h4 id="Bar">Bar</h4>
303
304EOF
305
306initialize($parser, $results);
307ok $parser->parse_string_document( "=head2 Foo\n\n=head1 Bar" ),
308    'Parse two down to 1';
309is $results, <<'EOF', 'Should have the 2-1 index';
310<ul id="index">
311  <li>
312    <ul>
313      <li><a href="#Foo">Foo</a></li>
314    </ul>
315  </li>
316  <li><a href="#Bar">Bar</a></li>
317</ul>
318
319<h2 id="Foo">Foo</h2>
320
321<h1 id="Bar">Bar</h1>
322
323EOF
324
325initialize($parser, $results);
326ok $parser->parse_string_document( "=head2 Foo\n\n=head1 Bar\n\n=head4 Four\n\n=head4 Four2" ),
327    'Parse two down to 1';
328is $results, <<'EOF', 'Should have the 2-1 index';
329<ul id="index">
330  <li>
331    <ul>
332      <li><a href="#Foo">Foo</a></li>
333    </ul>
334  </li>
335  <li><a href="#Bar">Bar</a>
336    <ul>
337      <li>
338        <ul>
339          <li>
340            <ul>
341              <li><a href="#Four">Four</a></li>
342              <li><a href="#Four2">Four2</a></li>
343            </ul>
344          </li>
345        </ul>
346      </li>
347    </ul>
348  </li>
349</ul>
350
351<h2 id="Foo">Foo</h2>
352
353<h1 id="Bar">Bar</h1>
354
355<h4 id="Four">Four</h4>
356
357<h4 id="Four2">Four2</h4>
358
359EOF
360
361initialize($parser, $results);
362ok $parser->parse_string_document( "=head4 Foo" ),
363    'Parse just a four';
364is $results, <<'EOF', 'Should have the 2-1 index';
365<ul id="index">
366  <li>
367    <ul>
368      <li>
369        <ul>
370          <li>
371            <ul>
372              <li><a href="#Foo">Foo</a></li>
373            </ul>
374          </li>
375        </ul>
376      </li>
377    </ul>
378  </li>
379</ul>
380
381<h4 id="Foo">Foo</h4>
382
383EOF
384
385initialize($parser, $results);
386ok $parser->parse_string_document( <<'EOF' ), 'Parse a mixture';
387=head2 Foo
388
389=head3 Bar
390
391=head1 Baz
392
393=head4 Drink
394
395=head3 Sip
396
397=head4 Ouch
398
399=head1 Drip
400EOF
401
402is $results, <<'EOF', 'And it should work!';
403<ul id="index">
404  <li>
405    <ul>
406      <li><a href="#Foo">Foo</a>
407        <ul>
408          <li><a href="#Bar">Bar</a></li>
409        </ul>
410      </li>
411    </ul>
412  </li>
413  <li><a href="#Baz">Baz</a>
414    <ul>
415      <li>
416        <ul>
417          <li>
418            <ul>
419              <li><a href="#Drink">Drink</a></li>
420            </ul>
421          </li>
422          <li><a href="#Sip">Sip</a>
423            <ul>
424              <li><a href="#Ouch">Ouch</a></li>
425            </ul>
426          </li>
427        </ul>
428      </li>
429    </ul>
430  </li>
431  <li><a href="#Drip">Drip</a></li>
432</ul>
433
434<h2 id="Foo">Foo</h2>
435
436<h3 id="Bar">Bar</h3>
437
438<h1 id="Baz">Baz</h1>
439
440<h4 id="Drink">Drink</h4>
441
442<h3 id="Sip">Sip</h3>
443
444<h4 id="Ouch">Ouch</h4>
445
446<h1 id="Drip">Drip</h1>
447
448EOF
449
450initialize($parser, $results);
451$parser->html_header($header);
452$parser->html_footer($footer);
453$parser->backlink(1);
454ok $parser->parse_string_document( '=head1 Foo' ), 'Parse a header';
455is $results, <<'EOF', 'Should have the index and a backlink';
456
457<html>
458<head>
459<title></title>
460<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
461</head>
462<body id="_podtop_">
463
464
465<ul id="index">
466  <li><a href="#Foo">Foo</a></li>
467</ul>
468
469<a href="#_podtop_"><h1 id="Foo">Foo</h1></a>
470
471</body>
472</html>
473
474EOF
475
476initialize($parser, $results);
477$parser->html_header($header);
478$parser->html_footer($footer);
479$parser->backlink(1);
480ok $parser->parse_string_document( "=head1 Foo \n\n=head2 Bar \n\n=head1 Baz" ), 'Parse headers';
481is $results, <<'EOF', 'Should have the index and backlinks';
482
483<html>
484<head>
485<title></title>
486<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
487</head>
488<body id="_podtop_">
489
490
491<ul id="index">
492  <li><a href="#Foo">Foo</a>
493    <ul>
494      <li><a href="#Bar">Bar</a></li>
495    </ul>
496  </li>
497  <li><a href="#Baz">Baz</a></li>
498</ul>
499
500<a href="#_podtop_"><h1 id="Foo">Foo</h1></a>
501
502<h2 id="Bar">Bar</h2>
503
504<a href="#_podtop_"><h1 id="Baz">Baz</h1></a>
505
506</body>
507</html>
508
509EOF
510
511initialize($parser, $results);
512$parser->html_header($header);
513$parser->html_footer($footer);
514$parser->index(0);
515$parser->backlink(1);
516ok $parser->parse_string_document( "=head1 Foo \n\n=head1 Bar" ), 'Parse headers';
517is $results, <<'EOF', 'Should have backlinks but no index';
518
519<html>
520<head>
521<title></title>
522<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
523</head>
524<body id="_podtop_">
525
526
527<a href="#_podtop_"><h1 id="Foo">Foo</h1></a>
528
529<a href="#_podtop_"><h1 id="Bar">Bar</h1></a>
530
531</body>
532</html>
533
534EOF
535
536initialize($parser, $results);
537$parser->html_header($header);
538$parser->html_footer($footer);
539$parser->backlink(1);
540$parser->html_h_level(2);
541ok $parser->parse_string_document( "=head1 Foo \n\n=head1 Bar" ), 'Parse headers';
542is $results, <<'EOF', 'Should have index and backlinks around h2 elements';
543
544<html>
545<head>
546<title></title>
547<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
548</head>
549<body id="_podtop_">
550
551
552<ul id="index">
553  <li>
554    <ul>
555      <li><a href="#Foo">Foo</a></li>
556      <li><a href="#Bar">Bar</a></li>
557    </ul>
558  </li>
559</ul>
560
561<a href="#_podtop_"><h2 id="Foo">Foo</h2></a>
562
563<a href="#_podtop_"><h2 id="Bar">Bar</h2></a>
564
565</body>
566</html>
567
568EOF
569
570initialize($parser, $results);
571$parser->anchor_items(1);
572ok $parser->parse_string_document( <<'EOPOD' ), 'Parse POD';
573=head1 Foo
574
575=over
576
577=item test
578
579=item Test 2
580
581body of item
582
583=back
584
585=over
586
587=item *
588
589not anchored
590
591=back
592
593=over
594
595=item 1
596
597still not anchored
598
599=back
600EOPOD
601
602is $results, <<'EOF', 'Anchor =item directives';
603<ul id="index">
604  <li><a href="#Foo">Foo</a></li>
605</ul>
606
607<h1 id="Foo">Foo</h1>
608
609<dl>
610
611<dt id="test">test</dt>
612<dd>
613
614</dd>
615<dt id="Test-2">Test 2</dt>
616<dd>
617
618<p>body of item</p>
619
620</dd>
621</dl>
622
623<ul>
624
625<li><p>not anchored</p>
626
627</li>
628</ul>
629
630<ol>
631
632<li><p>still not anchored</p>
633
634</li>
635</ol>
636
637EOF
638
639initialize($parser, $results);
640$parser->anchor_items(0);
641ok $parser->parse_string_document( <<'EOPOD' ), 'Parse POD';
642=head1 Foo
643
644=over
645
646=item test
647
648=item Test 2
649
650body of item
651
652=back
653
654=over
655
656=item *
657
658not anchored
659
660=back
661
662=over
663
664=item 1
665
666still not anchored
667
668=back
669EOPOD
670is $results, <<'EOF', 'Do not anchor =item directives';
671<ul id="index">
672  <li><a href="#Foo">Foo</a></li>
673</ul>
674
675<h1 id="Foo">Foo</h1>
676
677<dl>
678
679<dt>test</dt>
680<dd>
681
682</dd>
683<dt>Test 2</dt>
684<dd>
685
686<p>body of item</p>
687
688</dd>
689</dl>
690
691<ul>
692
693<li><p>not anchored</p>
694
695</li>
696</ul>
697
698<ol>
699
700<li><p>still not anchored</p>
701
702</li>
703</ol>
704
705EOF
706
707$ENV{FOO}= 1;
708
709initialize($parser, $results);
710ok $parser->parse_string_document( <<'EOPOD' ), 'Parse POD';
711=head1 Foo
712
713Test links from perlpodspec: L</"About LE<lt>...E<gt> Codes">
714
715=head1 About LE<lt>...E<gt> Codes
716
717Here it is
718EOPOD
719
720my $id = 'About-L...-Codes'; # what should this be?
721
722is $results, <<EOF, 'anchor and h1 use same section id for complex sections';
723<ul id="index">
724  <li><a href="#Foo">Foo</a></li>
725  <li><a href="#$id">About L&lt;...&gt; Codes</a></li>
726</ul>
727
728<h1 id="Foo">Foo</h1>
729
730<p>Test links from perlpodspec: <a href="#$id">&quot;About L&lt;...&gt; Codes&quot;</a></p>
731
732<h1 id="$id">About L&lt;...&gt; Codes</h1>
733
734<p>Here it is</p>
735
736EOF
737
738sub initialize {
739    $_[0] = Pod::Simple::XHTML->new;
740        $_[0]->html_header('');
741        $_[0]->html_footer('');
742        $_[0]->index(1);
743    $_[0]->output_string( \$results ); # Send the resulting output to a string
744    $_[1] = '';
745    return;
746}
747