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