Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 87347d50ae
Fetching contributors…

Cannot retrieve contributors at this time

file 69 lines (53 sloc) 1.6 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
use Test::More tests => 9;

BEGIN {
    use POSIX qw(locale_h);
    use locale;
    setlocale( LC_CTYPE, 'en_US.UTF-8' );
}

SKIP: {

    eval "require Text::Aspell";
    if ($@) {
        skip "Text::Aspell required for SpellCheck", 9;
    }

    use Data::Dump qw(dump);
    use_ok('Search::Tools::SpellCheck');

    my $query
        = 'asdfasdf the quik foo=foxx color:browwn and "lazay dogg" not jumped';

    ok( my $spellcheck = Search::Tools::SpellCheck->new(
            max_suggest => 4,
        ),
        "spellcheck object"
    );

    my $suggestions = $spellcheck->suggest($query);

    #diag(dump($suggestions));

    # if we had no suggestions, then the test is bad due to dictionaries
    # not being installed, locale or other.
    my $ok = 0;
    for my $v (@$suggestions) {
        $ok += scalar @{ $v->{suggestions} };
    }

SKIP: {

        skip "No dictionaries found for locale", 7 unless $ok;

        my %expect = (
            'the' => 0,
            'quik' => 4,
            'foxx' => 3,
            'browwn' => 4,
            'lazay' => 4,
            'dogg' => 4,
            'asdfasdf' => undef
        );

        for my $s (@$suggestions) {
            my $count = $expect{ $s->{word} };

            if ( !defined $count ) {
                ok( !@{ $s->{suggestions} }, $s->{word} );
            }
            elsif ( $count == 0 ) {
                ok( $s->{suggestions} == $count, $s->{word} );
            }
            else {
                ok( scalar( @{ $s->{suggestions} } ) == $count, $s->{word} );
            }
        }

    }

}
Something went wrong with that request. Please try again.