Genealogy-Occupation
view release on metacpan or search on metacpan
t/extended_tests.t view on Meta::CPAN
'"Shop Assistant Bakery" gains possessive prefix');
is_deeply($obj->normalise(occupation => 'Shop Assistant Draper'),
["Draper's Shop Assistant"], '"Shop Assistant Draper" reordered');
};
subtest '_normalise_single - Assistant passthrough cases' => sub {
delete local $ENV{LANGUAGE};
delete local $ENV{LC_ALL};
delete local $ENV{LC_MESSAGES};
local $ENV{LANG} = 'en_GB.UTF-8';
my $guard = mock_scoped('I18N::LangTags::Detect::detect' => sub { () });
my $obj = Genealogy::Occupation->new();
# Trade already has possessive: `unless($trade =~ /'s$/...)` passes it through
is_deeply($obj->normalise(occupation => "Miner's Assistant"),
["Miner's Assistant"],
'trade already possessive - passes through unchanged');
# Trade is 'shop': `|| lc($trade) eq 'shop'` passes it through
is_deeply($obj->normalise(occupation => 'Shop Assistant'),
['Shop Assistant'],
'"Shop Assistant" (no trailing word) passes through unchanged');
};
subtest '_normalise_single - "police" suffix triggers "officer" append' => sub {
delete local $ENV{LANGUAGE};
delete local $ENV{LC_ALL};
delete local $ENV{LC_MESSAGES};
local $ENV{LANG} = 'en_GB.UTF-8';
my $guard = mock_scoped('I18N::LangTags::Detect::detect' => sub { () });
my $obj = Genealogy::Occupation->new();
# /police$/i - untested branch; match is on trailing 'police'
is_deeply($obj->normalise(occupation => 'Metropolitan Police'),
['Metropolitan Police officer'],
'"Metropolitan Police" gains "officer" suffix');
# Plain "Police" also matches
is_deeply($obj->normalise(occupation => 'Police'),
['Police officer'], 'bare "Police" gains "officer"');
};
subtest '_normalise_single - "on farm" pattern inserts article "a"' => sub {
delete local $ENV{LANGUAGE};
delete local $ENV{LC_ALL};
delete local $ENV{LC_MESSAGES};
local $ENV{LANG} = 'en_GB.UTF-8';
my $guard = mock_scoped('I18N::LangTags::Detect::detect' => sub { () });
my $obj = Genealogy::Occupation->new();
# /^(.+)\s+on farm$/i - untested branch
is_deeply($obj->normalise(occupation => 'Labourer on farm'),
['Labourer on a farm'], '"Labourer on farm" gains article "a"');
is_deeply($obj->normalise(occupation => 'Carter on farm'),
['Carter on a farm'], '"Carter on farm" also gains "a"');
};
# -----------------------------------------------------------------------
# _get_language - environment variable cascade (all fallback paths)
# -----------------------------------------------------------------------
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; _get_language must fall through to LANGUAGE
my $guard = mock_scoped('I18N::LangTags::Detect::detect' => sub { () });
my $obj = Genealogy::Occupation->new();
is_deeply($obj->normalise(occupation => 'Teacher', sex => 'M'),
['Lehrer'], 'LANGUAGE env var drives German language detection');
};
subtest '_get_language - LC_ALL used when LANGUAGE and detect() both absent' => sub {
delete local $ENV{LANGUAGE};
delete local $ENV{LC_MESSAGES};
delete local $ENV{LANG};
local $ENV{LC_ALL} = 'fr_FR.UTF-8';
my $guard = mock_scoped('I18N::LangTags::Detect::detect' => sub { () });
my $obj = Genealogy::Occupation->new();
is_deeply($obj->normalise(occupation => 'Farmer', sex => 'M'),
['Agriculteur'], 'LC_ALL env var drives French language detection');
};
subtest '_get_language - LC_MESSAGES used when higher-priority vars absent' => sub {
delete local $ENV{LANGUAGE};
delete local $ENV{LC_ALL};
delete local $ENV{LANG};
local $ENV{LC_MESSAGES} = 'de_DE.UTF-8';
my $guard = mock_scoped('I18N::LangTags::Detect::detect' => sub { () });
my $obj = Genealogy::Occupation->new();
is_deeply($obj->normalise(occupation => 'Farmer', sex => 'M'),
['Bauer'], 'LC_MESSAGES env var drives German language detection');
};
subtest '_get_language - C.UTF-8 locale treated as English' => sub {
delete local $ENV{LANGUAGE};
delete local $ENV{LC_ALL};
delete local $ENV{LC_MESSAGES};
local $ENV{LANG} = 'C.UTF-8';
my $guard = mock_scoped('I18N::LangTags::Detect::detect' => sub { () });
# /^C(\.|$)/ matches both 'C' and 'C.anything' and returns 'en'
my $obj = Genealogy::Occupation->new();
is_deeply($obj->normalise(occupation => 'Ag Lab'), ['Agricultural Labourer'],
'C.UTF-8 locale treated as English');
};
subtest '_get_language - detect() returning hyphenated tag extracts prefix' => sub {
delete local $ENV{LANGUAGE};
delete local $ENV{LC_ALL};
delete local $ENV{LC_MESSAGES};
( run in 1.934 second using v1.01-cache-2.11-cpan-9581c071862 )