--- test.pl 2002/02/11 20:19:59 1.3 +++ test.pl 2002/02/12 12:41:31 1.4 @@ -3,14 +3,20 @@ use strict; # init some vars -my $affix_file='/usr/lib/ispell/english.aff'; +my @affs= qw ( + /usr/lib/ispell/english.aff + /usr/lib/ispell/american.aff + /usr/lib/ispell/british.aff + ); + my @test_words=( 'cars', 'dogs' ); my $findaffix_file='./findaffix.out'; my $loaded = 0; +my $debug = 0; -BEGIN { $| = 1; print "1..6\n"; } +BEGIN { $| = 1; print "1..8\n"; } END {print "not ok 1\n" unless $loaded;} use Lingua::Spelling::Alternative; @@ -19,23 +25,50 @@ ### test constructor -my $a = new Lingua::Spelling::Alternative( DEBUG => 1 ) ; +my $a = new Lingua::Spelling::Alternative( DEBUG => $debug ) ; defined($a) || print 'not '; print "ok 2\n"; ### test load affix +my $affix_file; +foreach (@affs) { + if (-e $_) { + $affix_file = $_; + last; + } +} + +# test sub + +sub test { + my $nr=$_[0]; + + my @words = $a->alternatives(@test_words); + print 'not ' if (! @words); + print "ok ",$nr++," # - ",join(", ",@test_words)," -> alternatives: ",join(", ",@words),"\n"; + my @min_words = $a->minimal(@test_words); + print 'not ' if (! @min_words); + print "ok ",$nr++," # - ",join(", ",@test_words)," -> minimal: ",join(", ",@min_words),"\n"; +} + +# skip sub + +sub skip { + foreach (@_) { + print "ok $_ # - Skip\n"; + } +} + if ( -e $affix_file ) { my $ok = $a->load_affix($affix_file); print 'not ' if (! $ok); print "ok 3\n"; + test(4); - my @words = $a->alternatives(@test_words); - print 'not ' if (! @words); - print "ok 4 # - ",join(", ",@test_words)," -> ",join(", ",@words),"\n"; } else { print "ok 3 # - Skip, affix file '$affix_file' not found\n"; - print "ok 4 # - Skip\n"; + skip(4..5); } undef $a; @@ -43,17 +76,15 @@ ### test load findaffix if ( -e $findaffix_file ) { - my $a = new Lingua::Spelling::Alternative( DEBUG => 1 ) ; + my $a = new Lingua::Spelling::Alternative( DEBUG => $debug ) ; my $ok = $a->load_findaffix($findaffix_file); print 'not ' if (! $ok); - print "ok 5\n"; + print "ok 6\n"; - my @words = $a->alternatives(@test_words); - print 'not ' if (! @words); - print "ok 6 # - ",join(", ",@test_words)," -> ",join(", ",@words),"\n"; + test(7); } else { - print "ok 5 # - Skip, findaffix file '$findaffix_file' not found\n"; - print "ok 6 # - Skip\n"; + print "ok 6 # - Skip, findaffix file '$findaffix_file' not found\n"; + skip(7..8); }