This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix links in generated HTML documentation
[perl5.git] / ext / Pod-Html / t / anchorify.t
1 # -*- perl -*-
2 use strict;
3 use Pod::Html qw( anchorify );
4 use Test::More tests => 1;
5
6 my @filedata;
7 {
8     local $/ = '';
9     @filedata = <DATA>;
10 }
11
12 my (@poddata, $i, $j);
13 for ($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
21 my %heads = ();
22 foreach $i (0..$#poddata) {
23     $heads{anchorify($1)} = 1 if $poddata[$i] =~ /=head[1-6]\s+(.*)/;
24 }
25 my %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 );
39 is_deeply(
40     \%heads,
41     \%expected,
42     "Got expected POD heads"
43 );
44
45 __DATA__
46 =head1 NAME
47
48 anchorify - Test C<Pod::Html::anchorify()>
49
50 =head1 DESCRIPTION
51
52 alpha
53
54 =head2 Subroutine
55
56 beta
57
58 =head3 Error
59
60 gamma
61
62 =head4 Method
63
64 delta
65
66 =head4 Has A Wordspace
67
68 delta
69
70 =head4 HasTrailingWordspace  
71
72 epsilon
73
74 =head4    HasLeadingWordspace
75
76 zeta
77
78 =head4 Has      Extra  InternalWordspace
79
80 eta
81
82 =head4 Has"Quotes"
83
84 theta
85
86 =head4 Has?QuestionMark
87
88 iota
89
90 =head4 Has-Hyphen And Space
91
92 kappa
93
94 =cut
95
96 __END__