Upgrade to Locale::Codes 2.00.
[p5sagit/p5-mst-13.2.git] / lib / Locale / Codes / t / country.t
CommitLineData
47a334e9 1#!./perl
2#
3# country.t - tests for Locale::Country
4#
5
a8135056 6BEGIN {
7 chdir 't' if -d 't';
8 @INC = '../lib';
9}
10
47a334e9 11use 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 -----------------------------------------
6b6e008c 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
69 ['country2code("Zimbabwe") eq "zw"', 0], # last in DATA
70 ['country2code("Iran") eq "ir"', 0], # alias
71 ['country2code("North Korea") eq "kp"', 0], # alias
72 ['country2code("South Korea") eq "kr"', 0], # alias
73 ['country2code("Libya") eq "ly"', 0], # alias
74 ['country2code("Syria") eq "sy"', 0], # alias
75 ['country2code("Svalbard") eq "sj"', 0], # alias
76 ['country2code("Jan Mayen") eq "sj"', 0], # alias
77 ['country2code("USA") eq "us"', 0], # alias
78 ['country2code("United States of America") eq "us"', 0], # alias
79 ['country2code("Great Britain") eq "gb"', 0], # alias
47a334e9 80
81 #================================================
82 # TESTS FOR country_code2code
83 #================================================
84
85 #---- selection of examples which should all result in undef -----------
86 ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
87 ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3)', 0],
88 ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
89 ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2)', 1],
90 ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_2)', 1],
91 ['!defined country_code2code()', 1], # no argument
92 ['!defined country_code2code(undef)', 1], # undef argument
93
94 #---- some successful examples -----------------------------------------
95 ['country_code2code("BO", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3) eq "bol"', 0],
96 ['country_code2code("bol", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "bo"', 0],
97 ['country_code2code("zwe", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "zw"', 0],
98 ['country_code2code("858", LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0],
99 ['country_code2code(858, LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0],
100 ['country_code2code("tr", LOCALE_CODE_ALPHA_2, LOCALE_CODE_NUMERIC) eq "792"', 0],
101
102);
103
104print "1..", int(@TESTS), "\n";
105
106$testid = 1;
107foreach $test (@TESTS)
108{
109 eval "print (($test->[0]) ? \"ok $testid\\n\" : \"not ok $testid\\n\" )";
110 if ($@)
111 {
112 if (!$test->[1])
113 {
114 print "not ok $testid\n";
115 }
116 else
117 {
118 print "ok $testid\n";
119 }
120 }
121 ++$testid;
122}
123
124exit 0;