Commit | Line | Data |
---|---|---|
6aaed204 NC |
1 | use strict; |
2 | use Test::More tests => 17; | |
3 | BEGIN {use_ok('I18N::LangTags::Detect', 1.01);} | |
8000a3fa | 4 | |
6aaed204 | 5 | note("Using I18N::LangTags::Detect v$I18N::LangTags::Detect::VERSION"); |
8000a3fa | 6 | |
6aaed204 NC |
7 | note("Make sure we can assign to ENV entries"); |
8 | note("Otherwise we can't run the subsequent tests"); | |
9 | $ENV{'MYORP'} = 'Zing'; is($ENV{'MYORP'}, 'Zing'); | |
10 | $ENV{'SWUZ'} = 'KLORTHO HOOBOY'; is($ENV{'SWUZ'}, 'KLORTHO HOOBOY'); | |
8000a3fa RGS |
11 | |
12 | delete $ENV{'MYORP'}; | |
13 | delete $ENV{'SWUZ'}; | |
14 | ||
8575f5e6 RGS |
15 | sub printenv { |
16 | print "# ENV:\n"; | |
17 | foreach my $k (sort keys %ENV) { | |
18 | my $p = $ENV{$k}; $p =~ s/\n/\n#/g; | |
19 | print "# [$k] = [$p]\n"; } | |
20 | print "# [end of ENV]\n#\n"; | |
21 | } | |
22 | ||
8fcd89ec | 23 | $ENV{'IGNORE_WIN32_LOCALE'} = 1; # a hack, just for testing's sake. |
8000a3fa | 24 | |
6aaed204 NC |
25 | foreach my $test_var (qw (LANGUAGE LC_ALL LC_MESSAGES LANG)) { |
26 | $ENV{$_} = '' foreach qw(REQUEST_METHOD LANGUAGE LC_ALL LC_MESSAGES LANG); | |
27 | $ENV{$test_var} = 'Eu-MT'; | |
28 | my $what = "I18N::LangTags::Detect::detect() for \$ENV{$test_var} = 'Eu-MT'"; | |
29 | printenv(); | |
30 | is(scalar I18N::LangTags::Detect::detect(), "eu-mt", | |
31 | "scalar $what"); | |
32 | is_deeply([I18N::LangTags::Detect::detect()], ["eu-mt"], $what); | |
33 | } | |
66ee8a1c | 34 | |
6aaed204 | 35 | note("Test HTTP_ACCEPT_LANGUAGE"); |
8000a3fa | 36 | $ENV{'REQUEST_METHOD'} = 'GET'; |
8000a3fa | 37 | |
6aaed204 NC |
38 | foreach(['eu-MT', "eu-mt"], |
39 | ['x-plorp, zaz, eu-MT, i-klung', | |
40 | 'x-plorp', 'i-plorp', 'zaz', 'eu-mt', 'i-klung', 'x-klung'], | |
41 | ['x-plorp, zaz, eU-Mt, i-klung', | |
42 | 'x-plorp', 'i-plorp', 'zaz', 'eu-mt', 'i-klung', 'x-klung'], | |
43 | ) { | |
44 | my ($val, @expect) = @$_; | |
45 | my $what = "I18N::LangTags::Detect::detect() for \$ENV{HTTP_ACCEPT_LANGUAGE} = '$val'"; | |
46 | $ENV{'HTTP_ACCEPT_LANGUAGE'} = $val; | |
47 | printenv(); | |
48 | is(scalar I18N::LangTags::Detect::detect(), $expect[0], "scalar $what"); | |
49 | is_deeply([I18N::LangTags::Detect::detect()], \@expect, $what); | |
50 | } |