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 => 48;
12#use Test::More 'no_plan';
13
14use_ok('Pod::Simple::XHTML') or exit;
15
16my $parser = Pod::Simple::XHTML->new ();
17isa_ok ($parser, 'Pod::Simple::XHTML');
18
19my $results;
20
21my $PERLDOC = "http://search.cpan.org/perldoc";
22my $MANURL = "http://man.he.net/man";
23
24initialize($parser, $results);
25$parser->parse_string_document( "=head1 Poit!" );
26is($results, qq{<h1 id="Poit-">Poit!</h1>\n\n}, "head1 level output");
27
28initialize($parser, $results);
29$parser->html_h_level(2);
30$parser->parse_string_document( "=head1 Poit!" );
31is($results, qq{<h2 id="Poit-">Poit!</h2>\n\n}, "head1 level output h_level 2");
32
33initialize($parser, $results);
34$parser->parse_string_document( "=head2 I think so Brain." );
35is($results, qq{<h2 id="I-think-so-Brain.">I think so Brain.</h2>\n\n}, "head2 level output");
36
37initialize($parser, $results);
38$parser->parse_string_document( "=head3 I say, Brain..." );
39is($results, qq{<h3 id="I-say-Brain...">I say, Brain...</h3>\n\n}, "head3 level output");
40
41initialize($parser, $results);
42$parser->parse_string_document( "=head4 Zort & Zog!" );
43is($results, qq{<h4 id="Zort-Zog-">Zort &amp; Zog!</h4>\n\n}, "head4 level output");
44
45sub x ($;&) {
46  my $code = $_[1];
47  Pod::Simple::XHTML->_out(
48  sub { $code->($_[0]) if $code },
49  "=pod\n\n$_[0]",
50) }
51
52like(
53  x("=head1 Header\n\n=for html <div>RAW<span>!</span></div>\n\nDone."),
54  qr/.+<\/h1>\s+<div>RAW<span>!<\/span><\/div>\s+.*/sm,
55  "heading building"
56) or exit;
57
58initialize($parser, $results);
59$parser->parse_string_document(<<'EOPOD');
60=pod
61
62Gee, Brain, what do you want to do tonight?
63EOPOD
64
65is($results, <<'EOHTML', "simple paragraph");
66<p>Gee, Brain, what do you want to do tonight?</p>
67
68EOHTML
69
70
71initialize($parser, $results);
72$parser->parse_string_document(<<'EOPOD');
73=pod
74
75B: Now, Pinky, if by any chance you are captured during this mission,
76remember you are Gunther Heindriksen from Appenzell. You moved to
77Grindelwald to drive the cog train to Murren. Can you repeat that?
78
79P: Mmmm, no, Brain, don't think I can.
80EOPOD
81
82is($results, <<'EOHTML', "multiple paragraphs");
83<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>
84
85<p>P: Mmmm, no, Brain, don&#39;t think I can.</p>
86
87EOHTML
88
89initialize($parser, $results);
90$parser->parse_string_document(<<'EOPOD');
91=over
92
93=item *
94
95P: Gee, Brain, what do you want to do tonight?
96
97=item *
98
99B: The same thing we do every night, Pinky. Try to take over the world!
100
101=back
102
103EOPOD
104
105is($results, <<'EOHTML', "simple bulleted list");
106<ul>
107
108<li><p>P: Gee, Brain, what do you want to do tonight?</p>
109
110</li>
111<li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>
112
113</li>
114</ul>
115
116EOHTML
117
118
119initialize($parser, $results);
120$parser->parse_string_document(<<'EOPOD');
121=over
122
123=item 1
124
125P: Gee, Brain, what do you want to do tonight?
126
127=item 2
128
129B: The same thing we do every night, Pinky. Try to take over the world!
130
131=back
132
133EOPOD
134
135is($results, <<'EOHTML', "numbered list");
136<ol>
137
138<li><p>P: Gee, Brain, what do you want to do tonight?</p>
139
140</li>
141<li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>
142
143</li>
144</ol>
145
146EOHTML
147
148
149initialize($parser, $results);
150$parser->parse_string_document(<<'EOPOD');
151=over
152
153=item Pinky
154
155Gee, Brain, what do you want to do tonight?
156
157=item Brain
158
159The same thing we do every night, Pinky. Try to take over the world!
160
161=back
162
163EOPOD
164
165is($results, <<'EOHTML', "list with text headings");
166<dl>
167
168<dt>Pinky</dt>
169<dd>
170
171<p>Gee, Brain, what do you want to do tonight?</p>
172
173</dd>
174<dt>Brain</dt>
175<dd>
176
177<p>The same thing we do every night, Pinky. Try to take over the world!</p>
178
179</dd>
180</dl>
181
182EOHTML
183
184initialize($parser, $results);
185$parser->parse_string_document(<<'EOPOD');
186=over
187
188=item * Pinky
189
190Gee, Brain, what do you want to do tonight?
191
192=item * Brain
193
194The same thing we do every night, Pinky. Try to take over the world!
195
196=back
197
198EOPOD
199
200is($results, <<'EOHTML', "list with bullet and text headings");
201<ul>
202
203<li><p>Pinky</p>
204
205<p>Gee, Brain, what do you want to do tonight?</p>
206
207</li>
208<li><p>Brain</p>
209
210<p>The same thing we do every night, Pinky. Try to take over the world!</p>
211
212</li>
213</ul>
214
215EOHTML
216
217initialize($parser, $results);
218$parser->parse_string_document(<<'EOPOD');
219=over
220
221=item * Brain <brain@binkyandthebrain.com>
222
223=item * Pinky <pinky@binkyandthebrain.com>
224
225=back
226
227EOPOD
228
229is($results, <<'EOHTML', "bulleted author list");
230<ul>
231
232<li><p>Brain &lt;brain@binkyandthebrain.com&gt;</p>
233
234</li>
235<li><p>Pinky &lt;pinky@binkyandthebrain.com&gt;</p>
236
237</li>
238</ul>
239
240EOHTML
241
242initialize($parser, $results);
243$parser->parse_string_document(<<'EOPOD');
244=over
245
246=item Pinky
247
248=over
249
250=item World Domination
251
252=back
253
254=item Brain
255
256=back
257
258EOPOD
259
260is($results, <<'EOHTML', 'nested lists');
261<dl>
262
263<dt>Pinky</dt>
264<dd>
265
266<dl>
267
268<dt>World Domination</dt>
269<dd>
270
271</dd>
272</dl>
273
274</dd>
275<dt>Brain</dt>
276<dd>
277
278</dd>
279</dl>
280
281EOHTML
282
283initialize($parser, $results);
284$parser->parse_string_document(<<'EOPOD');
285=over
286
287=item Pinky
288
289On the list:
290
291=over
292
293=item World Domination
294
295Fight the good fight
296
297=item Go to Europe
298
299(Steve Martin joke)
300
301=back
302
303=item Brain
304
305Not so much
306
307=back
308
309EOPOD
310
311is($results, <<'EOHTML', 'multiparagraph nested lists');
312<dl>
313
314<dt>Pinky</dt>
315<dd>
316
317<p>On the list:</p>
318
319<dl>
320
321<dt>World Domination</dt>
322<dd>
323
324<p>Fight the good fight</p>
325
326</dd>
327<dt>Go to Europe</dt>
328<dd>
329
330<p>(Steve Martin joke)</p>
331
332</dd>
333</dl>
334
335</dd>
336<dt>Brain</dt>
337<dd>
338
339<p>Not so much</p>
340
341</dd>
342</dl>
343
344EOHTML
345
346initialize($parser, $results);
347$parser->parse_string_document(<<'EOPOD');
348=pod
349
350  1 + 1 = 2;
351  2 + 2 = 4;
352
353EOPOD
354
355is($results, <<'EOHTML', "code block");
356<pre><code>  1 + 1 = 2;
357  2 + 2 = 4;</code></pre>
358
359EOHTML
360
361
362initialize($parser, $results);
363$parser->parse_string_document(<<'EOPOD');
364=pod
365
366A plain paragraph with a C<functionname>.
367EOPOD
368is($results, <<"EOHTML", "code entity in a paragraph");
369<p>A plain paragraph with a <code>functionname</code>.</p>
370
371EOHTML
372
373
374initialize($parser, $results);
375$parser->html_header("<html>\n<body>");
376$parser->html_footer("</body>\n</html>");
377$parser->parse_string_document(<<'EOPOD');
378=pod
379
380A plain paragraph with body tags turned on.
381EOPOD
382is($results, <<"EOHTML", "adding html body tags");
383<html>
384<body>
385
386<p>A plain paragraph with body tags turned on.</p>
387
388</body>
389</html>
390
391EOHTML
392
393
394initialize($parser, $results);
395$parser->html_css('style.css');
396$parser->html_header(undef);
397$parser->html_footer(undef);
398$parser->parse_string_document(<<'EOPOD');
399=pod
400
401A plain paragraph with body tags and css tags turned on.
402EOPOD
403like($results, qr/<link rel='stylesheet' href='style.css' type='text\/css'>/,
404"adding html body tags and css tags");
405
406
407initialize($parser, $results);
408$parser->parse_string_document(<<'EOPOD');
409=pod
410
411A plain paragraph with S<non breaking text>.
412EOPOD
413is($results, <<"EOHTML", "Non breaking text in a paragraph");
414<p>A plain paragraph with <nobr>non breaking text</nobr>.</p>
415
416EOHTML
417
418initialize($parser, $results);
419$parser->parse_string_document(<<'EOPOD');
420=pod
421
422A plain paragraph with a L<Newlines>.
423EOPOD
424is($results, <<"EOHTML", "Link entity in a paragraph");
425<p>A plain paragraph with a <a href="$PERLDOC?Newlines">Newlines</a>.</p>
426
427EOHTML
428
429initialize($parser, $results);
430$parser->parse_string_document(<<'EOPOD');
431=pod
432
433A plain paragraph with a L<perlport/Newlines>.
434EOPOD
435is($results, <<"EOHTML", "Link entity in a paragraph");
436<p>A plain paragraph with a <a href="$PERLDOC?perlport#Newlines">&quot;Newlines&quot; in perlport</a>.</p>
437
438EOHTML
439
440initialize($parser, $results);
441$parser->parse_string_document(<<'EOPOD');
442=pod
443
444A plain paragraph with a L<Boo|http://link.included.here>.
445EOPOD
446is($results, <<"EOHTML", "A link in a paragraph");
447<p>A plain paragraph with a <a href="http://link.included.here">Boo</a>.</p>
448
449EOHTML
450
451initialize($parser, $results);
452$parser->parse_string_document(<<'EOPOD');
453=pod
454
455A plain paragraph with a L<http://link.included.here>.
456EOPOD
457is($results, <<"EOHTML", "A link in a paragraph");
458<p>A plain paragraph with a <a href="http://link.included.here">http://link.included.here</a>.</p>
459
460EOHTML
461
462initialize($parser, $results);
463$parser->parse_string_document(<<'EOPOD');
464=pod
465
466A plain paragraph with B<bold text>.
467EOPOD
468is($results, <<"EOHTML", "Bold text in a paragraph");
469<p>A plain paragraph with <b>bold text</b>.</p>
470
471EOHTML
472
473initialize($parser, $results);
474$parser->parse_string_document(<<'EOPOD');
475=pod
476
477A plain paragraph with I<italic text>.
478EOPOD
479is($results, <<"EOHTML", "Italic text in a paragraph");
480<p>A plain paragraph with <i>italic text</i>.</p>
481
482EOHTML
483
484initialize($parser, $results);
485$parser->parse_string_document(<<'EOPOD');
486=pod
487
488A plain paragraph with a F<filename>.
489EOPOD
490is($results, <<"EOHTML", "File name in a paragraph");
491<p>A plain paragraph with a <i>filename</i>.</p>
492
493EOHTML
494
495# It's not important that 's (apostrophes) be encoded for XHTML output.
496initialize($parser, $results);
497$parser->parse_string_document(<<'EOPOD');
498=pod
499
500  # this header is very important & dont you forget it
501  my $text = "File is: " . <FILE>;
502EOPOD
503is($results, <<"EOHTML", "Verbatim text with encodable entities");
504<pre><code>  # this header is very important &amp; dont you forget it
505  my \$text = &quot;File is: &quot; . &lt;FILE&gt;;</code></pre>
506
507EOHTML
508
509initialize($parser, $results);
510$parser->parse_string_document(<<'EOPOD');
511=pod
512
513A text paragraph using E<sol> and E<verbar> special POD entities.
514
515EOPOD
516is($results, <<"EOHTML", "Text with decodable entities");
517<p>A text paragraph using / and | special POD entities.</p>
518
519EOHTML
520
521initialize($parser, $results);
522$parser->parse_string_document(<<'EOPOD');
523=pod
524
525A text paragraph using numeric POD entities: E<60>, E<62>.
526
527EOPOD
528is($results, <<"EOHTML", "Text with numeric entities");
529<p>A text paragraph using numeric POD entities: &lt;, &gt;.</p>
530
531EOHTML
532
533SKIP: for my $use_html_entities (0, 1) {
534  if ($use_html_entities and not $Pod::Simple::XHTML::HAS_HTML_ENTITIES) {
535    skip("HTML::Entities not installed", 1);
536  }
537  local $Pod::Simple::XHTML::HAS_HTML_ENTITIES = $use_html_entities;
538  initialize($parser, $results);
539  $parser->parse_string_document(<<'EOPOD');
540=pod
541
542  # this header is very important & dont you forget it
543  B<my $file = <FILEE<gt> || 'Blank!';>
544  my $text = "File is: " . <FILE>;
545EOPOD
546is($results, <<"EOHTML", "Verbatim text with markup and embedded formatting");
547<pre><code>  # this header is very important &amp; dont you forget it
548  <b>my \$file = &lt;FILE&gt; || &#39;Blank!&#39;;</b>
549  my \$text = &quot;File is: &quot; . &lt;FILE&gt;;</code></pre>
550
551EOHTML
552}
553
554
555ok $parser = Pod::Simple::XHTML->new, 'Construct a new parser';
556$results = '';
557$parser->output_string( \$results ); # Send the resulting output to a string
558ok $parser->parse_string_document( "=head1 Poit!" ), 'Parse with headers';
559like $results, qr{<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />},
560    'Should have proper http-equiv meta tag';
561
562# Test the link generation methods.
563is $parser->resolve_pod_page_link('Net::Ping', 'INSTALL'),
564    "$PERLDOC?Net::Ping#INSTALL",
565    'POD link with fragment';
566is $parser->resolve_pod_page_link('perlpodspec'),
567    "$PERLDOC?perlpodspec", 'Simple POD link';
568is $parser->resolve_pod_page_link(undef, 'SYNOPSIS'), '#SYNOPSIS',
569    'Simple fragment link';
570is $parser->resolve_pod_page_link(undef, 'this that'), '#this-that',
571    'Fragment link with space';
572is $parser->resolve_pod_page_link('perlpod', 'this that'),
573    "$PERLDOC?perlpod#this-that",
574    'POD link with fragment with space';
575
576is $parser->resolve_man_page_link('crontab(5)', 'EXAMPLE CRON FILE'),
577    "${MANURL}5/crontab", 'Man link with fragment';
578is $parser->resolve_man_page_link('crontab(5)'),
579    "${MANURL}5/crontab", 'Man link without fragment';
580is $parser->resolve_man_page_link('crontab'),
581    "${MANURL}1/crontab", 'Man link without section';
582
583# Make sure that batch_mode_page_object_init() works.
584ok $parser->batch_mode_page_object_init(0, 0, 0, 0, 6),
585    'Call batch_mode_page_object_init()';
586ok $parser->batch_mode, 'We should be in batch mode';
587is $parser->batch_mode_current_level, 6,
588    'The level should have been set';
589
590######################################
591
592sub initialize {
593	$_[0] = Pod::Simple::XHTML->new ();
594        $_[0]->html_header("");
595        $_[0]->html_footer("");
596	$_[0]->output_string( \$results ); # Send the resulting output to a string
597	$_[1] = '';
598	return;
599}
600