AmberDB
view release on metacpan or search on metacpan
t/amberdb-locale_09_gb.t view on Meta::CPAN
is( $global->language, 'gb', 'Alias language => global resolves to gb' );
# Alias 'gl'
my $gl = AmberDB::Locale->new( language => 'gl' );
is( $gl->language, 'gb', 'Alias language => gl resolves to gb' );
# Alias 'universal'
my $uni = AmberDB::Locale->new( language => 'universal' );
is( $uni->language, 'gb', 'Alias language => universal resolves to gb' );
# Positional string
my $pos = AmberDB::Locale->new('gb');
is( $pos->language, 'gb', 'Positional string new("gb") resolves to gb' );
};
# ============================================================
# 2. Multilingual Alphabet Character Class (alphabet_chars)
# ============================================================
subtest '2. Multilingual Alphabet Preservation in normalize' => sub {
plan tests => 4;
my $loc = AmberDB::Locale->new('gb');
# Turkish characters: ÃiÄdem Åafak ıÅık -> accent normalization turns to Cigdem Safak isik
is( $loc->normalize("ÃiÄdem Åafak ıÅık ÃÄretmen"), "Cigdem Safak isik Ogretmen", 'Turkish letters normalized correctly' );
# German: Mädchen läuft über die StraÃe -> Madchen lauft uber die Strasse
is( $loc->normalize("Mädchen läuft über die StraÃe"), "Madchen lauft uber die Strasse", 'German umlauts and à normalized' );
# French & Spanish
is( $loc->normalize("café crème cÅur garçon mañana"), "cafe creme coeur garcon manana", 'French & Spanish normalized' );
# HTML tags stripped and characters sanitized
is( $loc->normalize("<b>café</b> & <i>crème</i>"), "cafe & creme", 'HTML tags stripped and entities preserved/decoded' );
};
# ============================================================
# 3. Canonical Accent Normalization (normalize)
# ============================================================
subtest '3. Canonical Accent Normalization (normalize)' => sub {
plan tests => 6;
my $loc = AmberDB::Locale->new('gb');
# French
is( $loc->normalize("café"), "cafe", 'normalize: café -> cafe' );
is( $loc->normalize("HÃTEL"), "HOTEL", 'normalize: HÃTEL -> HOTEL' );
# German
is( $loc->normalize("München"), "Munchen", 'normalize: München -> Munchen' );
is( $loc->normalize("StraÃe"), "Strasse", 'normalize: StraÃe -> Strasse' );
# Turkish
is( $loc->normalize("ıÅık"), "isik", 'normalize: ıÅık -> isik' );
# Nordic
is( $loc->normalize("smørrebrød"), "smorrebrod", 'normalize: smørrebrød -> smorrebrod' );
};
# ============================================================
# 4. Lossless ASCII Transliteration (to_ascii / slug)
# ============================================================
subtest '4. Lossless ASCII Transliteration (to_ascii)' => sub {
plan tests => 8;
my $loc = AmberDB::Locale->new('gb');
is( $loc->to_ascii("StraÃe"), "Strasse", 'to_ascii: Ã -> ss' );
is( $loc->to_ascii("StraÃe", 1), "strasse", 'to_ascii slug: StraÃe -> strasse' );
is( $loc->to_ascii("bærum"), "baerum", 'to_ascii: æ -> ae' );
is( $loc->to_ascii("cÅur"), "coeur", 'to_ascii: Å -> oe' );
is( $loc->to_ascii("Kraków"), "Krakow", 'to_ascii: ó -> o' );
is( $loc->to_ascii("Åódź"), "Lodz", 'to_ascii: Å/ó/ź -> Lodz' );
is( $loc->to_ascii("smør"), "smor", 'to_ascii: ø -> o' );
is( $loc->to_ascii("ıÅık"), "isik", 'to_ascii: ı/Å -> isik' );
};
# ============================================================
# 5. Multilingual Search Regex (search_pattern & search_regex)
# ============================================================
subtest '5. Multilingual Search Regex Pattern' => sub {
plan tests => 5;
my $loc = AmberDB::Locale->new('gb');
# Searching 'cafe' matches both 'cafe' and 'café'
my $pat_c = $loc->search_pattern('cafe');
ok( $loc->search_regex('café', $pat_c), 'search_regex: cafe matches café' );
ok( $loc->search_regex('CAFE', $pat_c), 'search_regex: cafe matches CAFE' );
# Searching 'munchen' matches 'münchen'
my $pat_m = $loc->search_pattern('munchen');
ok( $loc->search_regex('München', $pat_m), 'search_regex: munchen matches München' );
# Searching 'seker' matches 'Åeker'
my $pat_s = $loc->search_pattern('seker');
ok( $loc->search_regex('Åeker', $pat_s), 'search_regex: seker matches Åeker' );
# Searching 'isik' matches 'ıÅık'
my $pat_i = $loc->search_pattern('isik');
ok( $loc->search_regex('ıÅık', $pat_i), 'search_regex: isik matches ıÅık' );
};
# ============================================================
# 6. AmberDB Engine Integration: Default Language is 'gb'
# ============================================================
subtest '6. AmberDB Engine Integration with Default gb Locale' => sub {
plan tests => 7;
my $tmpdir = tempdir( CLEANUP => 1 );
my $adb = AmberDB->new(
path => { dbase_dir => $tmpdir },
);
is( $adb->language, 'gb', 'AmberDB instance initializes with gb language by default' );
my $tbl = 'global_catalog';
$adb->table_attr( $tbl, {
record_index => 1,
search_block => [ 2, 3 ], # Title, Desc
});
# Insert items in multiple languages
( run in 0.326 second using v1.01-cache-2.11-cpan-aadc1410aed )