Rename ext/Hash/Util to ext/Hash-Util
[p5sagit/p5-mst-13.2.git] / ext / I18N-Langinfo / t / Langinfo.t
1 #!perl -T
2
3 BEGIN {
4     if ($ENV{PERL_CORE}) {
5         chdir 't';
6         @INC = '../lib';
7     }
8 }
9
10 use strict;
11 use Config;
12 use Test::More;
13
14 plan skip_all => "I18N::Langinfo or POSIX unavailable" 
15     if $Config{'extensions'} !~ m!\bI18N/Langinfo\b!;
16
17 my @constants = qw(ABDAY_1 DAY_1 ABMON_1 MON_1 RADIXCHAR AM_STR THOUSEP D_T_FMT D_FMT T_FMT);
18
19 plan tests => 1 + 3 * @constants;
20
21 use_ok('I18N::Langinfo', 'langinfo', @constants);
22
23 for my $constant (@constants) {
24     SKIP: {
25         my $string = eval { langinfo(eval "$constant()") };
26         is( $@, '', "calling langinfo() with $constant" );
27         skip "returned string was empty, skipping next two tests", 2 unless $string;
28         ok( defined $string, "checking if the returned string is defined" );
29         cmp_ok( length($string), '>=', 1, "checking if the returned string has a positive length" );
30     }
31 }
32
33 exit(0);
34
35 # Background: the langinfo() (in C known as nl_langinfo()) interface
36 # is supposed to be a portable way to fetch various language/country
37 # (locale) dependent constants like "the first day of the week" or
38 # "the decimal separator".  Give a portable (numeric) constant,
39 # get back a language-specific string.  That's a comforting fantasy.
40 # Now tune in for blunt reality: vendors seem to have implemented for
41 # those constants whatever they felt like implementing.  The UNIX
42 # standard says that one should have the RADIXCHAR constant for the
43 # decimal separator.  Not so for many Linux and BSD implementations.
44 # One should have the CODESET constant for returning the current
45 # codeset (say, ISO 8859-1).  Not so.  So let's give up any real
46 # testing (leave the old testing code here for old times' sake,
47 # though.) --jhi
48
49 my %want =
50     (
51      ABDAY_1    => "Sun",
52      DAY_1      => "Sunday",
53      ABMON_1    => "Jan",
54      MON_1      => "January",
55      RADIXCHAR  => ".",
56      AM_STR     => qr{^(?:am|a\.m\.)$}i,
57      THOUSEP    => "",
58      D_T_FMT    => qr{^%a %b %[de] %H:%M:%S %Y$},
59      D_FMT      => qr{^%m/%d/%y$},
60      T_FMT      => qr{^%H:%M:%S$},
61      );
62
63     
64 my @want = sort keys %want;
65
66 print "1..", scalar @want, "\n";
67     
68 for my $i (1..@want) {
69     my $try = $want[$i-1];
70     eval { I18N::Langinfo->import($try) };
71     unless ($@) {
72         my $got = langinfo(&$try);
73         if (ref $want{$try} && $got =~ $want{$try} || $got eq $want{$try}) {
74             print qq[ok $i - $try is "$got"\n];
75         } else {
76             print qq[not ok $i - $try is "$got" not "$want{$try}"\n];
77         }
78     } else {
79         print qq[ok $i - Skip: $try not defined\n];
80     }
81 }
82