This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move $func_header inside while loop closer to where it's used
[perl5.git] / dist / I18N-LangTags / t / 80_all_env.t
CommitLineData
6aaed204
NC
1use strict;
2use Test::More tests => 17;
3BEGIN {use_ok('I18N::LangTags::Detect', 1.01);}
8000a3fa 4
6aaed204 5note("Using I18N::LangTags::Detect v$I18N::LangTags::Detect::VERSION");
8000a3fa 6
6aaed204
NC
7note("Make sure we can assign to ENV entries");
8note("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
12delete $ENV{'MYORP'};
13delete $ENV{'SWUZ'};
14
8575f5e6
RGS
15sub 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
25foreach 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 35note("Test HTTP_ACCEPT_LANGUAGE");
8000a3fa 36$ENV{'REQUEST_METHOD'} = 'GET';
8000a3fa 37
6aaed204
NC
38foreach(['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}