3 |
use strict; |
use strict; |
4 |
|
|
5 |
# init some vars |
# init some vars |
6 |
my $affix_file='/usr/lib/ispell/english.aff'; |
my @affs= qw ( |
7 |
|
/usr/lib/ispell/english.aff |
8 |
|
/usr/lib/ispell/american.aff |
9 |
|
/usr/lib/ispell/british.aff |
10 |
|
); |
11 |
|
|
12 |
my @test_words=( 'cars', 'dogs' ); |
my @test_words=( 'cars', 'dogs' ); |
13 |
|
|
14 |
|
my $findaffix_file='./findaffix.out'; |
15 |
|
|
16 |
my $loaded = 0; |
my $loaded = 0; |
17 |
|
my $debug = 0; |
18 |
|
|
19 |
BEGIN { $| = 1; print "1..4\n"; } |
BEGIN { $| = 1; print "1..8\n"; } |
20 |
END {print "not ok 1\n" unless $loaded;} |
END {print "not ok 1\n" unless $loaded;} |
21 |
|
|
22 |
use Lingua::Spelling::Alternative; |
use Lingua::Spelling::Alternative; |
25 |
|
|
26 |
### test constructor |
### test constructor |
27 |
|
|
28 |
my $a = new Lingua::Spelling::Alternative( DEBUG => 1 ) ; |
my $a = new Lingua::Spelling::Alternative( DEBUG => $debug ) ; |
29 |
|
|
30 |
defined($a) || print 'not '; print "ok 2\n"; |
defined($a) || print 'not '; print "ok 2\n"; |
31 |
|
|
32 |
### test load affix |
### test load affix |
33 |
|
|
34 |
|
my $affix_file; |
35 |
|
foreach (@affs) { |
36 |
|
if (-e $_) { |
37 |
|
$affix_file = $_; |
38 |
|
last; |
39 |
|
} |
40 |
|
} |
41 |
|
|
42 |
|
# test sub |
43 |
|
|
44 |
|
sub test { |
45 |
|
my $a=shift @_; |
46 |
|
my $nr=shift @_; |
47 |
|
|
48 |
|
my @words = $a->alternatives(@test_words); |
49 |
|
print 'not ' if (! @words); |
50 |
|
print "ok ",$nr++," # - ",join(", ",@test_words)," -> alternatives: ",join(", ",@words),"\n"; |
51 |
|
my @min_words = $a->minimal(@test_words); |
52 |
|
print 'not ' if (! @min_words); |
53 |
|
print "ok ",$nr++," # - ",join(", ",@test_words)," -> minimal: ",join(", ",@min_words),"\n"; |
54 |
|
} |
55 |
|
|
56 |
|
# skip sub |
57 |
|
|
58 |
|
sub skip { |
59 |
|
foreach (@_) { |
60 |
|
print "ok $_ # - Skip\n"; |
61 |
|
} |
62 |
|
} |
63 |
|
|
64 |
if ( -e $affix_file ) { |
if ( -e $affix_file ) { |
65 |
my $ok = $a->load_affix($affix_file); |
my $ok = $a->load_affix($affix_file); |
66 |
print 'not ' if (! $ok); |
print 'not ' if (! $ok); |
67 |
print "ok 3\n"; |
print "ok 3\n"; |
68 |
|
test($a,4); |
69 |
|
|
|
my @words = $a->alternatives(@test_words); |
|
|
print 'not ' if (! @words); |
|
|
print "ok 4 # - ",join(", ",@test_words)," -> ",join(", ",@words),"\n"; |
|
70 |
} else { |
} else { |
71 |
print "ok 3 # - Skip, affix file '$affix_file' not found\n"; |
print "ok 3 # - Skip, affix file '$affix_file' not found\n"; |
72 |
print "ok 4 # - Skip\n"; |
skip(4..5); |
73 |
|
} |
74 |
|
|
75 |
|
undef $a; |
76 |
|
|
77 |
|
### test load findaffix |
78 |
|
|
79 |
|
if ( -e $findaffix_file ) { |
80 |
|
my $a = new Lingua::Spelling::Alternative( DEBUG => $debug ) ; |
81 |
|
|
82 |
|
my $ok = $a->load_findaffix($findaffix_file); |
83 |
|
print 'not ' if (! $ok); |
84 |
|
print "ok 6\n"; |
85 |
|
|
86 |
|
test($a,7); |
87 |
|
} else { |
88 |
|
print "ok 6 # - Skip, findaffix file '$findaffix_file' not found\n"; |
89 |
|
skip(7..8); |
90 |
} |
} |
91 |
|
|