]> git.imager.perl.org - imager.git/blob - xt/x20spell.t
add new comparison method rgb_difference that resembles arithmetical difference per...
[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 EXIF
25 FreeType
26 GDI
27 GIF
28 HSV
29 Hrafnkelsson
30 ICO
31 IMAGER
32 Imager
33 Imager's
34 JPEG
35 PNG
36 PNM
37 POSIX
38 RGB
39 RGBA
40 SGI
41 TGA
42 TIFF
43 UTF-8
44 Uncategorized
45 affine
46 allocator
47 bilevel
48 chromaticities
49 const
50 convolve
51 dpi
52 eg
53 equalities
54 gaussian
55 grayscale
56 ie
57 infix
58 invocant
59 metadata
60 multi-threaded
61 mutex
62 paletted
63 parsers
64 postfix
65 preload
66 preloading
67 preloads
68 quantization
69 quantize
70 quantized
71 radians
72 renderer
73 resizing
74 sRGB
75 specular
76 stereoscopy
77 tuple
78 unary
79 unassociated
80 unseekable
81 untransformed
82 varargs
83 WORDS
84
85 # see for example:
86 #  https://bugs.launchpad.net/ubuntu/+source/aspell/+bug/71322
87 $ENV{LANG} = "C";
88 $ENV{LC_ALL} = "C";
89 for my $file (@pod) {
90   my $check_fh = File::Temp->new;
91   my $check_filename = $check_fh->filename;
92   my $work_fh = File::Temp->new;
93   my $work_filename = $work_fh->filename;
94   open my $pod, "<", $file
95     or die "Cannot open $file for spell check: $!\n";
96   my @local_stop;
97   my $stop_re = qr/\b(xxxxx)\b/;
98   while (<$pod>) {
99     if (/^=for\s+stopwords\s+(.*)/) {
100       push @local_stop, map quotemeta, split ' ', $1;
101       my $stop_re_str = join('|', @local_stop);
102       $stop_re = qr/\b($stop_re_str)\b/;
103     }
104     else {
105       s/$stop_re/ /g;
106     }
107     print $work_fh $_;
108   }
109   seek $work_fh, 0, SEEK_SET;
110   my $spell = Pod::Spell->new;
111   $spell->stopwords->learn_stopwords($my_stopwords);
112   $spell->parse_from_filehandle($work_fh, $check_fh);
113   close $work_fh;
114   close $check_fh;
115   
116   my @out = `aspell list <$check_filename`;
117   unless (ok(@out == 0, "spell check $file")) {
118     chomp @out;
119     diag $_ for @out;
120     print "#----\n";
121     open my $fh, "<", $check_filename;
122     while (<$fh>) {
123       chomp;
124       print "# $_\n";
125     }
126     print "#----\n";
127   }
128 }