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