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