Koha-QA
view release on metacpan or search on metacpan
t/spelling.t view on Meta::CPAN
use Modern::Perl;
use IPC::Run3;
BEGIN {
# Check if codespell is available
my ( $stdout, $stderr );
eval { run3( [ 'codespell', '--version' ], undef, \$stdout, \$stderr ) };
if ( $@ || $? != 0 ) {
print "1..0 # skip codespell is not available\n";
exit 0;
}
}
use Test::NoWarnings qw(had_no_warnings);
use Test::More tests => 6;
use File::Temp qw(tempfile);
use Koha::QA::Spelling;
my $expected_messages = {};
sub check_spelling {
my ( $content, $params ) = @_;
$params ||= {};
my $checker = Koha::QA::Spelling->new( { content => $content, %$params } );
$checker->check();
return $checker->errors();
}
subtest '"Checking" is ok' => sub {
plan tests => 1;
my $input = <<INPUT;
Checking is not a spelling error
INPUT
my @errors = check_spelling($input);
is( scalar @errors, 0 );
};
subtest '"Checkin" is not ok' => sub {
plan tests => 1;
my $input = <<INPUT;
one
two
Checkin is a spelling error
four
INPUT
my @errors = check_spelling($input);
is_deeply(
\@errors,
[
{
error => 'spelling',
line_number => 3,
line => 'Checkin is a spelling error',
message => 'Spelling error: Checkin ==> Checking, Check in',
}
]
);
( run in 1.402 second using v1.01-cache-2.11-cpan-eb134014566 )