1#!/usr/bin/env perl 2 3use utf8; 4use strict; 5use warnings; 6use lib 't/lib'; 7 8use Test::More; 9use Test::More::UTF8; 10use My::Test::Util; 11use Math::Currency qw($LC_MONETARY); 12use POSIX; 13 14plan tests => 2; 15 16my $format = {}; 17 18my %LocaleData = ( 19 CURRENCY_SYMBOL => '¥', 20 FRAC_DIGITS => '0', 21 INT_CURR_SYMBOL => 'JPY ', 22 INT_FRAC_DIGITS => '0', 23 MON_DECIMAL_POINT => '.', 24 MON_GROUPING => '3', 25 MON_THOUSANDS_SEP => ',', 26 NEGATIVE_SIGN => '-', 27 N_CS_PRECEDES => '1', 28 N_SEP_BY_SPACE => '0', 29 N_SIGN_POSN => '4', 30 POSITIVE_SIGN => '', 31 P_CS_PRECEDES => '1', 32 P_SEP_BY_SPACE => '0', 33); 34 35# NOTE: The following values are inconstent depending on system locale 36# definitions. Therefore they are not tested: 37# P_SIGN_POSN 38 39# there are several YEN symbols which the system locale might use. Any of 40# these are acceptable. 41# - U+00A5 YEN SIGN 42# - U+FFE5 FULLWIDTH YEN SIGN 43my @CurrencySymbols = ("\x{a5}", "\x{ffe5}"); 44 45subtest 'ja_JP' => sub { 46 plan_locale(ja_JP => 18); 47 48 use_ok('Math::Currency::ja_JP'); 49 50 Math::Currency->localize(\$format); 51 52 for my $param (sort keys %LocaleData) { 53 if ($param eq 'CURRENCY_SYMBOL') { 54 ok( grep { $format->{CURRENCY_SYMBOL} eq $_ } @CurrencySymbols ); 55 } 56 else { 57 is $format->{$param}, $LocaleData{$param}, 58 "format parameter $param = $LocaleData{$param}"; 59 } 60 } 61 62 my $obj = new_ok 'Math::Currency', ['12345.67', 'ja_JP']; 63 64 ok index("$obj", $LocaleData{CURRENCY_SYMBOL}) != -1, 65 'string contains currency symbol'; 66 ok index("$obj", $LocaleData{MON_THOUSANDS_SEP}) != -1, 67 'string contains thousands separator'; 68}; 69 70subtest 'JPY' => sub { 71 plan_locale(ja_JP => 18); 72 73 use_ok('Math::Currency::JPY'); 74 75 Math::Currency->localize(\$format); 76 77 for my $param (sort keys %LocaleData) { 78 if ($param eq 'CURRENCY_SYMBOL') { 79 ok( grep { $format->{CURRENCY_SYMBOL} eq $_ } @CurrencySymbols ); 80 } 81 else { 82 is $format->{$param}, $LocaleData{$param}; 83 } 84 } 85 86 my $obj = new_ok 'Math::Currency', ['12345.67', 'JPY']; 87 88 ok index("$obj", $LocaleData{CURRENCY_SYMBOL}) != -1, 89 'string contains currency symbol'; 90 ok index("$obj", $LocaleData{MON_THOUSANDS_SEP}) != -1, 91 'string contains thousands separator'; 92}; 93 94