Commit | Line | Data |
4bbcc6e8 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
fb175bb2 |
5 | @INC = '../lib'; |
4bbcc6e8 |
6 | require Config; import Config; |
b270fb37 |
7 | if ($Config{'extensions'} !~ m!\bI18N/Langinfo\b! || |
2a2d7c2c |
8 | $Config{'extensions'} !~ m!\bPOSIX\b!) |
b270fb37 |
9 | { |
10 | print "1..0 # skip: I18N::Langinfo or POSIX unavailable\n"; |
4bbcc6e8 |
11 | exit 0; |
12 | } |
13 | } |
2a2d7c2c |
14 | |
15 | use I18N::Langinfo qw(langinfo); |
642c2bac |
16 | use POSIX qw(setlocale LC_ALL); |
bb5b2f6d |
17 | |
18 | setlocale(LC_ALL, $ENV{LC_ALL} = $ENV{LANG} = "C"); |
4bbcc6e8 |
19 | |
9250d75a |
20 | print "1..1\n"; # We loaded okay. That's about all we can hope for. |
21 | print "ok 1\n"; |
22 | exit(0); |
8a485222 |
23 | |
9250d75a |
24 | # Background: the langinfo() (in C known as nl_langinfo()) interface |
8a485222 |
25 | # is supposed to be a portable way to fetch various language/country |
26 | # (locale) dependent constants like "the first day of the week" or |
27 | # "the decimal separator". Give a portable (numeric) constant, |
28 | # get back a language-specific string. That's a comforting fantasy. |
29 | # Now tune in for blunt reality: vendors seem to have implemented for |
30 | # those constants whatever they felt like implementing. The UNIX |
31 | # standard says that one should have the RADIXCHAR constant for the |
32 | # decimal separator. Not so for many Linux and BSD implementations. |
33 | # One should have the CODESET constant for returning the current |
34 | # codeset (say, ISO 8859-1). Not so. So let's give up any real |
35 | # testing (leave the old testing code here for old times' sake, |
36 | # though.) --jhi |
9250d75a |
37 | |
2a2d7c2c |
38 | my %want = |
39 | ( |
40 | ABDAY_1 => "Sun", |
41 | DAY_1 => "Sunday", |
42 | ABMON_1 => "Jan", |
43 | MON_1 => "January", |
44 | RADIXCHAR => ".", |
2a2d7c2c |
45 | AM_STR => qr{^(?:am|a\.m\.)$}i, |
46 | THOUSEP => "", |
47 | D_T_FMT => qr{^%a %b %[de] %H:%M:%S %Y$}, |
48 | D_FMT => qr{^%m/%d/%y$}, |
49 | T_FMT => qr{^%H:%M:%S$}, |
50 | ); |
51 | |
52 | |
53 | my @want = sort keys %want; |
54 | |
55 | print "1..", scalar @want, "\n"; |
56 | |
57 | for my $i (1..@want) { |
58 | my $try = $want[$i-1]; |
59 | eval { I18N::Langinfo->import($try) }; |
60 | unless ($@) { |
61 | my $got = langinfo(&$try); |
62 | if (ref $want{$try} && $got =~ $want{$try} || $got eq $want{$try}) { |
63 | print qq[ok $i - $try is "$got"\n]; |
64 | } else { |
65 | print qq[not ok $i - $try is "$got" not "$want{$try}"\n]; |
66 | } |
bb5b2f6d |
67 | } else { |
2a2d7c2c |
68 | print qq[ok $i - Skip: $try not defined\n]; |
69af93f8 |
69 | } |
69af93f8 |
70 | } |
4bbcc6e8 |
71 | |