CGI-Lingua
view release on metacpan or search on metacpan
t/extended_tests.t view on Meta::CPAN
#!/usr/bin/env perl
# t/extended_tests.t â Coverage-gap tests for CGI::Lingua.
#
# Target: execution paths not reached by function.t, unit.t, integration.t,
# or edge_cases.t. Each section names the sub being probed and the specific
# branch being exercised.
#
# Network I/O is blocked globally; individual subtests install narrow mocks.
use strict;
use warnings;
use CHI;
use Readonly;
use Scalar::Util qw(blessed);
use Test::Most;
use Test::Mockingbird;
use Test::Returns qw(returns_ok);
use lib 't/lib';
BEGIN { use_ok('CGI::Lingua') }
# Pre-require lazy-loaded modules so their BEGIN blocks run before any mock.
my $HAS_LWP = eval { require LWP::Simple::WithCache; 1 } ? 1 : 0;
my $HAS_JSON = eval { require JSON::Parse; 1 } ? 1 : 0;
eval { require Net::Whois::IP };
eval { require Net::Whois::IANA };
# ââ Constants ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Readonly my %LANG => (EN => 'en', FR => 'fr', DE => 'de', EN_GB => 'en-gb', NB => 'nb');
Readonly my %IP => (
PUBLIC => '8.8.8.8',
LOOPBACK => '127.0.0.1',
PRIVATE => '192.168.1.1',
BAIDU => '185.10.104.1',
);
Readonly my $CACHE_NS => 'CGI::Lingua:';
Readonly my $GEO_ABSENT => 0;
Readonly my $GEO_PRESENT => 1;
# ââ Helpers âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
sub _block_network {
Test::Mockingbird::mock('CGI::Lingua', '_resolve_country_via_whois', sub { });
Test::Mockingbird::mock('LWP::Simple::WithCache', 'get', sub { undef })
if $HAS_LWP;
}
sub _obj {
my ($supported, %extra) = @_;
CGI::Lingua->new(supported => $supported, %extra);
}
sub _fresh_cache { CHI->new(driver => 'Memory', global => 0) }
sub _inject_ipcountry {
my ($l, $cc) = @_;
Test::Mockingbird::mock('IP::Country::Fast', 'inet_atocc', sub { $cc });
$l->{_have_ipcountry} = $GEO_PRESENT;
$l->{_ipcountry} = bless {}, 'IP::Country::Fast';
$l->{_have_geoip} = $GEO_ABSENT;
$l->{_have_geoipfree} = $GEO_ABSENT;
}
( run in 0.866 second using v1.01-cache-2.11-cpan-800906f7e73 )