Integrate perlio:
[p5sagit/p5-mst-13.2.git] / t / lib / lc-all.t
1 #!./perl
2 #
3 # all.t - tests for all_* routines in
4 #       Locale::Country
5 #       Locale::Language
6 #       Locale::Currency
7 #
8 # There are four tests. We get a list of all codes, convert to
9 # language/country/currency, # convert back to code,
10 # and check that they're the same. Then we do the same,
11 # starting with list of languages/countries/currencies.
12 #
13
14 use Locale::Country;
15 use Locale::Language;
16 use Locale::Currency;
17
18 print "1..12\n";
19
20 my $code;
21 my $language;
22 my $country;
23 my $ok;
24 my $reverse;
25 my $currency;
26
27
28 #-----------------------------------------------------------------------
29 # Old API - without codeset specified, default to ALPHA_2
30 #-----------------------------------------------------------------------
31 $ok = 1;
32 foreach $code (all_country_codes())
33 {
34     $country = code2country($code);
35     if (!defined $country)
36     {
37         $ok = 0;
38         last;
39     }
40     $reverse = country2code($country);
41     if (!defined $reverse)
42     {
43         $ok = 0;
44         last;
45     }
46     if ($reverse ne $code)
47     {
48         $ok = 0;
49         last;
50     }
51 }
52 print ($ok ? "ok 1\n" : "not ok 1\n");
53
54 #-----------------------------------------------------------------------
55 # code to country, back to code, for ALPHA2
56 #-----------------------------------------------------------------------
57 $ok = 1;
58 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_2))
59 {
60     $country = code2country($code, LOCALE_CODE_ALPHA_2);
61     if (!defined $country)
62     {
63         $ok = 0;
64         last;
65     }
66     $reverse = country2code($country, LOCALE_CODE_ALPHA_2);
67     if (!defined $reverse)
68     {
69         $ok = 0;
70         last;
71     }
72     if ($reverse ne $code)
73     {
74         $ok = 0;
75         last;
76     }
77 }
78 print ($ok ? "ok 2\n" : "not ok 2\n");
79
80 #-----------------------------------------------------------------------
81 # code to country, back to code, for ALPHA3
82 #-----------------------------------------------------------------------
83 $ok = 1;
84 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_3))
85 {
86     $country = code2country($code, LOCALE_CODE_ALPHA_3);
87     if (!defined $country)
88     {
89         $ok = 0;
90         last;
91     }
92     $reverse = country2code($country, LOCALE_CODE_ALPHA_3);
93     if (!defined $reverse)
94     {
95         $ok = 0;
96         last;
97     }
98     if ($reverse ne $code)
99     {
100         $ok = 0;
101         last;
102     }
103 }
104 print ($ok ? "ok 3\n" : "not ok 3\n");
105
106 #-----------------------------------------------------------------------
107 # code to country, back to code, for NUMERIC
108 #-----------------------------------------------------------------------
109 $ok = 1;
110 foreach $code (all_country_codes(LOCALE_CODE_NUMERIC))
111 {
112     $country = code2country($code, LOCALE_CODE_NUMERIC);
113     if (!defined $country)
114     {
115         $ok = 0;
116         last;
117     }
118     $reverse = country2code($country, LOCALE_CODE_NUMERIC);
119     if (!defined $reverse)
120     {
121         $ok = 0;
122         last;
123     }
124     if ($reverse ne $code)
125     {
126         $ok = 0;
127         last;
128     }
129 }
130 print ($ok ? "ok 4\n" : "not ok 4\n");
131
132
133 #-----------------------------------------------------------------------
134 # Old API - country to code, back to country, using default of ALPHA_2
135 #-----------------------------------------------------------------------
136 $ok = 1;
137 foreach $country (all_country_names())
138 {
139     $code = country2code($country);
140     if (!defined $code)
141     {
142         $ok = 0;
143         last;
144     }
145     $reverse = code2country($code);
146     if (!defined $reverse)
147     {
148         $ok = 0;
149         last;
150     }
151     if ($reverse ne $country)
152     {
153         $ok = 0;
154         last;
155     }
156 }
157 print ($ok ? "ok 5\n" : "not ok 5\n");
158
159 #-----------------------------------------------------------------------
160 # country to code, back to country, using LOCALE_CODE_ALPHA_2
161 #-----------------------------------------------------------------------
162 $ok = 1;
163 foreach $country (all_country_names())
164 {
165     $code = country2code($country, LOCALE_CODE_ALPHA_2);
166     if (!defined $code)
167     {
168         $ok = 0;
169         last;
170     }
171     $reverse = code2country($code, LOCALE_CODE_ALPHA_2);
172     if (!defined $reverse)
173     {
174         $ok = 0;
175         last;
176     }
177     if ($reverse ne $country)
178     {
179         $ok = 0;
180         last;
181     }
182 }
183 print ($ok ? "ok 6\n" : "not ok 6\n");
184
185 #-----------------------------------------------------------------------
186 # country to code, back to country, using LOCALE_CODE_ALPHA_3
187 #-----------------------------------------------------------------------
188 $ok = 1;
189 foreach $country (all_country_names())
190 {
191     $code = country2code($country, LOCALE_CODE_ALPHA_3);
192     if (!defined $code)
193     {
194         next if ($country eq 'Antarctica'
195                  || $country eq 'Bouvet Island'
196                  || $country eq 'Cocos (Keeling) Islands'
197                  || $country eq 'Christmas Island'
198                  || $country eq 'France, Metropolitan'
199                  || $country eq 'South Georgia and the South Sandwich Islands'
200                  || $country eq 'Heard Island and McDonald Islands'
201                  || $country eq 'British Indian Ocean Territory'
202                  || $country eq 'French Southern Territories'
203                  || $country eq 'United States Minor Outlying Islands'
204                  || $country eq 'Mayotte'
205                  || $country eq 'Zaire');
206         $ok = 0;
207         last;
208     }
209     $reverse = code2country($code, LOCALE_CODE_ALPHA_3);
210     if (!defined $reverse)
211     {
212         $ok = 0;
213         last;
214     }
215     if ($reverse ne $country)
216     {
217         $ok = 0;
218         last;
219     }
220 }
221 print ($ok ? "ok 7\n" : "not ok 7\n");
222
223 #-----------------------------------------------------------------------
224 # country to code, back to country, using LOCALE_CODE_NUMERIC
225 #-----------------------------------------------------------------------
226 $ok = 1;
227 foreach $country (all_country_names())
228 {
229     $code = country2code($country, LOCALE_CODE_NUMERIC);
230     if (!defined $code)
231     {
232         next if ($country eq 'Antarctica'
233                  || $country eq 'Bouvet Island'
234                  || $country eq 'Cocos (Keeling) Islands'
235                  || $country eq 'Christmas Island'
236                  || $country eq 'France, Metropolitan'
237                  || $country eq 'South Georgia and the South Sandwich Islands'
238                  || $country eq 'Heard Island and McDonald Islands'
239                  || $country eq 'British Indian Ocean Territory'
240                  || $country eq 'French Southern Territories'
241                  || $country eq 'United States Minor Outlying Islands'
242                  || $country eq 'Mayotte'
243                  || $country eq 'Zaire');
244         $ok = 0;
245         last;
246     }
247     $reverse = code2country($code, LOCALE_CODE_NUMERIC);
248     if (!defined $reverse)
249     {
250         $ok = 0;
251         last;
252     }
253     if ($reverse ne $country)
254     {
255         $ok = 0;
256         last;
257     }
258 }
259 print ($ok ? "ok 8\n" : "not ok 8\n");
260
261
262 $ok = 1;
263 foreach $code (all_language_codes())
264 {
265     $language = code2language($code);
266     if (!defined $language)
267     {
268         $ok = 0;
269         last;
270     }
271     $reverse = language2code($language);
272     if (!defined $reverse)
273     {
274         $ok = 0;
275         last;
276     }
277     if ($reverse ne $code)
278     {
279         $ok = 0;
280         last;
281     }
282 }
283 print ($ok ? "ok 9\n" : "not ok 9\n");
284
285
286 $ok = 1;
287 foreach $language (all_language_names())
288 {
289     $code = language2code($language);
290     if (!defined $code)
291     {
292         $ok = 0;
293         last;
294     }
295     $reverse = code2language($code);
296     if (!defined $reverse)
297     {
298         $ok = 0;
299         last;
300     }
301     if ($reverse ne $language)
302     {
303         $ok = 0;
304         last;
305     }
306 }
307 print ($ok ? "ok 10\n" : "not ok 10\n");
308
309 $ok = 1;
310 foreach $code (all_currency_codes())
311 {
312     $currency = code2currency($code);
313     if (!defined $currency)
314     {
315         $ok = 0;
316         last;
317     }
318     $reverse = currency2code($currency);
319     if (!defined $reverse)
320     {
321         $ok = 0;
322         last;
323     }
324     #
325     # three special cases:
326     #   The Kwacha has two codes - used in Zambia and Malawi
327     #   The Russian Ruble has two codes - rub and rur
328     #   The Belarussian Ruble has two codes - byb and byr
329     if ($reverse ne $code
330         && $code ne 'mwk' && $code ne 'zmk'
331         && $code ne 'byr' && $code ne 'byb'
332         && $code ne 'rub' && $code ne 'rur')
333     {
334         $ok = 0;
335         last;
336     }
337 }
338 print ($ok ? "ok 11\n" : "not ok 11\n");
339
340 $ok = 1;
341 foreach $currency (all_currency_names())
342 {
343     $code = currency2code($currency);
344     if (!defined $code)
345     {
346         $ok = 0;
347         last;
348     }
349     $reverse = code2currency($code);
350     if (!defined $reverse)
351     {
352         $ok = 0;
353         last;
354     }
355     if ($reverse ne $currency)
356     {
357         $ok = 0;
358         last;
359     }
360 }
361 print ($ok ? "ok 12\n" : "not ok 12\n");