Hack to remove insecure directories from PATH so test will run.
[p5sagit/p5-mst-13.2.git] / t / lib / lc-country.t
1 #!./perl
2 #
3 # country.t - tests for Locale::Country
4 #
5
6 BEGIN {
7         chdir 't' if -d 't';
8         @INC = '../lib';
9 }
10
11 use Locale::Country;
12
13 #-----------------------------------------------------------------------
14 # This is an array of tests specs. Each spec is [TEST, OK_TO_DIE]
15 # Each TEST is eval'd as an expression.
16 # If it evaluates to FALSE, then "not ok N" is printed for the test,
17 # otherwise "ok N". If the eval dies, then the OK_TO_DIE flag is checked.
18 # If it is true (1), the test is treated as passing, otherwise it failed.
19 #-----------------------------------------------------------------------
20 @TESTS =
21 (
22         #================================================
23         # TESTS FOR code2country
24         #================================================
25
26  #---- selection of examples which should all result in undef -----------
27  ['!defined code2country()', 0],                  # no argument
28  ['!defined code2country(undef)', 0],             # undef argument
29  ['!defined code2country("zz")', 0],              # illegal code
30  ['!defined code2country("zz", LOCALE_CODE_ALPHA_2)', 0],        # illegal code
31  ['!defined code2country("zz", LOCALE_CODE_ALPHA_3)', 0],        # illegal code
32  ['!defined code2country("zz", LOCALE_CODE_NUMERIC)', 0],        # illegal code
33  ['!defined code2country("ja")', 0],              # should be jp for country
34  ['!defined code2country("uk")', 0],              # should be jp for country
35
36  #---- some successful examples -----------------------------------------
37  ['code2country("BO") eq "Bolivia"', 0],
38  ['code2country("BO", LOCALE_CODE_ALPHA_2) eq "Bolivia"', 0],
39  ['code2country("bol", LOCALE_CODE_ALPHA_3) eq "Bolivia"', 0],
40  ['code2country("pk") eq "Pakistan"', 0],
41  ['code2country("sn") eq "Senegal"', 0],
42  ['code2country("us") eq "United States"', 0],
43  ['code2country("ad") eq "Andorra"', 0],          # first in DATA segment
44  ['code2country("ad", LOCALE_CODE_ALPHA_2) eq "Andorra"', 0],
45  ['code2country("and", LOCALE_CODE_ALPHA_3) eq "Andorra"', 0],
46  ['code2country("020", LOCALE_CODE_NUMERIC) eq "Andorra"', 0],
47  ['code2country(48, LOCALE_CODE_NUMERIC) eq "Bahrain"', 0],
48  ['code2country("zw") eq "Zimbabwe"', 0],         # last in DATA segment
49  ['code2country("gb") eq "United Kingdom"', 0],   # United Kingdom is "gb", not "uk"
50
51         #================================================
52         # TESTS FOR country2code
53         #================================================
54
55  #---- selection of examples which should all result in undef -----------
56  ['!defined code2country("BO", LOCALE_CODE_ALPHA_3)', 0],
57  ['!defined code2country("BO", LOCALE_CODE_NUMERIC)', 0],
58  ['!defined country2code()', 0],                  # no argument
59  ['!defined country2code(undef)', 0],             # undef argument
60  ['!defined country2code("Banana")', 0],          # illegal country name
61
62  #---- some successful examples -----------------------------------------
63  ['country2code("japan")          eq "jp"', 0],
64  ['country2code("japan")          ne "ja"', 0],
65  ['country2code("Japan")          eq "jp"', 0],
66  ['country2code("United States")  eq "us"', 0],
67  ['country2code("United Kingdom") eq "gb"', 0],
68  ['country2code("Andorra")        eq "ad"', 0],    # first in DATA segment
69  ['country2code("Zimbabwe")       eq "zw"', 0],    # last in DATA segment
70
71         #================================================
72         # TESTS FOR country_code2code
73         #================================================
74
75  #---- selection of examples which should all result in undef -----------
76  ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
77  ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3)', 0],
78  ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
79  ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2)', 1],
80  ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_2)', 1],
81  ['!defined country_code2code()', 1],                  # no argument
82  ['!defined country_code2code(undef)', 1],             # undef argument
83
84  #---- some successful examples -----------------------------------------
85  ['country_code2code("BO", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3) eq "bol"', 0],
86  ['country_code2code("bol", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "bo"', 0],
87  ['country_code2code("zwe", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "zw"', 0],
88  ['country_code2code("858", LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0],
89  ['country_code2code(858, LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0],
90  ['country_code2code("tr", LOCALE_CODE_ALPHA_2, LOCALE_CODE_NUMERIC) eq "792"', 0],
91
92 );
93
94 print "1..", int(@TESTS), "\n";
95
96 $testid = 1;
97 foreach $test (@TESTS)
98 {
99     eval "print (($test->[0]) ? \"ok $testid\\n\" : \"not ok $testid\\n\" )";
100     if ($@)
101     {
102         if (!$test->[1])
103         {
104             print "not ok $testid\n";
105         }
106         else
107         {
108             print "ok $testid\n";
109         }
110     }
111     ++$testid;
112 }
113
114 exit 0;