1use strict; 2use warnings; 3use Pod::Html::Util qw( anchorify relativize_url ); 4use Test::More; 5 6my @filedata; 7{ 8 local $/ = ''; 9 @filedata = <DATA>; 10} 11 12my (@poddata, $i, $j); 13for ($i = 0, $j = -1; $i <= $#filedata; $i++) { 14 $j++ if ($filedata[$i] =~ /^\s*=head[1-6]/); 15 if ($j >= 0) { 16 $poddata[$j] = "" unless defined $poddata[$j]; 17 $poddata[$j] .= "\n$filedata[$i]" if $j >= 0; 18 } 19} 20 21my %heads = (); 22foreach $i (0..$#poddata) { 23 $heads{anchorify($1)} = 1 if $poddata[$i] =~ /=head[1-6]\s+(.*)/; 24} 25my %expected = map { $_ => 1 } qw( 26 NAME 27 DESCRIPTION 28 Subroutine 29 Error 30 Method 31 Has_A_Wordspace 32 HasTrailingWordspace 33 HasLeadingWordspace 34 Has_Extra_InternalWordspace 35 Has_Quotes 36 Has_QuestionMark 37 Has_Hyphen_And_Space 38); 39is_deeply( 40 \%heads, 41 \%expected, 42 "Got expected POD heads" 43); 44 45{ 46 # adapted from 'installhtml' 47 my $file = '/home/username/tmp/installhtml/pod/perlipc'; 48 my $capture = 'NAME'; 49 my $expected_url = '/home/username/tmp/installhtml/pod/perlipc/NAME.html'; 50 my $expected_relativized_url = 'perlipc/NAME.html'; 51 my $url = "$file/@{[anchorify(qq($capture))]}.html" ; 52 is($url, $expected_url, "anchorify() returned expected value"); 53 my $relativized_url = relativize_url( $url, "$file.html" ); 54 is($relativized_url, $expected_relativized_url, "relativize_url() returned expected value"); 55} 56 57done_testing; 58 59__DATA__ 60=head1 NAME 61 62anchorify - Test C<Pod::Html::Util::anchorify()> 63 64=head1 DESCRIPTION 65 66alpha 67 68=head2 Subroutine 69 70beta 71 72=head3 Error 73 74gamma 75 76=head4 Method 77 78delta 79 80=head4 Has A Wordspace 81 82delta 83 84=head4 HasTrailingWordspace 85 86epsilon 87 88=head4 HasLeadingWordspace 89 90zeta 91 92=head4 Has Extra InternalWordspace 93 94eta 95 96=head4 Has"Quotes" 97 98theta 99 100=head4 Has?QuestionMark 101 102iota 103 104=head4 Has-Hyphen And Space 105 106kappa 107 108=cut 109 110__END__ 111