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> &amp; <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 )