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