This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Synch cpan/version/* and other files with CPAN version 0.9921.
[perl5.git] / cpan / version / t / 07locale.t
1 #! /usr/local/perl -w
2 # Before `make install' is performed this script should be runnable with
3 # `make test'. After `make install' it should work as `perl test.pl'
4
5 #########################
6
7 use File::Basename;
8 use File::Temp qw/tempfile/;
9 use POSIX qw/locale_h/;
10 use Test::More tests => 8;
11 use Config;
12
13 BEGIN {
14     use_ok('version', 0.9921);
15 }
16
17 SKIP: {
18         skip 'No locale testing for Perl < 5.6.0', 6 if $] < 5.006;
19         skip 'No locale testing without d_setlocale', 6
20             if(!$Config{d_setlocale});
21
22         # test locale handling
23         my $warning = '';
24
25         local $SIG{__WARN__} = sub { $warning = $_[0] };
26
27         my $ver = 1.23;  # has to be floating point number
28         my $loc;
29         my $orig_loc = setlocale(LC_NUMERIC);
30         ok ($ver eq "1.23", 'Not using locale yet');  # Don't use is(),
31                                                       # because have to
32                                                       # evaluate in current
33                                                       # scope
34         use if $^O !~ /android/, 'locale';
35
36         while (<DATA>) {
37             chomp;
38             $loc = setlocale( LC_ALL, $_);
39             last if $loc && localeconv()->{decimal_point} eq ',';
40         }
41         skip 'Cannot test locale handling without a comma locale', 6
42             unless $loc and localeconv()->{decimal_point} eq ',';
43
44         setlocale(LC_NUMERIC, $loc);
45         $ver = 1.23;  # has to be floating point number
46         ok ($ver eq "1,23", "Using locale: $loc");
47         $v = version->new($ver);
48         unlike($warning, qr/Version string '1,23' contains invalid data/,
49             "Process locale-dependent floating point");
50         ok ($v eq "1.23", "Locale doesn't apply to version objects");
51         ok ($v == $ver, "Comparison to locale floating point");
52
53         TODO: { # Resolve https://rt.cpan.org/Ticket/Display.html?id=102272
54             local $TODO = 'Fails for Perl 5.x.0 < 5.19.0' if $] < 5.019000;
55             $ver = version->new($]);
56             is "$ver", "$]", 'Use PV for dualvars';
57         }
58         setlocale( LC_ALL, $orig_loc); # reset this before possible skip
59         skip 'Cannot test RT#46921 with Perl < 5.008', 1
60             if ($] < 5.008);
61         my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
62         (my $package = basename($filename)) =~ s/\.pm$//;
63         print $fh <<"EOF";
64 package $package;
65 use locale;
66 use POSIX qw(locale_h);
67 \$^W = 1;
68 use version;
69 setlocale (LC_ALL, '$loc');
70 use version ;
71 eval "use Socket 1.7";
72 setlocale( LC_ALL, '$orig_loc');
73 1;
74 EOF
75         close $fh;
76
77         eval "use lib '.'; use $package;";
78         unlike($warning, qr"Version string '1,7' contains invalid data",
79             'Handle locale action-at-a-distance');
80     }
81
82 __DATA__
83 af_ZA
84 af_ZA.utf8
85 af_ZA.UTF-8
86 an_ES
87 an_ES.utf8
88 an_ES.UTF-8
89 az_AZ.utf8
90 az_AZ.UTF-8
91 be_BY
92 be_BY.utf8
93 be_BY.UTF-8
94 bg_BG
95 bg_BG.utf8
96 bg_BG.UTF-8
97 br_FR
98 br_FR@euro
99 br_FR.utf8
100 br_FR.UTF-8
101 bs_BA
102 bs_BA.utf8
103 bs_BA.UTF-8
104 ca_ES
105 ca_ES@euro
106 ca_ES.utf8
107 ca_ES.UTF-8
108 cs_CZ
109 cs_CZ.utf8
110 cs_CZ.UTF-8
111 da_DK
112 da_DK.utf8
113 da_DK.UTF-8
114 de_AT
115 de_AT@euro
116 de_AT.utf8
117 de_AT.UTF-8
118 de_BE
119 de_BE@euro
120 de_BE.utf8
121 de_BE.UTF-8
122 de_DE
123 de_DE@euro
124 de_DE.utf8
125 de_DE.UTF-8
126 de_DE.UTF-8
127 de_LU
128 de_LU@euro
129 de_LU.utf8
130 de_LU.UTF-8
131 el_GR
132 el_GR.utf8
133 el_GR.UTF-8
134 en_DK
135 en_DK.utf8
136 en_DK.UTF-8
137 es_AR
138 es_AR.utf8
139 es_AR.UTF-8
140 es_BO
141 es_BO.utf8
142 es_BO.UTF-8
143 es_CL
144 es_CL.utf8
145 es_CL.UTF-8
146 es_CO
147 es_CO.utf8
148 es_CO.UTF-8
149 es_EC
150 es_EC.utf8
151 es_EC.UTF-8
152 es_ES
153 es_ES@euro
154 es_ES.utf8
155 es_ES.UTF-8
156 es_PY
157 es_PY.utf8
158 es_PY.UTF-8
159 es_UY
160 es_UY.utf8
161 es_UY.UTF-8
162 es_VE
163 es_VE.utf8
164 es_VE.UTF-8
165 et_EE
166 et_EE.iso885915
167 et_EE.utf8
168 et_EE.UTF-8
169 eu_ES
170 eu_ES@euro
171 eu_ES.utf8
172 eu_ES.UTF-8
173 fi_FI
174 fi_FI@euro
175 fi_FI.utf8
176 fi_FI.UTF-8
177 fo_FO
178 fo_FO.utf8
179 fo_FO.UTF-8
180 fr_BE
181 fr_BE@euro
182 fr_BE.utf8
183 fr_BE.UTF-8
184 fr_CA
185 fr_CA.utf8
186 fr_CA.UTF-8
187 fr_CH
188 fr_CH.utf8
189 fr_CH.UTF-8
190 fr_FR
191 fr_FR@euro
192 fr_FR.utf8
193 fr_FR.UTF-8
194 fr_LU
195 fr_LU@euro
196 fr_LU.utf8
197 fr_LU.UTF-8
198 gl_ES
199 gl_ES@euro
200 gl_ES.utf8
201 gl_ES.UTF-8
202 hr_HR
203 hr_HR.utf8
204 hr_HR.UTF-8
205 hu_HU
206 hu_HU.utf8
207 hu_HU.UTF-8
208 id_ID
209 id_ID.utf8
210 id_ID.UTF-8
211 is_IS
212 is_IS.utf8
213 is_IS.UTF-8
214 it_CH
215 it_CH.utf8
216 it_CH.UTF-8
217 it_IT
218 it_IT@euro
219 it_IT.utf8
220 it_IT.UTF-8
221 ka_GE
222 ka_GE.utf8
223 ka_GE.UTF-8
224 kk_KZ
225 kk_KZ.utf8
226 kk_KZ.UTF-8
227 kl_GL
228 kl_GL.utf8
229 kl_GL.UTF-8
230 lt_LT
231 lt_LT.utf8
232 lt_LT.UTF-8
233 lv_LV
234 lv_LV.utf8
235 lv_LV.UTF-8
236 mk_MK
237 mk_MK.utf8
238 mk_MK.UTF-8
239 mn_MN
240 mn_MN.utf8
241 mn_MN.UTF-8
242 nb_NO
243 nb_NO.utf8
244 nb_NO.UTF-8
245 nl_BE
246 nl_BE@euro
247 nl_BE.utf8
248 nl_BE.UTF-8
249 nl_NL
250 nl_NL@euro
251 nl_NL.utf8
252 nl_NL.UTF-8
253 nn_NO
254 nn_NO.utf8
255 nn_NO.UTF-8
256 no_NO
257 no_NO.utf8
258 no_NO.UTF-8
259 oc_FR
260 oc_FR.utf8
261 oc_FR.UTF-8
262 pl_PL
263 pl_PL.utf8
264 pl_PL.UTF-8
265 pt_BR
266 pt_BR.utf8
267 pt_BR.UTF-8
268 pt_PT
269 pt_PT@euro
270 pt_PT.utf8
271 pt_PT.UTF-8
272 ro_RO
273 ro_RO.utf8
274 ro_RO.UTF-8
275 ru_RU
276 ru_RU.koi8r
277 ru_RU.utf8
278 ru_RU.UTF-8
279 ru_UA
280 ru_UA.utf8
281 ru_UA.UTF-8
282 se_NO
283 se_NO.utf8
284 se_NO.UTF-8
285 sh_YU
286 sh_YU.utf8
287 sh_YU.UTF-8
288 sk_SK
289 sk_SK.utf8
290 sk_SK.UTF-8
291 sl_SI
292 sl_SI.utf8
293 sl_SI.UTF-8
294 sq_AL
295 sq_AL.utf8
296 sq_AL.UTF-8
297 sr_CS
298 sr_CS.utf8
299 sr_CS.UTF-8
300 sv_FI
301 sv_FI@euro
302 sv_FI.utf8
303 sv_FI.UTF-8
304 sv_SE
305 sv_SE.iso885915
306 sv_SE.utf8
307 sv_SE.UTF-8
308 tg_TJ
309 tg_TJ.utf8
310 tg_TJ.UTF-8
311 tr_TR
312 tr_TR.utf8
313 tr_TR.UTF-8
314 tt_RU.utf8
315 tt_RU.UTF-8
316 uk_UA
317 uk_UA.utf8
318 uk_UA.UTF-8
319 vi_VN
320 vi_VN.tcvn
321 wa_BE
322 wa_BE@euro
323 wa_BE.utf8
324 wa_BE.UTF-8