[perl #113926] add tests for Pod::Html::anchorify()
authorJames E Keenan <jkeenan@cpan.org>
Mon, 24 Jun 2013 01:48:03 +0000 (11:48 +1000)
committerTony Cook <tony@develop-help.com>
Mon, 24 Jun 2013 02:02:01 +0000 (12:02 +1000)
MANIFEST
ext/Pod-Html/t/anchorify.t [new file with mode: 0644]

index 6f76240..3d7956d 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -3679,6 +3679,7 @@ ext/Pod-Functions/Makefile.PL             Makefile writer
 ext/Pod-Functions/t/Functions.t                See if Pod::Functions works
 ext/Pod-Html/bin/pod2html      Translator to turn pod into HTML
 ext/Pod-Html/lib/Pod/Html.pm   Convert POD data to HTML
+ext/Pod-Html/t/anchorify.t
 ext/Pod-Html/t/cache.pod
 ext/Pod-Html/t/cache.t
 ext/Pod-Html/t/crossref2.t
diff --git a/ext/Pod-Html/t/anchorify.t b/ext/Pod-Html/t/anchorify.t
new file mode 100644 (file)
index 0000000..96b7e14
--- /dev/null
@@ -0,0 +1,96 @@
+# -*- perl -*-
+use strict;
+use Pod::Html qw( anchorify );
+use Test::More tests => 1;
+
+my @filedata;
+{
+    local $/ = '';
+    @filedata = <DATA>;
+}
+
+my (@poddata, $i, $j);
+for ($i = 0, $j = -1; $i <= $#filedata; $i++) {
+    $j++ if ($filedata[$i] =~ /^\s*=head[1-6]/);
+    if ($j >= 0) {
+        $poddata[$j]  = "" unless defined $poddata[$j];
+        $poddata[$j] .= "\n$filedata[$i]" if $j >= 0;
+    }
+}
+
+my %heads = ();
+foreach $i (0..$#poddata) {
+    $heads{anchorify($1)} = 1 if $poddata[$i] =~ /=head[1-6]\s+(.*)/;
+}
+my %expected = map { $_ => 1 } qw(
+    name
+    description
+    subroutine
+    error
+    method
+    has_a_wordspace
+    hastrailingwordspace
+    hasleadingwordspace
+    has_extra_internalwordspace
+    hasquotes
+    hasquestionmark
+    has_hyphen_and_space
+);
+is_deeply(
+    [ keys %heads ],
+    [ keys %expected ],
+    "Got expected POD heads"
+);
+
+__DATA__
+=head1 NAME
+
+anchorify - Test C<Pod::Html::anchorify()>
+
+=head1 DESCRIPTION
+
+alpha
+
+=head2 Subroutine
+
+beta
+
+=head3 Error
+
+gamma
+
+=head4 Method
+
+delta
+
+=head4 Has A Wordspace
+
+delta
+
+=head4 HasTrailingWordspace  
+
+epsilon
+
+=head4    HasLeadingWordspace
+
+zeta
+
+=head4 Has     Extra  InternalWordspace
+
+eta
+
+=head4 Has"Quotes"
+
+theta
+
+=head4 Has?QuestionMark
+
+iota
+
+=head4 Has-Hyphen And Space
+
+kappa
+
+=cut
+
+__END__