xref: /openbsd-src/gnu/usr.bin/perl/cpan/Pod-Simple/t/xhtml10.t (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
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';
11use Test::More tests => 44;
12#use Test::More 'no_plan';
13
14use_ok('Pod::Simple::XHTML') or exit;
15
16isa_ok my $parser = Pod::Simple::XHTML->new, 'Pod::Simple::XHTML';
17my $header = $parser->html_header;
18my $footer = $parser->html_footer;
19
20for my $spec (
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-.:' ],
27) {
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]"};
32}
33
34my $results;
35
36initialize($parser, $results);
37$parser->html_header($header);
38$parser->html_footer($footer);
39ok $parser->parse_string_document( '=head1 Foo' ), 'Parse one header';
40is $results, <<'EOF', 'Should have the index';
41
42<html>
43<head>
44<title></title>
45<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
46</head>
47<body>
48
49
50<ul id="index">
51  <li><a href="#Foo">Foo</a></li>
52</ul>
53
54<h1 id="Foo">Foo</h1>
55
56</body>
57</html>
58
59EOF
60
61initialize($parser, $results);
62ok $parser->parse_string_document( '=head1 Foo Bar' ), 'Parse multiword header';
63is $results, <<'EOF', 'Should have the index';
64<ul id="index">
65  <li><a href="#Foo-Bar">Foo Bar</a></li>
66</ul>
67
68<h1 id="Foo-Bar">Foo Bar</h1>
69
70EOF
71
72initialize($parser, $results);
73ok $parser->parse_string_document( "=head1 Foo B<Bar>\n\n=head1 Foo B<Baz>" ),
74    'Parse two multiword headers';
75is $results, <<'EOF', 'Should have the index';
76<ul id="index">
77  <li><a href="#Foo-Bar">Foo <b>Bar</b></a></li>
78  <li><a href="#Foo-Baz">Foo <b>Baz</b></a></li>
79</ul>
80
81<h1 id="Foo-Bar">Foo <b>Bar</b></h1>
82
83<h1 id="Foo-Baz">Foo <b>Baz</b></h1>
84
85EOF
86
87initialize($parser, $results);
88ok $parser->parse_string_document( "=head1 Foo\n\n=head1 Bar" ), 'Parse two headers';
89is $results, <<'EOF', 'Should have both and the index';
90<ul id="index">
91  <li><a href="#Foo">Foo</a></li>
92  <li><a href="#Bar">Bar</a></li>
93</ul>
94
95<h1 id="Foo">Foo</h1>
96
97<h1 id="Bar">Bar</h1>
98
99EOF
100initialize($parser, $results);
101ok $parser->parse_string_document( "=head1 Foo\n\n=head1 Bar\n\n=head1 Baz" ),
102    'Parse three headers';
103is $results, <<'EOF', 'Should have all three and the index';
104<ul id="index">
105  <li><a href="#Foo">Foo</a></li>
106  <li><a href="#Bar">Bar</a></li>
107  <li><a href="#Baz">Baz</a></li>
108</ul>
109
110<h1 id="Foo">Foo</h1>
111
112<h1 id="Bar">Bar</h1>
113
114<h1 id="Baz">Baz</h1>
115
116EOF
117
118initialize($parser, $results);
119ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar" ), 'Parse two levels';
120is $results, <<'EOF', 'Should have the dual-level index';
121<ul id="index">
122  <li><a href="#Foo">Foo</a>
123    <ul>
124      <li><a href="#Bar">Bar</a></li>
125    </ul>
126  </li>
127</ul>
128
129<h1 id="Foo">Foo</h1>
130
131<h2 id="Bar">Bar</h2>
132
133EOF
134
135initialize($parser, $results);
136ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head3 Baz" ),
137    'Parse three levels';
138is $results, <<'EOF', 'Should have the three-level index';
139<ul id="index">
140  <li><a href="#Foo">Foo</a>
141    <ul>
142      <li><a href="#Bar">Bar</a>
143        <ul>
144          <li><a href="#Baz">Baz</a></li>
145        </ul>
146      </li>
147    </ul>
148  </li>
149</ul>
150
151<h1 id="Foo">Foo</h1>
152
153<h2 id="Bar">Bar</h2>
154
155<h3 id="Baz">Baz</h3>
156
157EOF
158
159initialize($parser, $results);
160ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head3 Baz\n\n=head4 Howdy" ),
161    'Parse four levels';
162is $results, <<'EOF', 'Should have the four-level index';
163<ul id="index">
164  <li><a href="#Foo">Foo</a>
165    <ul>
166      <li><a href="#Bar">Bar</a>
167        <ul>
168          <li><a href="#Baz">Baz</a>
169            <ul>
170              <li><a href="#Howdy">Howdy</a></li>
171            </ul>
172          </li>
173        </ul>
174      </li>
175    </ul>
176  </li>
177</ul>
178
179<h1 id="Foo">Foo</h1>
180
181<h2 id="Bar">Bar</h2>
182
183<h3 id="Baz">Baz</h3>
184
185<h4 id="Howdy">Howdy</h4>
186
187EOF
188
189initialize($parser, $results);
190ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head2 Baz" ),
191    'Parse 1/2';
192is $results, <<'EOF', 'Should have the 1/s index';
193<ul id="index">
194  <li><a href="#Foo">Foo</a>
195    <ul>
196      <li><a href="#Bar">Bar</a></li>
197      <li><a href="#Baz">Baz</a></li>
198    </ul>
199  </li>
200</ul>
201
202<h1 id="Foo">Foo</h1>
203
204<h2 id="Bar">Bar</h2>
205
206<h2 id="Baz">Baz</h2>
207
208EOF
209
210initialize($parser, $results);
211ok $parser->parse_string_document( "=head1 Foo\n\n=head3 Bar" ), 'Parse jump from one to three';
212is $results, <<'EOF', 'Should have the 1-3 index';
213<ul id="index">
214  <li><a href="#Foo">Foo</a>
215    <ul>
216      <li>
217        <ul>
218          <li><a href="#Bar">Bar</a></li>
219        </ul>
220      </li>
221    </ul>
222  </li>
223</ul>
224
225<h1 id="Foo">Foo</h1>
226
227<h3 id="Bar">Bar</h3>
228
229EOF
230
231initialize($parser, $results);
232ok $parser->parse_string_document( "=head1 Foo\n\n=head4 Bar" ), 'Parse jump from one to four';
233is $results, <<'EOF', 'Should have the 1-4 index';
234<ul id="index">
235  <li><a href="#Foo">Foo</a>
236    <ul>
237      <li>
238        <ul>
239          <li>
240            <ul>
241              <li><a href="#Bar">Bar</a></li>
242            </ul>
243          </li>
244        </ul>
245      </li>
246    </ul>
247  </li>
248</ul>
249
250<h1 id="Foo">Foo</h1>
251
252<h4 id="Bar">Bar</h4>
253
254EOF
255
256initialize($parser, $results);
257ok $parser->parse_string_document( "=head2 Foo\n\n=head1 Bar" ),
258    'Parse two down to 1';
259is $results, <<'EOF', 'Should have the 2-1 index';
260<ul id="index">
261  <li>
262    <ul>
263      <li><a href="#Foo">Foo</a></li>
264    </ul>
265  </li>
266  <li><a href="#Bar">Bar</a></li>
267</ul>
268
269<h2 id="Foo">Foo</h2>
270
271<h1 id="Bar">Bar</h1>
272
273EOF
274
275initialize($parser, $results);
276ok $parser->parse_string_document( "=head2 Foo\n\n=head1 Bar\n\n=head4 Four\n\n=head4 Four2" ),
277    'Parse two down to 1';
278is $results, <<'EOF', 'Should have the 2-1 index';
279<ul id="index">
280  <li>
281    <ul>
282      <li><a href="#Foo">Foo</a></li>
283    </ul>
284  </li>
285  <li><a href="#Bar">Bar</a>
286    <ul>
287      <li>
288        <ul>
289          <li>
290            <ul>
291              <li><a href="#Four">Four</a></li>
292              <li><a href="#Four2">Four2</a></li>
293            </ul>
294          </li>
295        </ul>
296      </li>
297    </ul>
298  </li>
299</ul>
300
301<h2 id="Foo">Foo</h2>
302
303<h1 id="Bar">Bar</h1>
304
305<h4 id="Four">Four</h4>
306
307<h4 id="Four2">Four2</h4>
308
309EOF
310
311initialize($parser, $results);
312ok $parser->parse_string_document( "=head4 Foo" ),
313    'Parse just a four';
314is $results, <<'EOF', 'Should have the 2-1 index';
315<ul id="index">
316  <li>
317    <ul>
318      <li>
319        <ul>
320          <li>
321            <ul>
322              <li><a href="#Foo">Foo</a></li>
323            </ul>
324          </li>
325        </ul>
326      </li>
327    </ul>
328  </li>
329</ul>
330
331<h4 id="Foo">Foo</h4>
332
333EOF
334
335initialize($parser, $results);
336ok $parser->parse_string_document( <<'EOF' ), 'Parse a mixture';
337=head2 Foo
338
339=head3 Bar
340
341=head1 Baz
342
343=head4 Drink
344
345=head3 Sip
346
347=head4 Ouch
348
349=head1 Drip
350EOF
351
352is $results, <<'EOF', 'And it should work!';
353<ul id="index">
354  <li>
355    <ul>
356      <li><a href="#Foo">Foo</a>
357        <ul>
358          <li><a href="#Bar">Bar</a></li>
359        </ul>
360      </li>
361    </ul>
362  </li>
363  <li><a href="#Baz">Baz</a>
364    <ul>
365      <li>
366        <ul>
367          <li>
368            <ul>
369              <li><a href="#Drink">Drink</a></li>
370            </ul>
371          </li>
372          <li><a href="#Sip">Sip</a>
373            <ul>
374              <li><a href="#Ouch">Ouch</a></li>
375            </ul>
376          </li>
377        </ul>
378      </li>
379    </ul>
380  </li>
381  <li><a href="#Drip">Drip</a></li>
382</ul>
383
384<h2 id="Foo">Foo</h2>
385
386<h3 id="Bar">Bar</h3>
387
388<h1 id="Baz">Baz</h1>
389
390<h4 id="Drink">Drink</h4>
391
392<h3 id="Sip">Sip</h3>
393
394<h4 id="Ouch">Ouch</h4>
395
396<h1 id="Drip">Drip</h1>
397
398EOF
399
400sub initialize {
401	$_[0] = Pod::Simple::XHTML->new;
402        $_[0]->html_header('');
403        $_[0]->html_footer('');
404        $_[0]->index(1);
405	$_[0]->output_string( \$results ); # Send the resulting output to a string
406	$_[1] = '';
407	return;
408}
409