Commit | Line | Data |
---|---|---|
8000a3fa RGS |
1 | |
2 | require 5; | |
3 | use Test; | |
66ee8a1c | 4 | # Time-stamp: "2004-07-01 14:33:50 ADT" |
1d810d02 | 5 | BEGIN { plan tests => 18; } |
8000a3fa RGS |
6 | use I18N::LangTags::Detect 1.01; |
7 | print "# Hi there...\n"; | |
8 | ok 1; | |
9 | ||
8575f5e6 RGS |
10 | print "# Using I18N::LangTags::Detect v$I18N::LangTags::Detect::VERSION\n"; |
11 | ||
8000a3fa RGS |
12 | print "# Make sure we can assign to ENV entries\n", |
13 | "# (Otherwise we can't run the subsequent tests)...\n"; | |
14 | $ENV{'MYORP'} = 'Zing'; ok $ENV{'MYORP'}, 'Zing'; | |
15 | $ENV{'SWUZ'} = 'KLORTHO HOOBOY'; ok $ENV{'SWUZ'}, 'KLORTHO HOOBOY'; | |
16 | ||
17 | delete $ENV{'MYORP'}; | |
18 | delete $ENV{'SWUZ'}; | |
19 | ||
8575f5e6 RGS |
20 | sub j { "[" . join(' ', map "\"$_\"", @_) . "]" ;} |
21 | ||
22 | sub show { | |
23 | print "# (Seeing {", join(' ', | |
24 | map(qq{<$_>}, @_)), "} at line ", (caller)[2], ")\n"; | |
25 | printenv(); | |
26 | return $_[0] || ''; | |
27 | } | |
28 | sub printenv { | |
29 | print "# ENV:\n"; | |
30 | foreach my $k (sort keys %ENV) { | |
31 | my $p = $ENV{$k}; $p =~ s/\n/\n#/g; | |
32 | print "# [$k] = [$p]\n"; } | |
33 | print "# [end of ENV]\n#\n"; | |
34 | } | |
35 | ||
8fcd89ec | 36 | $ENV{'IGNORE_WIN32_LOCALE'} = 1; # a hack, just for testing's sake. |
8000a3fa | 37 | |
66ee8a1c RGS |
38 | |
39 | print "# Test LANGUAGE...\n"; | |
40 | $ENV{'REQUEST_METHOD'} = ''; | |
41 | $ENV{'LANGUAGE'} = 'Eu-MT'; | |
42 | $ENV{'LC_ALL'} = ''; | |
43 | $ENV{'LC_MESSAGES'} = ''; | |
44 | $ENV{'LANG'} = ''; | |
45 | ok show( scalar I18N::LangTags::Detect::detect()), "eu-mt"; | |
46 | ok show( j I18N::LangTags::Detect::detect()), q{["eu-mt"]}; | |
47 | ||
48 | ||
49 | print "# Test LC_ALL...\n"; | |
50 | $ENV{'REQUEST_METHOD'} = ''; | |
51 | $ENV{'LANGUAGE'} = ''; | |
52 | $ENV{'LC_ALL'} = 'Eu-MT'; | |
53 | $ENV{'LC_MESSAGES'} = ''; | |
54 | $ENV{'LANG'} = ''; | |
55 | ||
56 | ok show( scalar I18N::LangTags::Detect::detect()), "eu-mt"; | |
57 | ok show( j I18N::LangTags::Detect::detect()), q{["eu-mt"]}; | |
58 | ||
59 | print "# Test LC_MESSAGES...\n"; | |
60 | $ENV{'REQUEST_METHOD'} = ''; | |
61 | $ENV{'LANGUAGE'} = ''; | |
62 | $ENV{'LC_ALL'} = ''; | |
63 | $ENV{'LC_MESSAGES'} = 'Eu-MT'; | |
64 | $ENV{'LANG'} = ''; | |
65 | ||
66 | ok show( scalar I18N::LangTags::Detect::detect()), "eu-mt"; | |
67 | ok show( j I18N::LangTags::Detect::detect()), q{["eu-mt"]}; | |
68 | ||
69 | ||
8000a3fa RGS |
70 | print "# Test LANG...\n"; |
71 | $ENV{'REQUEST_METHOD'} = ''; | |
66ee8a1c RGS |
72 | $ENV{'LANGUAGE'} = ''; |
73 | $ENV{'LC_ALL'} = ''; | |
74 | $ENV{'LC_MESSAGES'} = ''; | |
75 | $ENV{'LANG'} = 'Eu_MT'; | |
76 | ||
8575f5e6 RGS |
77 | ok show( scalar I18N::LangTags::Detect::detect()), "eu-mt"; |
78 | ok show( j I18N::LangTags::Detect::detect()), q{["eu-mt"]}; | |
8000a3fa | 79 | |
66ee8a1c RGS |
80 | |
81 | ||
66ee8a1c | 82 | |
8000a3fa RGS |
83 | print "# Test HTTP_ACCEPT_LANGUAGE...\n"; |
84 | $ENV{'REQUEST_METHOD'} = 'GET'; | |
85 | $ENV{'HTTP_ACCEPT_LANGUAGE'} = 'eu-MT'; | |
8575f5e6 RGS |
86 | ok show( scalar I18N::LangTags::Detect::detect()), "eu-mt"; |
87 | ok show( j I18N::LangTags::Detect::detect()), q{["eu-mt"]}; | |
88 | ||
8000a3fa RGS |
89 | |
90 | $ENV{'HTTP_ACCEPT_LANGUAGE'} = 'x-plorp, zaz, eu-MT, i-klung'; | |
8575f5e6 RGS |
91 | ok show( scalar I18N::LangTags::Detect::detect()), "x-plorp"; |
92 | ok show( j I18N::LangTags::Detect::detect()), qq{["x-plorp" "i-plorp" "zaz" "eu-mt" "i-klung" "x-klung"]}; | |
8000a3fa RGS |
93 | |
94 | $ENV{'HTTP_ACCEPT_LANGUAGE'} = 'x-plorp, zaz, eU-Mt, i-klung'; | |
8575f5e6 RGS |
95 | ok show( scalar I18N::LangTags::Detect::detect()), "x-plorp"; |
96 | ok show( j I18N::LangTags::Detect::detect()), qq{["x-plorp" "i-plorp" "zaz" "eu-mt" "i-klung" "x-klung"]}; | |
97 | ||
8000a3fa RGS |
98 | |
99 | ||
100 | ||
101 | print "# Byebye!\n"; | |
102 | ok 1; | |
103 |