This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move ExtUtils-Command to cpan/
[perl5.git] / cpan / Locale-Codes / t / country.t
CommitLineData
f768f60b
S
1#!/usr/bin/perl -w
2
3require 5.002;
4
5$runtests=shift(@ARGV);
6if ( -f "t/testfunc.pl" ) {
7 require "t/testfunc.pl";
8 $dir="./lib";
9 $tdir="t";
10} elsif ( -f "testfunc.pl" ) {
11 require "testfunc.pl";
12 $dir="../lib";
13 $tdir=".";
14} else {
15 die "ERROR: cannot find testfunc.pl\n";
16}
47a334e9 17
f768f60b 18unshift(@INC,$dir);
c69a30ec 19use Locale::Codes::Country;
47a334e9 20
f768f60b
S
21%type = ( "LOCALE_CODE_ALPHA_2" => LOCALE_CODE_ALPHA_2,
22 "LOCALE_CODE_ALPHA_3" => LOCALE_CODE_ALPHA_3,
23 "LOCALE_CODE_NUMERIC" => LOCALE_CODE_NUMERIC,
f768f60b
S
24 );
25
26sub test {
27 my(@test) = @_;
28
29 if ($test[0] eq "rename_country") {
30 shift(@test);
31 $test[2] = $type{$test[2]}
32 if (@test == 3 && $test[2] && exists $type{$test[2]});
c69a30ec 33 return Locale::Codes::Country::rename_country(@test,"nowarn");
f768f60b
S
34
35 } elsif ($test[0] eq "add_country") {
36 shift(@test);
37 $test[2] = $type{$test[2]}
38 if (@test == 3 && $test[2] && exists $type{$test[2]});
c69a30ec 39 return Locale::Codes::Country::add_country(@test,"nowarn");
f768f60b
S
40
41 } elsif ($test[0] eq "delete_country") {
42 shift(@test);
43 $test[1] = $type{$test[1]}
44 if (@test == 2 && $test[1] && exists $type{$test[1]});
c69a30ec 45 return Locale::Codes::Country::delete_country(@test,"nowarn");
f768f60b
S
46
47 } elsif ($test[0] eq "add_country_alias") {
48 shift(@test);
c69a30ec 49 return Locale::Codes::Country::add_country_alias(@test,"nowarn");
f768f60b
S
50
51 } elsif ($test[0] eq "delete_country_alias") {
52 shift(@test);
c69a30ec 53 return Locale::Codes::Country::delete_country_alias(@test,"nowarn");
f768f60b
S
54
55 } elsif ($test[0] eq "rename_country_code") {
56 shift(@test);
57 $test[2] = $type{$test[2]}
58 if (@test == 3 && $test[2] && exists $type{$test[2]});
c69a30ec 59 return Locale::Codes::Country::rename_country_code(@test,"nowarn");
f768f60b
S
60
61 } elsif ($test[0] eq "add_country_code_alias") {
62 shift(@test);
63 $test[2] = $type{$test[2]}
64 if (@test == 3 && $test[2] && exists $type{$test[2]});
c69a30ec 65 return Locale::Codes::Country::add_country_code_alias(@test,"nowarn");
f768f60b
S
66
67 } elsif ($test[0] eq "delete_country_code_alias") {
68 shift(@test);
69 $test[1] = $type{$test[1]}
70 if (@test == 2 && $test[1] && exists $type{$test[1]});
c69a30ec 71 return Locale::Codes::Country::delete_country_code_alias(@test,"nowarn");
f768f60b
S
72
73 } elsif ($test[0] eq "country2code") {
74 shift(@test);
75 $test[1] = $type{$test[1]}
76 if (@test == 2 && $test[1] && exists $type{$test[1]});
77 return country2code(@test);
78
79 } else {
80 shift(@test) if ($test[0] eq "code2country");
81 $test[1] = $type{$test[1]}
82 if (@test == 2 && $test[1] && exists $type{$test[1]});
83 return code2country(@test);
84 }
47a334e9
JH
85}
86
f768f60b
S
87$tests = "
88
89###################################
90# Test rename_country
91
92gb
93 ~
94 United Kingdom
95
96rename_country x1 NewName ~ 0
97
98rename_country gb NewName LOCALE_CODE_FOO ~ 0
99
100rename_country gb Macao ~ 0
101
102rename_country gb NewName LOCALE_CODE_ALPHA_3 ~ 0
103
104gb
105 ~
106 United Kingdom
107
108rename_country gb NewName ~ 1
109
110gb
111 ~
112 NewName
113
d07feb8f
SH
114us
115 ~
116 United States
117
118rename_country
119us
120The United States
121 ~
122 1
123
124us
125 ~
126 The United States
127
f768f60b
S
128###################################
129# Test add_country
130
131xx ~ _undef_
132
133add_country xx Bolivia ~ 0
134
135add_country fi Xxxxx ~ 0
136
137add_country xx Xxxxx ~ 1
138
139xx ~ Xxxxx
140
141###################################
142# Test add_country_alias
143
144add_country_alias FooBar NewName ~ 0
145
146add_country_alias Australia Angola ~ 0
147
148country2code Australia ~ au
149
150country2code DownUnder ~ _undef_
151
152add_country_alias Australia DownUnder ~ 1
153
154country2code DownUnder ~ au
155
156###################################
157# Test delete_country_alias
158
159country2code uk ~ gb
160
161delete_country_alias Foobar ~ 0
162
163delete_country_alias UK ~ 1
164
165country2code uk ~ _undef_
166
167delete_country_alias Angola ~ 0
168
169###################################
170# Test delete_country
171
172country2code Angola ~ ao
173
174country2code Angola LOCALE_CODE_ALPHA_3 ~ ago
175
176delete_country ao ~ 1
177
178country2code Angola ~ _undef_
179
180country2code Angola LOCALE_CODE_ALPHA_3 ~ ago
181
182###################################
183# Test rename_country_code
184
185code2country zz ~ _undef_
186
187code2country ar ~ Argentina
188
189country2code Argentina ~ ar
190
191rename_country_code ar us ~ 0
192
193rename_country_code ar zz ~ 1
194
195rename_country_code us ar ~ 0
196
197code2country zz ~ Argentina
198
199code2country ar ~ Argentina
200
201country2code Argentina ~ zz
202
203rename_country_code zz ar ~ 1
204
205code2country zz ~ Argentina
206
207code2country ar ~ Argentina
208
209country2code Argentina ~ ar
210
211###################################
212# Test add_country_code_alias and
213# delete_country_code_alias
214
215code2country bm ~ Bermuda
216
217code2country yy ~ _undef_
218
219country2code Bermuda ~ bm
220
221add_country_code_alias bm us ~ 0
222
223add_country_code_alias bm zz ~ 0
224
225add_country_code_alias bm yy ~ 1
226
227code2country bm ~ Bermuda
228
229code2country yy ~ Bermuda
230
231country2code Bermuda ~ bm
232
233delete_country_code_alias us ~ 0
234
235delete_country_code_alias ww ~ 0
236
237delete_country_code_alias yy ~ 1
238
239code2country bm ~ Bermuda
240
241code2country yy ~ _undef_
242
243country2code Bermuda ~ bm
244
245";
246
247print "country (semi-private)...\n";
248test_Func(\&test,$tests,$runtests);
249
2501;
251# Local Variables:
252# mode: cperl
253# indent-tabs-mode: nil
254# cperl-indent-level: 3
255# cperl-continued-statement-offset: 2
256# cperl-continued-brace-offset: 0
257# cperl-brace-offset: 0
258# cperl-brace-imaginary-offset: 0
259# cperl-label-offset: -2
260# End: