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