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