Commit | Line | Data |
---|---|---|
f768f60b S |
1 | #!/usr/bin/perl -w |
2 | ||
3 | require 5.002; | |
4 | ||
5 | $runtests=shift(@ARGV); | |
6 | if ( -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 | 18 | unshift(@INC,$dir); |
c69a30ec | 19 | use 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 | ||
26 | sub 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 | ||
92 | gb | |
93 | ~ | |
94 | United Kingdom | |
95 | ||
96 | rename_country x1 NewName ~ 0 | |
97 | ||
98 | rename_country gb NewName LOCALE_CODE_FOO ~ 0 | |
99 | ||
100 | rename_country gb Macao ~ 0 | |
101 | ||
102 | rename_country gb NewName LOCALE_CODE_ALPHA_3 ~ 0 | |
103 | ||
104 | gb | |
105 | ~ | |
106 | United Kingdom | |
107 | ||
108 | rename_country gb NewName ~ 1 | |
109 | ||
110 | gb | |
111 | ~ | |
112 | NewName | |
113 | ||
d07feb8f SH |
114 | us |
115 | ~ | |
116 | United States | |
117 | ||
118 | rename_country | |
119 | us | |
120 | The United States | |
121 | ~ | |
122 | 1 | |
123 | ||
124 | us | |
125 | ~ | |
126 | The United States | |
127 | ||
f768f60b S |
128 | ################################### |
129 | # Test add_country | |
130 | ||
131 | xx ~ _undef_ | |
132 | ||
133 | add_country xx Bolivia ~ 0 | |
134 | ||
135 | add_country fi Xxxxx ~ 0 | |
136 | ||
137 | add_country xx Xxxxx ~ 1 | |
138 | ||
139 | xx ~ Xxxxx | |
140 | ||
141 | ################################### | |
142 | # Test add_country_alias | |
143 | ||
144 | add_country_alias FooBar NewName ~ 0 | |
145 | ||
146 | add_country_alias Australia Angola ~ 0 | |
147 | ||
148 | country2code Australia ~ au | |
149 | ||
150 | country2code DownUnder ~ _undef_ | |
151 | ||
152 | add_country_alias Australia DownUnder ~ 1 | |
153 | ||
154 | country2code DownUnder ~ au | |
155 | ||
156 | ################################### | |
157 | # Test delete_country_alias | |
158 | ||
159 | country2code uk ~ gb | |
160 | ||
161 | delete_country_alias Foobar ~ 0 | |
162 | ||
163 | delete_country_alias UK ~ 1 | |
164 | ||
165 | country2code uk ~ _undef_ | |
166 | ||
167 | delete_country_alias Angola ~ 0 | |
168 | ||
169 | ################################### | |
170 | # Test delete_country | |
171 | ||
172 | country2code Angola ~ ao | |
173 | ||
174 | country2code Angola LOCALE_CODE_ALPHA_3 ~ ago | |
175 | ||
176 | delete_country ao ~ 1 | |
177 | ||
178 | country2code Angola ~ _undef_ | |
179 | ||
180 | country2code Angola LOCALE_CODE_ALPHA_3 ~ ago | |
181 | ||
182 | ################################### | |
183 | # Test rename_country_code | |
184 | ||
185 | code2country zz ~ _undef_ | |
186 | ||
187 | code2country ar ~ Argentina | |
188 | ||
189 | country2code Argentina ~ ar | |
190 | ||
191 | rename_country_code ar us ~ 0 | |
192 | ||
193 | rename_country_code ar zz ~ 1 | |
194 | ||
195 | rename_country_code us ar ~ 0 | |
196 | ||
197 | code2country zz ~ Argentina | |
198 | ||
199 | code2country ar ~ Argentina | |
200 | ||
201 | country2code Argentina ~ zz | |
202 | ||
203 | rename_country_code zz ar ~ 1 | |
204 | ||
205 | code2country zz ~ Argentina | |
206 | ||
207 | code2country ar ~ Argentina | |
208 | ||
209 | country2code Argentina ~ ar | |
210 | ||
211 | ################################### | |
212 | # Test add_country_code_alias and | |
213 | # delete_country_code_alias | |
214 | ||
215 | code2country bm ~ Bermuda | |
216 | ||
217 | code2country yy ~ _undef_ | |
218 | ||
219 | country2code Bermuda ~ bm | |
220 | ||
221 | add_country_code_alias bm us ~ 0 | |
222 | ||
223 | add_country_code_alias bm zz ~ 0 | |
224 | ||
225 | add_country_code_alias bm yy ~ 1 | |
226 | ||
227 | code2country bm ~ Bermuda | |
228 | ||
229 | code2country yy ~ Bermuda | |
230 | ||
231 | country2code Bermuda ~ bm | |
232 | ||
233 | delete_country_code_alias us ~ 0 | |
234 | ||
235 | delete_country_code_alias ww ~ 0 | |
236 | ||
237 | delete_country_code_alias yy ~ 1 | |
238 | ||
239 | code2country bm ~ Bermuda | |
240 | ||
241 | code2country yy ~ _undef_ | |
242 | ||
243 | country2code Bermuda ~ bm | |
244 | ||
245 | "; | |
246 | ||
247 | print "country (semi-private)...\n"; | |
248 | test_Func(\&test,$tests,$runtests); | |
249 | ||
250 | 1; | |
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: |