AmberDB
view release on metacpan or search on metacpan
t/amberdb-locale_00.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use open ':std', ':utf8';
use Test::More;
binmode Test::More->builder->output, ':utf8';
binmode Test::More->builder->failure_output, ':utf8';
binmode Test::More->builder->todo_output, ':utf8';
use FindBin qw($Bin);
use lib "$Bin/../lib", 'lib';
use AmberDB::Locale;
# ============================================================
# 1. Constructor â Turkish locale
# ============================================================
my $tr = AmberDB::Locale->new( language => 'tr' );
is( $tr->language, 'tr', 'Constructor: language tag stored' );
# ============================================================
# 2. English locale and Global Base (gb) fallback
# ============================================================
my $en = AmberDB::Locale->new( language => 'en' );
is( $en->language, 'en', 'Constructor: English locale' );
# Unknown locale falls back to gb
my $xx;
{
local $SIG{__WARN__} = sub {}; # suppress fallback warning
$xx = AmberDB::Locale->new( language => 'zz' );
}
is( $xx->language, 'gb', 'Constructor: unknown locale falls back to gb' );
# ============================================================
# 3. Turkish casing â uc()
# ============================================================
is( $tr->uc('istanbul'), 'İSTANBUL', 'tr->uc: i â İ' );
is( $tr->uc('ankara'), 'ANKARA', 'tr->uc: plain ASCII' );
# ============================================================
# 4. Turkish casing â lc()
# ============================================================
# In Turkish: uppercase I â lowercase ı (dotless), İ â i
is( $tr->lc('I'), 'ı', 'tr->lc: I â ı' );
is( $tr->lc('İ'), 'i', 'tr->lc: İ â i' );
# Full word: ISTANBUL â ıstanbul (all I become ı in Turkish)
is( $tr->lc('ISTANBUL'), 'ıstanbul', 'tr->lc: ISTANBUL â ıstanbul (Turkish Iâı rule)' );
# ============================================================
# 5. English casing â no Turkish rules
# ============================================================
is( $en->uc('istanbul'), 'ISTANBUL', 'en->uc: plain uc no dotted-I' );
is( $en->lc('I'), 'i', 'en->lc: plain I â i' );
# ============================================================
# 6. ucfirst
# ============================================================
my $str = $tr->ucfirst('istanbul Åehri büyük');
# After lc: 'istanbul Åehri büyük'
# After ucfirst each word: 'İstanbul Åehri Büyük'
is( substr($str,0,1), 'İ', 'tr->ucfirst: first char İ' );
# ============================================================
# 7. sort (Unicode::Collate::Locale)
# ============================================================
my @words = qw(çay bal arı Åeker güzel);
my @sorted_tr = $tr->sort( \@words );
# Turkish order: arı, bal, çay, güzel, Åeker
t/amberdb-locale_00.t view on Meta::CPAN
# ============================================================
# 9. normalize
# ============================================================
my $norm = $tr->normalize('<b>Ãay</b> & Åeker');
# HTML stripped, & entity cleaned, Turkish chars kept
is( $norm, 'Ãay & Åeker', 'tr->normalize: strip HTML keep Turkish' );
# ============================================================
# 10. decode_entities
# ============================================================
is( $tr->decode_entities('&lt;'), '<', 'decode_entities: & â &' );
is( $tr->decode_entities('Ç'), 'Ã', 'decode_entities: Ç â Ã' );
is( $tr->decode_entities('ç'), 'ç', 'decode_entities: ç â ç (tr locale)' );
# English locale has no ç extra â should pass through unchanged
is( $en->decode_entities('&'), '&', 'en->decode_entities: & â &' );
# ============================================================
# 11. num2text â Turkish
# ============================================================
is( $tr->num2text(0), 'Sıfır', 'num2text: 0 â Sıfır' );
is( $tr->num2text(1), 'Bir TL', 'num2text: 1 â Bir TL' );
is( $tr->num2text(10), 'On TL', 'num2text: 10 â On TL' );
is( $tr->num2text(100), 'Yüz TL', 'num2text: 100 â Yüz TL' );
is( $tr->num2text(1000), 'Bin TL', 'num2text: 1000 â Bin (not Bir Bin)' );
is( $tr->num2text(2000), 'İki Bin TL', 'num2text: 2000 â İki Bin TL' );
is( $tr->num2text(1000000), 'Bir Milyon TL', 'num2text: 1000000' );
# num2text â external numbers hash override
my %custom = (
zero => 'Zero',
ones => [qw(One Two Three Four Five Six Seven Eight Nine)],
tens => [qw(Ten Twenty Thirty Forty Fifty Sixty Seventy Eighty Ninety)],
hundred => 'Hundred',
thousand => 'Thousand',
million => 'Million',
billion => 'Billion',
currency => { main => 'USD', sub => 'cent' },
decimal_sep => '.',
thousand_one_prefix => 1,
);
is( $tr->num2text(0, numbers => \%custom), 'Zero', 'num2text: external 0' );
is( $tr->num2text(1, numbers => \%custom), 'One USD', 'num2text: external 1' );
is( $tr->num2text(100, numbers => \%custom), 'One Hundred USD', 'num2text: external 100' );
is( $tr->num2text(1000,numbers => \%custom), 'One Thousand USD', 'num2text: external 1000' );
# Currency override
is( $tr->num2text(1, currency => { main => 'EUR', sub => 'cent' }),
'Bir EUR', 'num2text: currency override' );
# ============================================================
# 12. first_char
# ============================================================
is( $tr->first_char('çay'), 'Ã', 'first_char: çay â Ã' );
is( $tr->first_char('arı'), 'A', 'first_char: arı â A' );
is( $tr->first_char('123'), '0-9', 'first_char: number â 0-9' );
# ============================================================
# 13. substring (locale-independent)
# ============================================================
my $utf8_str = Encode::encode('UTF-8', 'Ãaylık bahçe');
my $sub = $tr->substring($utf8_str, 6);
is( Encode::decode('UTF-8',$sub), 'Ãaylık', 'substring: 6 chars UTF-8' );
# ============================================================
# 14. German locale (de)
# ============================================================
my $de = AmberDB::Locale->new( language => 'de' );
is( $de->language, 'de', 'de locale: loaded' );
is( $de->to_ascii('München'), 'Muenchen', 'de->to_ascii: ü â ue' );
is( $de->to_ascii('StraÃe'), 'Strasse', 'de->to_ascii: Ã â ss' );
# ============================================================
# 15. French locale (fr)
# ============================================================
my $fr = AmberDB::Locale->new( language => 'fr' );
is( $fr->language, 'fr', 'fr locale: loaded' );
is( $fr->to_ascii('Château'), 'Chateau', 'fr->to_ascii: Château â Chateau' );
is( $fr->num2text(100), 'Cent EUR', 'fr->num2text: 100 â Cent EUR' );
# ============================================================
# 16. Spanish locale (es)
# ============================================================
my $es = AmberDB::Locale->new( language => 'es' );
is( $es->language, 'es', 'es locale: loaded' );
is( $es->to_ascii('Niño'), 'Nino', 'es->to_ascii: Niño â Nino' );
is( $es->num2text(1), 'Uno EUR', 'es->num2text: 1 â Uno EUR' );
# ============================================================
# 17. Russian locale (ru)
# ============================================================
my $ru = AmberDB::Locale->new( language => 'ru' );
is( $ru->language, 'ru', 'ru locale: loaded' );
is( $ru->num2text(100), 'СÑо RUB', 'ru->num2text: 100 â СÑо RUB' );
# ============================================================
# 18. Arabic locale (ar)
# ============================================================
my $ar = AmberDB::Locale->new( language => 'ar' );
is( $ar->language, 'ar', 'ar locale: loaded' );
is( $ar->num2text(1), 'ÙØ§ØØ¯ SAR', 'ar->num2text: 1 â ÙØ§ØØ¯ SAR' );
# ============================================================
# 19. Azerbaijani locale (az)
# ============================================================
my $az = AmberDB::Locale->new( language => 'az' );
is( $az->language, 'az', 'az locale: loaded' );
is( $az->lc('Æ'), 'É', 'az->lc: Æ â É' );
is( $az->to_ascii('Bakı'), 'Baki', 'az->to_ascii: Bakı â Baki' );
done_testing();
( run in 0.776 second using v1.01-cache-2.11-cpan-364913b4093 )