]> git.imager.perl.org - imager.git/blob - xt/x20spell.t
note that new() accepts an io parameter
[imager.git] / xt / x20spell.t
1 #!perl -w
2 use strict;
3 use Test::More;
4 use ExtUtils::Manifest qw(maniread);
5 use File::Temp;
6 eval "use Pod::Spell 1.15";
7 plan skip_all => "Pod::Spell 1.15 required for spellchecking POD" if $@;
8 my @pod = @ARGV;
9 unless (@pod) {
10   my $manifest = maniread();
11   @pod = sort grep !/^inc/ && /\.(pm|pl|pod|PL)$/, keys %$manifest;
12 }
13 plan tests => scalar(@pod);
14 my $my_stopwords = <<'WORDS';
15 API
16 Addi
17 Addi's
18 Arnar
19 BMP
20 Blit
21 CGI
22 CMYK
23 CPAN
24 FreeType
25 GDI
26 GIF
27 HSV
28 Hrafnkelsson
29 ICO
30 IMAGER
31 Imager
32 Imager's
33 JPEG
34 PNG
35 PNM
36 POSIX
37 RGB
38 RGBA
39 SGI
40 TGA
41 TIFF
42 UTF-8
43 Uncategorized
44 affine
45 allocator
46 bilevel
47 chromaticities
48 const
49 convolve
50 dpi
51 eg
52 equalities
53 gaussian
54 grayscale
55 ie
56 infix
57 invocant
58 metadata
59 multi-threaded
60 mutex
61 paletted
62 parsers
63 postfix
64 preload
65 preloading
66 preloads
67 quantization
68 quantize
69 quantized
70 radians
71 renderer
72 resizing
73 sRGB
74 specular
75 stereoscopy
76 tuple
77 unary
78 unassociated
79 unseekable
80 untransformed
81 varargs
82 WORDS
83
84 # see for example:
85 #  https://bugs.launchpad.net/ubuntu/+source/aspell/+bug/71322
86 $ENV{LANG} = "C";
87 $ENV{LC_ALL} = "C";
88 for my $file (@pod) {
89   my $check_fh = File::Temp->new;
90   my $check_filename = $check_fh->filename;
91   my $work_fh = File::Temp->new;
92   my $work_filename = $work_fh->filename;
93   open my $pod, "<", $file
94     or die "Cannot open $file for spell check: $!\n";
95   my @local_stop;
96   my $stop_re = qr/\b(xxxxx)\b/;
97   while (<$pod>) {
98     if (/^=for\s+stopwords\s+(.*)/) {
99       push @local_stop, map quotemeta, split ' ', $1;
100       my $stop_re_str = join('|', @local_stop);
101       $stop_re = qr/\b($stop_re_str)\b/;
102     }
103     else {
104       s/$stop_re/ /g;
105     }
106     print $work_fh $_;
107   }
108   seek $work_fh, 0, SEEK_SET;
109   my $spell = Pod::Spell->new;
110   $spell->stopwords->learn_stopwords($my_stopwords);
111   $spell->parse_from_filehandle($work_fh, $check_fh);
112   close $work_fh;
113   close $check_fh;
114   
115   my @out = `aspell list <$check_filename`;
116   unless (ok(@out == 0, "spell check $file")) {
117     chomp @out;
118     diag $_ for @out;
119     print "#----\n";
120     open my $fh, "<", $check_filename;
121     while (<$fh>) {
122       chomp;
123       print "# $_\n";
124     }
125     print "#----\n";
126   }
127 }