This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove duplicate test for $ENV{LANG} in I18N::LangTags test 80_all_env.t
[perl5.git] / dist / I18N-LangTags / t / 80_all_env.t
1
2 require 5;
3 use Test;
4 # Time-stamp: "2004-07-01 14:33:50 ADT"
5 BEGIN { plan tests => 18; }
6 use I18N::LangTags::Detect 1.01;
7 print "# Hi there...\n";
8 ok 1;
9
10 print "# Using I18N::LangTags::Detect v$I18N::LangTags::Detect::VERSION\n";
11
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
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
36 $ENV{'IGNORE_WIN32_LOCALE'} = 1; # a hack, just for testing's sake.
37
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
70 print "# Test LANG...\n";
71 $ENV{'REQUEST_METHOD'} = '';
72 $ENV{'LANGUAGE'}       = '';
73 $ENV{'LC_ALL'}         = '';
74 $ENV{'LC_MESSAGES'}    = '';
75 $ENV{'LANG'}           = 'Eu_MT';
76
77 ok show( scalar I18N::LangTags::Detect::detect()),    "eu-mt";
78 ok show( j      I18N::LangTags::Detect::detect()), q{["eu-mt"]};
79
80
81
82
83 print "# Test HTTP_ACCEPT_LANGUAGE...\n";
84 $ENV{'REQUEST_METHOD'}       = 'GET';
85 $ENV{'HTTP_ACCEPT_LANGUAGE'} = 'eu-MT';
86 ok show( scalar I18N::LangTags::Detect::detect()),    "eu-mt";
87 ok show( j      I18N::LangTags::Detect::detect()), q{["eu-mt"]};
88
89
90 $ENV{'HTTP_ACCEPT_LANGUAGE'} = 'x-plorp, zaz, eu-MT, i-klung';
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"]};
93
94 $ENV{'HTTP_ACCEPT_LANGUAGE'} = 'x-plorp, zaz, eU-Mt, i-klung';
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
98
99
100
101 print "# Byebye!\n";
102 ok 1;
103