]> git.imager.perl.org - imager.git/blobdiff - xt/x20spell.t
update Changes
[imager.git] / xt / x20spell.t
index 9661e0ebbb3e8601579a66c80680ab16c6a4b9da..405f0e2073b48fdf4802da997ed963d242c682c9 100644 (file)
@@ -3,12 +3,15 @@ use strict;
 use Test::More;
 use ExtUtils::Manifest qw(maniread);
 use File::Temp;
-eval "use Pod::Spell 1.01";
-plan skip_all => "Pod::Spell 1.01 required for spellchecking POD" if $@;
-my $manifest = maniread();
-my @pod = sort grep !/^inc/ && /\.(pm|pl|pod|PL)$/, keys %$manifest;
+eval "use Pod::Spell 1.15";
+plan skip_all => "Pod::Spell 1.15 required for spellchecking POD" if $@;
+my @pod = @ARGV;
+unless (@pod) {
+  my $manifest = maniread();
+  @pod = sort grep !/^inc/ && /\.(pm|pl|pod|PL)$/, keys %$manifest;
+}
 plan tests => scalar(@pod);
-my @stopwords = qw/
+my $my_stopwords = <<'WORDS';
 API
 Addi
 Addi's
@@ -48,6 +51,7 @@ dpi
 eg
 equalities
 gaussian
+grayscale
 ie
 infix
 invocant
@@ -75,12 +79,7 @@ unassociated
 unseekable
 untransformed
 varargs
-/;
-
-local %Pod::Wordlist::Wordlist = %Pod::Wordlist::Wordlist;
-for my $stop (@stopwords) {
-  $Pod::Wordlist::Wordlist{$stop} = 1;
-}
+WORDS
 
 # see for example:
 #  https://bugs.launchpad.net/ubuntu/+source/aspell/+bug/71322
@@ -89,9 +88,28 @@ $ENV{LC_ALL} = "C";
 for my $file (@pod) {
   my $check_fh = File::Temp->new;
   my $check_filename = $check_fh->filename;
-  open POD, "< $file"
+  my $work_fh = File::Temp->new;
+  my $work_filename = $work_fh->filename;
+  open my $pod, "<", $file
     or die "Cannot open $file for spell check: $!\n";
-  Pod::Spell->new->parse_from_filehandle(\*POD, $check_fh);
+  my @local_stop;
+  my $stop_re = qr/\b(xxxxx)\b/;
+  while (<$pod>) {
+    if (/^=for\s+stopwords\s+(.*)/) {
+      push @local_stop, map quotemeta, split ' ', $1;
+      my $stop_re_str = join('|', @local_stop);
+      $stop_re = qr/\b($stop_re_str)\b/;
+    }
+    else {
+      s/$stop_re/ /g;
+    }
+    print $work_fh $_;
+  }
+  seek $work_fh, 0, SEEK_SET;
+  my $spell = Pod::Spell->new;
+  $spell->stopwords->learn_stopwords($my_stopwords);
+  $spell->parse_from_filehandle($work_fh, $check_fh);
+  close $work_fh;
   close $check_fh;
   
   my @out = `aspell list <$check_filename`;