diff options
author | Karl Williamson <khw@cpan.org> | 2017-09-07 16:25:33 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2017-09-09 21:27:44 -0600 |
commit | a955329feb1bca301b7432e95da0cf75d52211a8 (patch) | |
tree | 8e47692297d32676dde44f37cc0ae2249624e214 /ext/I18N-Langinfo | |
parent | f1d36e7cfb15f7f95884896e0b408c9b7ed49cac (diff) | |
download | perl-a955329feb1bca301b7432e95da0cf75d52211a8.tar.gz |
I18N-Langinfo/t/Langinfo.t: Reinstate tests, modernize
The comments say that a bunch of tests were disabled due to the poor
support of nl_langinfo() at the time, 2001. I haven't seen these issues
lately, and so am reinstating many of the tests, using the modern
Test::More that the rest of the file in the meantime had been updated to
use. The tests that weren't reinstated were because results for them
may vary by platform.
Diffstat (limited to 'ext/I18N-Langinfo')
-rw-r--r-- | ext/I18N-Langinfo/t/Langinfo.t | 66 |
1 files changed, 20 insertions, 46 deletions
diff --git a/ext/I18N-Langinfo/t/Langinfo.t b/ext/I18N-Langinfo/t/Langinfo.t index deaaf2851e..25d30e6fb3 100644 --- a/ext/I18N-Langinfo/t/Langinfo.t +++ b/ext/I18N-Langinfo/t/Langinfo.t @@ -8,10 +8,25 @@ plan skip_all => "I18N::Langinfo or POSIX unavailable" my @constants = qw(ABDAY_1 DAY_1 ABMON_1 MON_1 RADIXCHAR AM_STR THOUSEP D_T_FMT D_FMT T_FMT); -plan tests => 1 + 3 * @constants; +my %want = + ( + ABDAY_1 => "Sun", + DAY_1 => "Sunday", + ABMON_1 => "Jan", + MON_1 => "January", + RADIXCHAR => ".", + THOUSEP => "", + ); + +my @want = sort keys %want; + +plan tests => 1 + 3 * @constants + keys(@want); use_ok('I18N::Langinfo', 'langinfo', @constants); +use POSIX; +setlocale(LC_ALL, "C"); + for my $constant (@constants) { SKIP: { my $string = eval { langinfo(eval "$constant()") }; @@ -22,53 +37,12 @@ for my $constant (@constants) { } } -exit(0); - -# Background: the langinfo() (in C known as nl_langinfo()) interface -# is supposed to be a portable way to fetch various language/country -# (locale) dependent constants like "the first day of the week" or -# "the decimal separator". Give a portable (numeric) constant, -# get back a language-specific string. That's a comforting fantasy. -# Now tune in for blunt reality: vendors seem to have implemented for -# those constants whatever they felt like implementing. The UNIX -# standard says that one should have the RADIXCHAR constant for the -# decimal separator. Not so for many Linux and BSD implementations. -# One should have the CODESET constant for returning the current -# codeset (say, ISO 8859-1). Not so. So let's give up any real -# testing (leave the old testing code here for old times' sake, -# though.) --jhi - -my %want = - ( - ABDAY_1 => "Sun", - DAY_1 => "Sunday", - ABMON_1 => "Jan", - MON_1 => "January", - RADIXCHAR => ".", - AM_STR => qr{^(?:am|a\.m\.)$}i, - THOUSEP => "", - D_T_FMT => qr{^%a %b %[de] %H:%M:%S %Y$}, - D_FMT => qr{^%m/%d/%y$}, - T_FMT => qr{^%H:%M:%S$}, - ); - - -my @want = sort keys %want; - -print "1..", scalar @want, "\n"; - for my $i (1..@want) { my $try = $want[$i-1]; eval { I18N::Langinfo->import($try) }; - unless ($@) { - my $got = langinfo(&$try); - if (ref $want{$try} && $got =~ $want{$try} || $got eq $want{$try}) { - print qq[ok $i - $try is "$got"\n]; - } else { - print qq[not ok $i - $try is "$got" not "$want{$try}"\n]; - } - } else { - print qq[ok $i - Skip: $try not defined\n]; + SKIP: { + skip "$try not defined", 1, if $@; + no strict 'refs'; + is (langinfo(&$try), $want{$try}, "$try => '$want{$try}'"); } } - |