Move Archive::Tar from lib/ to ext/
[p5sagit/p5-mst-13.2.git] / lib / Locale / Codes / t / country.t
1 #!./perl
2 #
3 # country.t - tests for Locale::Country
4 #
5
6 use Locale::Country;
7
8 #-----------------------------------------------------------------------
9 # This is an array of tests specs. Each spec is [TEST, OK_TO_DIE]
10 # Each TEST is eval'd as an expression.
11 # If it evaluates to FALSE, then "not ok N" is printed for the test,
12 # otherwise "ok N". If the eval dies, then the OK_TO_DIE flag is checked.
13 # If it is true (1), the test is treated as passing, otherwise it failed.
14 #-----------------------------------------------------------------------
15 @TESTS =
16 (
17         #================================================
18         # TESTS FOR code2country
19         #================================================
20
21  #---- selection of examples which should all result in undef -----------
22  ['!defined code2country()', 0],                  # no argument
23  ['!defined code2country(undef)', 0],             # undef argument
24  ['!defined code2country("zz")', 0],              # illegal code
25  ['!defined code2country("zz", LOCALE_CODE_ALPHA_2)', 0],        # illegal code
26  ['!defined code2country("zz", LOCALE_CODE_ALPHA_3)', 0],        # illegal code
27  ['!defined code2country("zz", LOCALE_CODE_NUMERIC)', 0],        # illegal code
28  ['!defined code2country("ja")', 0],              # should be jp for country
29  ['!defined code2country("uk")', 0],              # should be jp for country
30
31  #---- some successful examples -----------------------------------------
32  ['code2country("BO") eq "Bolivia"', 0],
33  ['code2country("BO", LOCALE_CODE_ALPHA_2) eq "Bolivia"', 0],
34  ['code2country("bol", LOCALE_CODE_ALPHA_3) eq "Bolivia"', 0],
35  ['code2country("pk") eq "Pakistan"', 0],
36  ['code2country("sn") eq "Senegal"', 0],
37  ['code2country("us") eq "United States"', 0],
38  ['code2country("ad") eq "Andorra"', 0],          # first in DATA segment
39  ['code2country("ad", LOCALE_CODE_ALPHA_2) eq "Andorra"', 0],
40  ['code2country("and", LOCALE_CODE_ALPHA_3) eq "Andorra"', 0],
41  ['code2country("020", LOCALE_CODE_NUMERIC) eq "Andorra"', 0],
42  ['code2country(48, LOCALE_CODE_NUMERIC) eq "Bahrain"', 0],
43  ['code2country("zw") eq "Zimbabwe"', 0],         # last in DATA segment
44  ['code2country("gb") eq "United Kingdom"', 0],   # United Kingdom is "gb", not "uk"
45
46  #-- tests added after changes in the standard 2002-05-20 ------
47  ['code2country("kz") eq "Kazakhstan"', 0],
48  ['country2code("kazakhstan")               eq "kz"', 0],
49  ['country2code("kazakstan")                eq "kz"', 0],
50
51  ['code2country("mo") eq "Macao"', 0],
52  ['country2code("macao")                    eq "mo"', 0],
53  ['country2code("macau")                    eq "mo"', 0],
54
55  ['code2country("tl", LOCALE_CODE_ALPHA_2) eq "Timor-Leste"', 0],
56  ['code2country("tls", LOCALE_CODE_ALPHA_3) eq "Timor-Leste"', 0],
57  ['code2country("626", LOCALE_CODE_NUMERIC) eq "Timor-Leste"', 0],
58
59         #================================================
60         # TESTS FOR country2code
61         #================================================
62
63  #---- selection of examples which should all result in undef -----------
64  ['!defined code2country("BO", LOCALE_CODE_ALPHA_3)', 0],
65  ['!defined code2country("BO", LOCALE_CODE_NUMERIC)', 0],
66  ['!defined country2code()', 0],                  # no argument
67  ['!defined country2code(undef)', 0],             # undef argument
68  ['!defined country2code("Banana")', 0],          # illegal country name
69
70  #---- some successful examples -----------------------------------------
71  ['country2code("japan")                    eq "jp"', 0],
72  ['country2code("japan")                    ne "ja"', 0],
73  ['country2code("Japan")                    eq "jp"', 0],
74  ['country2code("United States")            eq "us"', 0],
75  ['country2code("United Kingdom")           eq "gb"', 0],
76  ['country2code("Andorra")                  eq "ad"', 0],    # first in DATA
77  ['country2code("Zimbabwe")                 eq "zw"', 0],    # last in DATA
78  ['country2code("Iran")                     eq "ir"', 0],    # alias
79  ['country2code("North Korea")              eq "kp"', 0],    # alias
80  ['country2code("South Korea")              eq "kr"', 0],    # alias
81  ['country2code("Libya")                    eq "ly"', 0],    # alias
82  ['country2code("Syria")                    eq "sy"', 0],    # alias
83  ['country2code("Svalbard")                 eq "sj"', 0],    # alias
84  ['country2code("Jan Mayen")                eq "sj"', 0],    # alias
85  ['country2code("USA")                      eq "us"', 0],    # alias
86  ['country2code("United States of America") eq "us"', 0],    # alias
87  ['country2code("Great Britain")                        eq "gb"', 0],    # alias
88
89         #================================================
90         # TESTS FOR country_code2code
91         #================================================
92
93  #---- selection of examples which should all result in undef -----------
94  ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
95  ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3)', 0],
96  ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
97  ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2)', 1],
98  ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_2)', 1],
99  ['!defined country_code2code()', 1],                  # no argument
100  ['!defined country_code2code(undef)', 1],             # undef argument
101
102  #---- some successful examples -----------------------------------------
103  ['country_code2code("BO", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3) eq "bol"', 0],
104  ['country_code2code("bol", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "bo"', 0],
105  ['country_code2code("zwe", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "zw"', 0],
106  ['country_code2code("858", LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0],
107  ['country_code2code(858, LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0],
108  ['country_code2code("tr", LOCALE_CODE_ALPHA_2, LOCALE_CODE_NUMERIC) eq "792"', 0],
109
110  #-- tests added for 2.07 release
111  ['country2code("Burma")                                eq "mm"', 0],    # alias
112  ['country2code("French Southern and Antarctic Lands")  eq "tf"', 0],    # alias
113  ['code2country("ax") eq "Aland Islands"', 0],
114  ['country2code("Aland Islands")                        eq "ax"', 0],
115  ['code2country("ala", LOCALE_CODE_ALPHA_3) eq "Aland Islands"', 0],
116  ['code2country("248", LOCALE_CODE_NUMERIC) eq "Aland Islands"', 0],
117
118  ['country2code("Yugoslavia")                           eq "cs"', 0],   # alias (old name)
119  ['country2code("Serbia and Montenegro")                eq "cs"', 0],   # new name
120  ['code2country("scg", LOCALE_CODE_ALPHA_3) eq "Serbia and Montenegro"', 0],
121  ['code2country("891", LOCALE_CODE_NUMERIC) eq "Serbia and Montenegro"', 0],
122
123  ['country2code("East Timor")                           eq "tl"', 0],   # alias (provisional name)
124  ['code2country("rou", LOCALE_CODE_ALPHA_3) eq "Romania"', 0],
125
126  ['country2code("Zaire")                                eq "cd"', 0],   # alias (old name)
127  ['country2code("Congo, The Democratic Republic of the")        eq "cd"', 0],   # new name
128  ['country2code("Congo, The Democratic Republic of the", LOCALE_CODE_ALPHA_3)   eq "cod"', 0],  # new name
129  ['country2code("Congo, The Democratic Republic of the", LOCALE_CODE_NUMERIC)   eq "180"', 0],  # new name
130
131 );
132
133 print "1..", int(@TESTS), "\n";
134
135 $testid = 1;
136 foreach $test (@TESTS)
137 {
138     eval "print (($test->[0]) ? \"ok $testid\\n\" : \"not ok $testid\\n\" )";
139     if ($@)
140     {
141         if (!$test->[1])
142         {
143             print "not ok $testid\n";
144         }
145         else
146         {
147             print "ok $testid\n";
148         }
149     }
150     ++$testid;
151 }
152
153 exit 0;