3 # t/xhtml01.t - check basic output from Pod::Simple::XHTML
11 use Test::More tests => 62;
12 #use Test::More 'no_plan';
14 use_ok('Pod::Simple::XHTML') or exit;
16 my $parser = Pod::Simple::XHTML->new ();
17 isa_ok ($parser, 'Pod::Simple::XHTML');
21 my $PERLDOC = "http://search.cpan.org/perldoc";
22 my $MANURL = "http://man.he.net/man";
24 initialize($parser, $results);
25 $parser->parse_string_document( "=head1 Poit!" );
26 is($results, qq{<h1 id="Poit">Poit!</h1>\n\n}, "head1 level output");
28 initialize($parser, $results);
29 $parser->parse_string_document( "=head2 Yada Yada Operator
30 X<...> X<... operator> X<yada yada operator>" );
31 is($results, qq{<h2 id="Yada-Yada-Operator">Yada Yada Operator </h2>\n\n}, "head ID with X<>");
33 initialize($parser, $results);
34 $parser->parse_string_document( "=head2 Platforms with no supporting programmers:");
35 is($results, qq{<h2 id="Platforms-with-no-supporting-programmers">Platforms with no supporting programmers:</h2>\n\n}, "head ID ending in colon");
37 initialize($parser, $results);
38 $parser->html_h_level(2);
39 $parser->parse_string_document( "=head1 Poit!" );
40 is($results, qq{<h2 id="Poit">Poit!</h2>\n\n}, "head1 level output h_level 2");
42 initialize($parser, $results);
43 $parser->parse_string_document( "=head2 I think so Brain." );
44 is($results, qq{<h2 id="I-think-so-Brain">I think so Brain.</h2>\n\n}, "head2 level output");
46 initialize($parser, $results);
47 $parser->parse_string_document( "=head3 I say, Brain..." );
48 is($results, qq{<h3 id="I-say-Brain">I say, Brain...</h3>\n\n}, "head3 level output");
50 initialize($parser, $results);
51 $parser->parse_string_document( "=head4 Zort & Zog!" );
52 is($results, qq{<h4 id="Zort-Zog">Zort & Zog!</h4>\n\n}, "head4 level output");
56 Pod::Simple::XHTML->_out(
57 sub { $code->($_[0]) if $code },
62 x("=head1 Header\n\n=for html <div>RAW<span>!</span></div>\n\nDone."),
63 qr/.+<\/h1>\s+<div>RAW<span>!<\/span><\/div>\s+.*/sm,
67 initialize($parser, $results);
68 $parser->parse_string_document(<<'EOPOD');
71 Gee, Brain, what do you want to do tonight?
74 is($results, <<'EOHTML', "simple paragraph");
75 <p>Gee, Brain, what do you want to do tonight?</p>
80 initialize($parser, $results);
81 $parser->parse_string_document(<<'EOPOD');
84 B: Now, Pinky, if by any chance you are captured during this mission,
85 remember you are Gunther Heindriksen from Appenzell. You moved to
86 Grindelwald to drive the cog train to Murren. Can you repeat that?
88 P: Mmmm, no, Brain, dont think I can.
91 is($results, <<'EOHTML', "multiple paragraphs");
92 <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>
94 <p>P: Mmmm, no, Brain, dont think I can.</p>
98 initialize($parser, $results);
99 $parser->parse_string_document(<<'EOPOD');
104 P: Gee, Brain, what do you want to do tonight?
108 B: The same thing we do every night, Pinky. Try to take over the world!
114 is($results, <<'EOHTML', "simple bulleted list");
117 <li><p>P: Gee, Brain, what do you want to do tonight?</p>
120 <li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>
128 initialize($parser, $results);
129 $parser->parse_string_document(<<'EOPOD');
134 P: Gee, Brain, what do you want to do tonight?
138 B: The same thing we do every night, Pinky. Try to take over the world!
156 is($results, <<'EOHTML', "nested bulleted list");
159 <li><p>P: Gee, Brain, what do you want to do tonight?</p>
162 <li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>
166 <li><p>Take over world</p>
169 <li><p>Do laundry</p>
181 initialize($parser, $results);
182 $parser->parse_string_document(<<'EOPOD');
187 P: Gee, Brain, what do you want to do tonight?
191 B: The same thing we do every night, Pinky. Try to take over the world!
197 is($results, <<'EOHTML', "numbered list");
200 <li><p>P: Gee, Brain, what do you want to do tonight?</p>
203 <li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>
211 initialize($parser, $results);
212 $parser->parse_string_document(<<'EOPOD');
217 P: Gee, Brain, what do you want to do tonight?
221 B: The same thing we do every night, Pinky. Try to take over the world!
239 is($results, <<'EOHTML', "nested numbered list");
242 <li><p>P: Gee, Brain, what do you want to do tonight?</p>
245 <li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>
249 <li><p>Take over world</p>
252 <li><p>Do laundry</p>
263 initialize($parser, $results);
264 $parser->parse_string_document(<<'EOPOD');
269 Gee, Brain, what do you want to do tonight?
273 The same thing we do every night, Pinky. Try to take over the world!
279 is($results, <<'EOHTML', "list with text headings");
285 <p>Gee, Brain, what do you want to do tonight?</p>
291 <p>The same thing we do every night, Pinky. Try to take over the world!</p>
298 initialize($parser, $results);
299 $parser->parse_string_document(<<'EOPOD');
304 Gee, Brain, what do you want to do tonight?
308 The same thing we do every night, Pinky. Try to take over the world!
314 is($results, <<'EOHTML', "list with bullet and text headings");
319 <p>Gee, Brain, what do you want to do tonight?</p>
324 <p>The same thing we do every night, Pinky. Try to take over the world!</p>
331 initialize($parser, $results);
332 $parser->parse_string_document(<<'EOPOD');
335 =item * Brain <brain@binkyandthebrain.com>
337 =item * Pinky <pinky@binkyandthebrain.com>
343 is($results, <<'EOHTML', "bulleted author list");
346 <li><p>Brain <brain@binkyandthebrain.com></p>
349 <li><p>Pinky <pinky@binkyandthebrain.com></p>
356 initialize($parser, $results);
357 $parser->parse_string_document(<<'EOPOD');
364 =item World Domination
374 is($results, <<'EOHTML', 'nested lists');
382 <dt>World Domination</dt>
397 initialize($parser, $results);
398 $parser->parse_string_document(<<'EOPOD');
407 =item World Domination
425 is($results, <<'EOHTML', 'multiparagraph nested lists');
435 <dt>World Domination</dt>
438 <p>Fight the good fight</p>
441 <dt>Go to Europe</dt>
444 <p>(Steve Martin joke)</p>
460 initialize($parser, $results);
461 $parser->parse_string_document(<<'EOPOD');
469 is($results, <<'EOHTML', "code block");
470 <pre><code> 1 + 1 = 2;
471 2 + 2 = 4;</code></pre>
476 initialize($parser, $results);
477 $parser->parse_string_document(<<'EOPOD');
480 A plain paragraph with a C<functionname>.
482 C<< This code is B<important> to E<lt>me>! >>
485 is($results, <<"EOHTML", "code entity in a paragraph");
486 <p>A plain paragraph with a <code>functionname</code>.</p>
488 <p><code>This code is <b>important</b> to <me>!</code></p>
493 initialize($parser, $results);
494 $parser->html_header("<html>\n<body>");
495 $parser->html_footer("</body>\n</html>");
496 $parser->parse_string_document(<<'EOPOD');
499 A plain paragraph with body tags turned on.
501 is($results, <<"EOHTML", "adding html body tags");
505 <p>A plain paragraph with body tags turned on.</p>
513 initialize($parser, $results);
514 $parser->html_css('style.css');
515 $parser->html_header(undef);
516 $parser->html_footer(undef);
517 $parser->parse_string_document(<<'EOPOD');
520 A plain paragraph with body tags and css tags turned on.
522 like($results, qr/<link rel="stylesheet" href="style.css" type="text\/css" \/>/,
523 "adding html body tags and css tags");
526 initialize($parser, $results);
527 $parser->parse_string_document(<<'EOPOD');
530 A plain paragraph with S<non breaking text>.
532 is($results, <<"EOHTML", "Non breaking text in a paragraph");
533 <p>A plain paragraph with <span style="white-space: nowrap;">non breaking text</span>.</p>
537 initialize($parser, $results);
538 $parser->parse_string_document(<<'EOPOD');
541 A plain paragraph with a L<Newlines>.
543 is($results, <<"EOHTML", "Link entity in a paragraph");
544 <p>A plain paragraph with a <a href="$PERLDOC?Newlines">Newlines</a>.</p>
548 initialize($parser, $results);
549 $parser->parse_string_document(<<'EOPOD');
552 A plain paragraph with a L<perlport/Newlines>.
554 is($results, <<"EOHTML", "Link entity in a paragraph");
555 <p>A plain paragraph with a <a href="$PERLDOC?perlport#Newlines">"Newlines" in perlport</a>.</p>
559 initialize($parser, $results);
560 $parser->parse_string_document(<<'EOPOD');
563 A plain paragraph with a L<Boo|http://link.included.here>.
565 is($results, <<"EOHTML", "A link in a paragraph");
566 <p>A plain paragraph with a <a href="http://link.included.here">Boo</a>.</p>
570 initialize($parser, $results);
571 $parser->parse_string_document(<<'EOPOD');
574 A plain paragraph with a L<http://link.included.here>.
576 is($results, <<"EOHTML", "A link in a paragraph");
577 <p>A plain paragraph with a <a href="http://link.included.here">http://link.included.here</a>.</p>
581 initialize($parser, $results);
582 $parser->parse_string_document(<<'EOPOD');
585 A plain paragraph with a L<http://link.included.here?o=1&p=2>.
587 is($results, <<"EOHTML", "A link in a paragraph");
588 <p>A plain paragraph with a <a href="http://link.included.here?o=1&p=2">http://link.included.here?o=1&p=2</a>.</p>
592 initialize($parser, $results);
593 $parser->parse_string_document(<<'EOPOD');
596 A plain paragraph with B<bold text>.
598 is($results, <<"EOHTML", "Bold text in a paragraph");
599 <p>A plain paragraph with <b>bold text</b>.</p>
603 initialize($parser, $results);
604 $parser->parse_string_document(<<'EOPOD');
607 A plain paragraph with I<italic text>.
609 is($results, <<"EOHTML", "Italic text in a paragraph");
610 <p>A plain paragraph with <i>italic text</i>.</p>
614 initialize($parser, $results);
615 $parser->parse_string_document(<<'EOPOD');
618 A plain paragraph with a F<filename>.
620 is($results, <<"EOHTML", "File name in a paragraph");
621 <p>A plain paragraph with a <i>filename</i>.</p>
625 # It's not important that 's (apostrophes) be encoded for XHTML output.
626 initialize($parser, $results);
627 $parser->parse_string_document(<<'EOPOD');
630 # this header is very important & dont you forget it
631 my $text = "File is: " . <FILE>;
633 is($results, <<"EOHTML", "Verbatim text with encodable entities");
634 <pre><code> # this header is very important & dont you forget it
635 my \$text = "File is: " . <FILE>;</code></pre>
639 initialize($parser, $results);
640 $parser->parse_string_document(<<'EOPOD');
643 A text paragraph using E<sol> and E<verbar> special POD entities.
646 is($results, <<"EOHTML", "Text with decodable entities");
647 <p>A text paragraph using / and | special POD entities.</p>
651 initialize($parser, $results);
652 $parser->parse_string_document(<<'EOPOD');
655 A text paragraph using numeric POD entities: E<60>, E<62>.
658 is($results, <<"EOHTML", "Text with numeric entities");
659 <p>A text paragraph using numeric POD entities: <, >.</p>
665 #include <stdio.h>
667 int main(int argc,char *argv[]) {
669 printf("Hellow World\n");
675 initialize($parser, $results);
676 $parser->parse_string_document("=begin html\n\n$html\n\n=end html\n");
677 is($results, "$html\n\n", "Text with =begin html");
679 SKIP: for my $use_html_entities (0, 1) {
680 if ($use_html_entities and not $Pod::Simple::XHTML::HAS_HTML_ENTITIES) {
681 skip("HTML::Entities not installed", 3);
683 local $Pod::Simple::XHTML::HAS_HTML_ENTITIES = $use_html_entities;
684 initialize($parser, $results);
685 $parser->codes_in_verbatim(1);
686 $parser->parse_string_document(<<'EOPOD');
689 # this header is very important & dont you forget it
690 B<my $file = <FILEE<gt> || Blank!;>
691 my $text = "File is: " . <FILE>;
693 is($results, <<"EOHTML", "Verbatim text with markup and embedded formatting");
694 <pre><code> # this header is very important & dont you forget it
695 <b>my \$file = <FILE> || Blank!;</b>
696 my \$text = "File is: " . <FILE>;</code></pre>
700 # Specify characters to encode.
701 initialize($parser, $results);
702 $parser->html_encode_chars('><"&T');
703 $parser->parse_string_document(<<'EOPOD');
706 This is Anna's "Answer" to the <q>Question</q>.
711 my $T = $use_html_entities ? 84 : 'x54';
712 is($results, <<"EOHTML", 'HTML Entities should be only for specified characters');
713 <p>&#$T;his is Anna's "Answer" to the <q>Question</q>.</p>
717 # Keep =encoding out of content.
718 initialize($parser, $results);
719 $parser->parse_string_document("=encoding ascii\n\n=head1 NAME\n");
720 is($results, <<"EOHTML", 'Encoding should not be in content')
721 <h1 id="NAME">NAME</h1>
728 ok $parser = Pod::Simple::XHTML->new, 'Construct a new parser';
730 $parser->output_string( \$results ); # Send the resulting output to a string
731 ok $parser->parse_string_document( "=head1 Poit!" ), 'Parse with headers';
732 like $results, qr{\Q<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />},
733 'Should have proper http-equiv meta tag';
735 ok $parser = Pod::Simple::XHTML->new, 'Construct a new parser again';
736 ok $parser->html_charset('UTF-8'), 'Set the html charset to UTF-8';
738 $parser->output_string( \$results ); # Send the resulting output to a string
739 ok $parser->parse_string_document( "=head1 Poit!" ), 'Parse with headers';
740 like $results, qr{\Q<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />},
741 'Should have http-equiv meta tag with UTF-8';
743 # Test the link generation methods.
744 is $parser->resolve_pod_page_link('Net::Ping', 'INSTALL'),
745 "$PERLDOC?Net::Ping#INSTALL",
746 'POD link with fragment';
747 is $parser->resolve_pod_page_link('perlpodspec'),
748 "$PERLDOC?perlpodspec", 'Simple POD link';
749 is $parser->resolve_pod_page_link(undef, 'SYNOPSIS'), '#SYNOPSIS',
750 'Simple fragment link';
751 is $parser->resolve_pod_page_link(undef, 'this that'), '#this-that',
752 'Fragment link with space';
753 is $parser->resolve_pod_page_link('perlpod', 'this that'),
754 "$PERLDOC?perlpod#this-that",
755 'POD link with fragment with space';
757 is $parser->resolve_man_page_link('crontab(5)', 'EXAMPLE CRON FILE'),
758 "${MANURL}5/crontab", 'Man link with fragment';
759 is $parser->resolve_man_page_link('crontab(5)'),
760 "${MANURL}5/crontab", 'Man link without fragment';
761 is $parser->resolve_man_page_link('crontab'),
762 "${MANURL}1/crontab", 'Man link without section';
764 # Make sure that batch_mode_page_object_init() works.
765 ok $parser->batch_mode_page_object_init(0, 0, 0, 0, 6),
766 'Call batch_mode_page_object_init()';
767 ok $parser->batch_mode, 'We should be in batch mode';
768 is $parser->batch_mode_current_level, 6,
769 'The level should have been set';
771 ######################################
774 $_[0] = Pod::Simple::XHTML->new ();
775 $_[0]->html_header("");
776 $_[0]->html_footer("");
777 $_[0]->output_string( \$results ); # Send the resulting output to a string