Genealogy-Military-Branch
view release on metacpan or search on metacpan
t/extended_tests.t view on Meta::CPAN
use strict;
use warnings;
use 5.014;
use Test::Most;
use Test::Mockingbird 0.09 qw(mock_scoped);
use_ok('Genealogy::Military::Branch') or BAIL_OUT('Cannot load Genealogy::Military::Branch');
# -----------------------------------------------------------------------
# _get_language - environment variable cascade (all fallback paths)
# Each subtest exercises a distinct branch in the cascade:
# detect() â LANGUAGE â LC_ALL â LC_MESSAGES â LANG â C-locale â undef
# -----------------------------------------------------------------------
subtest '_get_language - LANGUAGE env var used when detect() returns nothing' => sub {
delete local $ENV{LC_ALL};
delete local $ENV{LC_MESSAGES};
delete local $ENV{LANG};
local $ENV{LANGUAGE} = 'de_DE.UTF-8';
# detect() returns nothing so the I18N::LangTags path is skipped;
t/extended_tests.t view on Meta::CPAN
'marine', 'hyphenated detect() tag "fr-FR" extracts "fr"');
};
subtest '_get_language - non-matching detect() tag falls through to env vars' => sub {
delete local $ENV{LANGUAGE};
delete local $ENV{LC_ALL};
delete local $ENV{LC_MESSAGES};
local $ENV{LANG} = 'de_DE.UTF-8';
# '123' does not match /^([a-z]{2})/i so the loop exhausts without returning;
# control falls through to the LANGUAGE/LC_ALL/LC_MESSAGES/LANG cascade
my $guard = mock_scoped('I18N::LangTags::Detect::detect' => sub { '123' });
my $obj = Genealogy::Military::Branch->new();
is($obj->detect(text => 'He served in the Navy'),
'Marine', 'non-matching detect() tag falls through to LANG env var');
};
subtest '_get_language - undef returned when no locale detectable' => sub {
delete local $ENV{LANGUAGE};
delete local $ENV{LC_ALL};
( run in 2.318 seconds using v1.01-cache-2.11-cpan-9581c071862 )