]> git.imager.perl.org - imager.git/commitdiff
test for duplicate words in POD
authorTony Cook <tony@develop-help.com>
Thu, 31 Oct 2013 01:08:24 +0000 (12:08 +1100)
committerTony Cook <tony@develop-help.com>
Thu, 31 Oct 2013 01:08:24 +0000 (12:08 +1100)
t/950-kwalitee/060-podstruct.t

index 78420f243c0101a3bbf1223524bcc4c45b115edc..693c48fc9c101c2cfc2209e1770e9a32fe11e64e 100644 (file)
@@ -32,7 +32,7 @@ for my $file (@files) {
   }
 }
 
-plan tests =>  2 * scalar(@pod);
+plan tests =>  3 * scalar(@pod);
 
 my @req_head1s = qw(NAME DESCRIPTION AUTHOR);
 
@@ -40,6 +40,7 @@ for my $file (@pod) {
   my $parser = PodStructCheck->new;
   my $relfile = abs2rel($file, $base);
   $parser->{bad_quotes} = [];
+  $parser->{dup_words} = [];
   $parser->parse_from_file($file);
 
   my @missing;
@@ -54,6 +55,10 @@ for my $file (@pod) {
     diag "$relfile:$_->[1]: bad quote in: $_->[0]"
       for @{$parser->{bad_quotes}};
   }
+  unless (ok(!@{$parser->{dup_words}}, "$relfile: check for duplicate words")) {
+    diag "$relfile:$_->[1]: dup word '$_->[0]' in: $_->[2]"
+      for @{$parser->{dup_words}};
+  }
 }
 
 package PodPreparse;
@@ -91,6 +96,14 @@ sub command {
 sub verbatim {}
 
 sub textblock {
+  my ($self, $text, $line_num) = @_;
+
+  if (my ($sample, $word) = $text =~ /(.{0,10}\b(\w+)\s+\2\b.{0,10})/s) {
+    # avoid catching "C C<something to do with C>"
+    if ($word ne "C") {
+      push @{$self->{dup_words}}, [ $word, $line_num, $sample ];
+    }
+  }
 }
 
 sub sequence {