#!/usr/bin/perl -w
# t/xhtml01.t - check basic output from Pod::Simple::XHTML
BEGIN {
chdir 't' if -d 't';
}
use strict;
use lib '../lib';
use Test::More tests => 60;
#use Test::More 'no_plan';
use_ok('Pod::Simple::XHTML') or exit;
isa_ok my $parser = Pod::Simple::XHTML->new, 'Pod::Simple::XHTML';
my $header = $parser->html_header;
my $footer = $parser->html_footer;
for my $spec (
[ 'foo' => 'foo', 'foo' ],
[ '12foo' => 'foo1', 'foo' ],
[ 'fo$bar' => 'fo-bar', 'fo-bar' ],
[ 'f12' => 'f12', 'f12' ],
[ '13' => 'pod13', 'pod13' ],
[ '**.:' => 'pod', 'pod' ],
) {
is $parser->idify( $spec->[0] ), $spec->[1],
qq{ID for "$spec->[0]" should be "$spec->[1]"};
is $parser->idify( $spec->[0], 1 ), $spec->[2],
qq{Non-unique ID for "$spec->[0]" should be "$spec->[2]"};
}
my $results;
initialize($parser, $results);
$parser->html_header($header);
$parser->html_footer($footer);
ok $parser->parse_string_document( '=head1 Foo' ), 'Parse one header';
is $results, <<'EOF', 'Should have the index';
Foo
EOF
initialize($parser, $results);
ok $parser->parse_string_document( '=head1 Foo Bar' ), 'Parse multiword header';
is $results, <<'EOF', 'Should have the index';
Foo Bar
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo B\n\n=head1 Foo B" ),
'Parse two multiword headers';
is $results, <<'EOF', 'Should have the index';
Foo Bar
Foo Baz
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo\n\n=head1 Bar" ), 'Parse two headers';
is $results, <<'EOF', 'Should have both and the index';
Foo
Bar
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo C\n\n=head1 C" ),
'Parse two headers with C<> formatting';
is $results, <<'EOF', 'Should have the index';
Foo Bar
Baz
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo\n\n=head1 Bar\n\n=head1 Baz" ),
'Parse three headers';
is $results, <<'EOF', 'Should have all three and the index';
Foo
Bar
Baz
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar" ), 'Parse two levels';
is $results, <<'EOF', 'Should have the dual-level index';
Foo
Bar
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head3 Baz" ),
'Parse three levels';
is $results, <<'EOF', 'Should have the three-level index';
Foo
Bar
Baz
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head3 Baz\n\n=head4 Howdy" ),
'Parse four levels';
is $results, <<'EOF', 'Should have the four-level index';
Foo
Bar
Baz
Howdy
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo\n\n=head2 Bar\n\n=head2 Baz" ),
'Parse 1/2';
is $results, <<'EOF', 'Should have the 1/s index';
Foo
Bar
Baz
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo\n\n=head3 Bar" ), 'Parse jump from one to three';
is $results, <<'EOF', 'Should have the 1-3 index';
Foo
Bar
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo\n\n=head4 Bar" ), 'Parse jump from one to four';
is $results, <<'EOF', 'Should have the 1-4 index';
Foo
Bar
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head2 Foo\n\n=head1 Bar" ),
'Parse two down to 1';
is $results, <<'EOF', 'Should have the 2-1 index';
Foo
Bar
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head2 Foo\n\n=head1 Bar\n\n=head4 Four\n\n=head4 Four2" ),
'Parse two down to 1';
is $results, <<'EOF', 'Should have the 2-1 index';
Foo
Bar
Four
Four2
EOF
initialize($parser, $results);
ok $parser->parse_string_document( "=head4 Foo" ),
'Parse just a four';
is $results, <<'EOF', 'Should have the 2-1 index';
Foo
EOF
initialize($parser, $results);
ok $parser->parse_string_document( <<'EOF' ), 'Parse a mixture';
=head2 Foo
=head3 Bar
=head1 Baz
=head4 Drink
=head3 Sip
=head4 Ouch
=head1 Drip
EOF
is $results, <<'EOF', 'And it should work!';
Foo
Bar
Baz
Drink
Sip
Ouch
Drip
EOF
initialize($parser, $results);
$parser->html_header($header);
$parser->html_footer($footer);
$parser->backlink(1);
ok $parser->parse_string_document( '=head1 Foo' ), 'Parse a header';
is $results, <<'EOF', 'Should have the index and a backlink';
Foo
EOF
initialize($parser, $results);
$parser->html_header($header);
$parser->html_footer($footer);
$parser->backlink(1);
ok $parser->parse_string_document( "=head1 Foo \n\n=head2 Bar \n\n=head1 Baz" ), 'Parse headers';
is $results, <<'EOF', 'Should have the index and backlinks';
Foo
Bar
Baz
EOF
initialize($parser, $results);
$parser->html_header($header);
$parser->html_footer($footer);
$parser->index(0);
$parser->backlink(1);
ok $parser->parse_string_document( "=head1 Foo \n\n=head1 Bar" ), 'Parse headers';
is $results, <<'EOF', 'Should have backlinks but no index';
Foo
Bar
EOF
initialize($parser, $results);
$parser->html_header($header);
$parser->html_footer($footer);
$parser->backlink(1);
$parser->html_h_level(2);
ok $parser->parse_string_document( "=head1 Foo \n\n=head1 Bar" ), 'Parse headers';
is $results, <<'EOF', 'Should have index and backlinks around h2 elements';
Foo
Bar
EOF
initialize($parser, $results);
$parser->anchor_items(1);
ok $parser->parse_string_document( <<'EOPOD' ), 'Parse POD';
=head1 Foo
=over
=item test
=item Test 2
body of item
=back
=over
=item *
not anchored
=back
=over
=item 1
still not anchored
=back
EOPOD
is $results, <<'EOF', 'Anchor =item directives';
Foo
- test
-
- Test 2
-
body of item
still not anchored
EOF
initialize($parser, $results);
$parser->anchor_items(0);
ok $parser->parse_string_document( <<'EOPOD' ), 'Parse POD';
=head1 Foo
=over
=item test
=item Test 2
body of item
=back
=over
=item *
not anchored
=back
=over
=item 1
still not anchored
=back
EOPOD
is $results, <<'EOF', 'Do not anchor =item directives';
Foo
- test
-
- Test 2
-
body of item
still not anchored
EOF
$ENV{FOO}= 1;
initialize($parser, $results);
ok $parser->parse_string_document( <<'EOPOD' ), 'Parse POD';
=head1 Foo
Test links from perlpodspec: L"About LE...E Codes">
=head1 About LE...E Codes
Here it is
EOPOD
my $id = 'About-L...-Codes'; # what should this be?
is $results, <
Foo
About L<...> Codes
Foo
Test links from perlpodspec: "About L<...> Codes"
About L<...> Codes
Here it is
EOF
sub initialize {
$_[0] = Pod::Simple::XHTML->new;
$_[0]->html_header('');
$_[0]->html_footer('');
$_[0]->index(1);
$_[0]->output_string( \$results ); # Send the resulting output to a string
$_[1] = '';
return;
}