This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.c: White-space changes only
[perl5.git] / lib / locale.t
CommitLineData
8ebc5c01
PP
1#!./perl -wT
2
e3a2734b
KW
3binmode STDOUT, ':utf8';
4binmode STDERR, ':utf8';
5
8ebc5c01
PP
6BEGIN {
7 chdir 't' if -d 't';
20822f61 8 @INC = '../lib';
f9cbebe1 9 unshift @INC, '.';
b002077a 10 require Config; import Config;
97a0514d 11 if (!$Config{d_setlocale} || $Config{ccflags} =~ /\bD?NO_LOCALE\b/) {
b002077a
CS
12 print "1..0\n";
13 exit;
14 }
2de3dbcc 15 $| = 1;
8ebc5c01
PP
16}
17
18use strict;
19
284102e8
JH
20my $debug = 1;
21
db4b7445
A
22use Dumpvalue;
23
24my $dumper = Dumpvalue->new(
25 tick => qq{"},
26 quoteHighBit => 0,
27 unctrl => "quote"
28 );
6be75cd7 29sub debug {
db4b7445
A
30 return unless $debug;
31 my($mess) = join "", @_;
32 chop $mess;
33 print $dumper->stringify($mess,1), "\n";
6be75cd7
JH
34}
35
36sub debugf {
37 printf @_ if $debug;
38}
39
8ebc5c01
PP
40my $have_setlocale = 0;
41eval {
42 require POSIX;
43 import POSIX ':locale_h';
44 $have_setlocale++;
45};
46
6dead956 47# Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
f6c6487a 48# and mingw32 uses said silly CRT
3a2d1764
SH
49# This doesn't seem to be an issue any more, at least on Windows XP,
50# so re-enable the tests for Windows XP onwards.
51my $winxp = ($^O eq 'MSWin32' && defined &Win32::GetOSVersion &&
52 join('.', (Win32::GetOSVersion())[1..2]) >= 5.1);
53$have_setlocale = 0 if ((($^O eq 'MSWin32' && !$winxp) || $^O eq 'NetWare') &&
54 $Config{cc} =~ /^(cl|gcc)/i);
6dead956 55
cd19b65c
JH
56# UWIN seems to loop after test 98, just skip for now
57$have_setlocale = 0 if ($^O =~ /^uwin/);
58
98daf176 59my $last_locales = $have_setlocale ? &last_locales : &last_without_setlocale;
906f284f 60my $last = $have_setlocale ? &last : &last_without_setlocale;
26d80d95
LC
61
62print "1..$last\n";
8ebc5c01 63
9a66ea41 64sub LC_ALL ();
8ebc5c01 65
0e053d1e 66$a = 'abc %';
8ebc5c01
PP
67
68sub ok {
e3a2734b
KW
69 my ($n, $result, $message) = @_;
70 $message = "" unless defined $message;
8ebc5c01
PP
71
72 print 'not ' unless ($result);
e3a2734b
KW
73 print "ok $n";
74 print " $message";
75 print "\n";
8ebc5c01
PP
76}
77
78# First we'll do a lot of taint checking for locales.
79# This is the easiest to test, actually, as any locale,
80# even the default locale will taint under 'use locale'.
81
82sub is_tainted { # hello, camel two.
9f1b1f2d 83 no warnings 'uninitialized' ;
8ebc5c01 84 my $dummy;
ba74571d 85 local $@;
8ebc5c01
PP
86 not eval { $dummy = join("", @_), kill 0; 1 }
87}
88
89sub check_taint ($$) {
e3a2734b 90 ok $_[0], is_tainted($_[1]), "verify that is tainted";
8ebc5c01
PP
91}
92
93sub check_taint_not ($$) {
e3a2734b 94 ok $_[0], (not is_tainted($_[1])), "verify that isn't tainted";
8ebc5c01
PP
95}
96
97use locale; # engage locale and therefore locale taint.
98
99check_taint_not 1, $a;
100
101check_taint 2, uc($a);
102check_taint 3, "\U$a";
103check_taint 4, ucfirst($a);
104check_taint 5, "\u$a";
105check_taint 6, lc($a);
106check_taint 7, "\L$a";
107check_taint 8, lcfirst($a);
108check_taint 9, "\l$a";
109
ff9121f8
JH
110check_taint_not 10, sprintf('%e', 123.456);
111check_taint_not 11, sprintf('%f', 123.456);
112check_taint_not 12, sprintf('%g', 123.456);
8ebc5c01
PP
113check_taint_not 13, sprintf('%d', 123.456);
114check_taint_not 14, sprintf('%x', 123.456);
115
116$_ = $a; # untaint $_
117
118$_ = uc($a); # taint $_
119
120check_taint 15, $_;
121
122/(\w)/; # taint $&, $`, $', $+, $1.
123check_taint 16, $&;
124check_taint 17, $`;
125check_taint 18, $';
126check_taint 19, $+;
127check_taint 20, $1;
128check_taint_not 21, $2;
129
130/(.)/; # untaint $&, $`, $', $+, $1.
131check_taint_not 22, $&;
132check_taint_not 23, $`;
133check_taint_not 24, $';
134check_taint_not 25, $+;
135check_taint_not 26, $1;
136check_taint_not 27, $2;
137
138/(\W)/; # taint $&, $`, $', $+, $1.
139check_taint 28, $&;
140check_taint 29, $`;
141check_taint 30, $';
142check_taint 31, $+;
143check_taint 32, $1;
144check_taint_not 33, $2;
145
146/(\s)/; # taint $&, $`, $', $+, $1.
147check_taint 34, $&;
148check_taint 35, $`;
149check_taint 36, $';
150check_taint 37, $+;
151check_taint 38, $1;
152check_taint_not 39, $2;
153
154/(\S)/; # taint $&, $`, $', $+, $1.
155check_taint 40, $&;
156check_taint 41, $`;
157check_taint 42, $';
158check_taint 43, $+;
159check_taint 44, $1;
160check_taint_not 45, $2;
161
162$_ = $a; # untaint $_
163
164check_taint_not 46, $_;
165
166/(b)/; # this must not taint
167check_taint_not 47, $&;
168check_taint_not 48, $`;
169check_taint_not 49, $';
170check_taint_not 50, $+;
171check_taint_not 51, $1;
172check_taint_not 52, $2;
173
174$_ = $a; # untaint $_
175
176check_taint_not 53, $_;
177
178$b = uc($a); # taint $b
179s/(.+)/$b/; # this must taint only the $_
180
181check_taint 54, $_;
182check_taint_not 55, $&;
183check_taint_not 56, $`;
184check_taint_not 57, $';
185check_taint_not 58, $+;
186check_taint_not 59, $1;
187check_taint_not 60, $2;
188
189$_ = $a; # untaint $_
190
191s/(.+)/b/; # this must not taint
192check_taint_not 61, $_;
193check_taint_not 62, $&;
194check_taint_not 63, $`;
195check_taint_not 64, $';
196check_taint_not 65, $+;
197check_taint_not 66, $1;
198check_taint_not 67, $2;
199
200$b = $a; # untaint $b
201
202($b = $a) =~ s/\w/$&/;
203check_taint 68, $b; # $b should be tainted.
204check_taint_not 69, $a; # $a should be not.
205
206$_ = $a; # untaint $_
207
208s/(\w)/\l$1/; # this must taint
209check_taint 70, $_;
210check_taint 71, $&;
211check_taint 72, $`;
212check_taint 73, $';
213check_taint 74, $+;
214check_taint 75, $1;
215check_taint_not 76, $2;
216
217$_ = $a; # untaint $_
218
219s/(\w)/\L$1/; # this must taint
220check_taint 77, $_;
221check_taint 78, $&;
222check_taint 79, $`;
223check_taint 80, $';
224check_taint 81, $+;
225check_taint 82, $1;
226check_taint_not 83, $2;
227
228$_ = $a; # untaint $_
229
230s/(\w)/\u$1/; # this must taint
231check_taint 84, $_;
232check_taint 85, $&;
233check_taint 86, $`;
234check_taint 87, $';
235check_taint 88, $+;
236check_taint 89, $1;
237check_taint_not 90, $2;
238
239$_ = $a; # untaint $_
240
241s/(\w)/\U$1/; # this must taint
242check_taint 91, $_;
243check_taint 92, $&;
244check_taint 93, $`;
245check_taint 94, $';
246check_taint 95, $+;
247check_taint 96, $1;
248check_taint_not 97, $2;
249
250# After all this tainting $a should be cool.
251
252check_taint_not 98, $a;
253
906f284f
NC
254sub last_without_setlocale { 98 }
255
8ebc5c01
PP
256# I think we've seen quite enough of taint.
257# Let us do some *real* locale work now,
284102e8 258# unless setlocale() is missing (i.e. minitest).
8ebc5c01
PP
259
260exit unless $have_setlocale;
261
284102e8
JH
262# Find locales.
263
6be75cd7
JH
264debug "# Scanning for locales...\n";
265
266# Note that it's okay that some languages have their native names
267# capitalized here even though that's not "right". They are lowercased
268# anyway later during the scanning process (and besides, some clueless
98dc9551 269# vendor might have them capitalized erroneously anyway).
6be75cd7 270
284102e8 271my $locales = <<EOF;
6be75cd7 272Afrikaans:af:za:1 15
284102e8 273Arabic:ar:dz eg sa:6 arabic8
6be75cd7
JH
274Brezhoneg Breton:br:fr:1 15
275Bulgarski Bulgarian:bg:bg:5
dd8482fc 276Chinese:zh:cn tw:cn.EUC eucCN eucTW euc.CN euc.TW Big5 GB2312 tw.EUC
6be75cd7
JH
277Hrvatski Croatian:hr:hr:2
278Cymraeg Welsh:cy:cy:1 14 15
284102e8 279Czech:cs:cz:2
6be75cd7
JH
280Dansk Danish:dk:da:1 15
281Nederlands Dutch:nl:be nl:1 15
dd8482fc 282English American British:en:au ca gb ie nz us uk zw:1 15 cp850
6be75cd7
JH
283Esperanto:eo:eo:3
284Eesti Estonian:et:ee:4 6 13
285Suomi Finnish:fi:fi:1 15
286Flamish::fl:1 15
6be75cd7
JH
287Deutsch German:de:at be ch de lu:1 15
288Euskaraz Basque:eu:es fr:1 15
6be75cd7
JH
289Galego Galician:gl:es:1 15
290Ellada Greek:el:gr:7 g8
6be75cd7
JH
291Frysk:fy:nl:1 15
292Greenlandic:kl:gl:4 6
284102e8
JH
293Hebrew:iw:il:8 hebrew8
294Hungarian:hu:hu:2
6be75cd7
JH
295Indonesian:in:id:1 15
296Gaeilge Irish:ga:IE:1 14 15
297Italiano Italian:it:ch it:1 15
298Nihongo Japanese:ja:jp:euc eucJP jp.EUC sjis
284102e8 299Korean:ko:kr:
6be75cd7
JH
300Latine Latin:la:va:1 15
301Latvian:lv:lv:4 6 13
302Lithuanian:lt:lt:4 6 13
303Macedonian:mk:mk:1 15
304Maltese:mt:mt:3
dd8482fc
JH
305Moldovan:mo:mo:2
306Norsk Norwegian:no no\@nynorsk:no:1 15
6be75cd7
JH
307Occitan:oc:es:1 15
308Polski Polish:pl:pl:2
284102e8 309Rumanian:ro:ro:2
a528dad0 310Russki Russian:ru:ru su ua:5 koi8 koi8r KOI8-R koi8u cp1251 cp866
6be75cd7 311Serbski Serbian:sr:yu:5
284102e8 312Slovak:sk:sk:2
6be75cd7 313Slovene Slovenian:sl:si:2
d43ce814
JH
314Sqhip Albanian:sq:sq:1 15
315Svenska Swedish:sv:fi se:1 15
6be75cd7 316Thai:th:th:11 tis620
284102e8 317Turkish:tr:tr:9 turkish8
dd8482fc 318Yiddish:yi::1 15
284102e8
JH
319EOF
320
ee50adbe 321if ($^O eq 'os390') {
dd8482fc 322 # These cause heartburn. Broken locales?
ee50adbe
PP
323 $locales =~ s/Svenska Swedish:sv:fi se:1 15\n//;
324 $locales =~ s/Thai:th:th:11 tis620\n//;
325}
326
ef4a39e5 327sub in_utf8 () { $^H & 0x08 || (${^OPEN} || "") =~ /:utf8/ }
f9cbebe1
JH
328
329if (in_utf8) {
8a6cb2cb 330 require "lib/locale/utf8";
f9cbebe1 331} else {
8a6cb2cb 332 require "lib/locale/latin1";
f9cbebe1
JH
333}
334
284102e8
JH
335my @Locale;
336my $Locale;
337my @Alnum_;
338
0e053d1e
JH
339my @utf8locale;
340my %utf8skip;
341
284102e8 342sub getalnum_ {
8ebc5c01
PP
343 sort grep /\w/, map { chr } 0..255
344}
345
284102e8
JH
346sub trylocale {
347 my $locale = shift;
348 if (setlocale(LC_ALL, $locale)) {
349 push @Locale, $locale;
350 }
351}
8ebc5c01 352
284102e8
JH
353sub decode_encodings {
354 my @enc;
8ebc5c01 355
284102e8
JH
356 foreach (split(/ /, shift)) {
357 if (/^(\d+)$/) {
358 push @enc, "ISO8859-$1";
359 push @enc, "iso8859$1"; # HP
360 if ($1 eq '1') {
361 push @enc, "roman8"; # HP
362 }
363 } else {
364 push @enc, $_;
dd8482fc 365 push @enc, "$_.UTF-8";
8ebc5c01
PP
366 }
367 }
ee50adbe
PP
368 if ($^O eq 'os390') {
369 push @enc, qw(IBM-037 IBM-819 IBM-1047);
370 }
8ebc5c01 371
284102e8 372 return @enc;
8ebc5c01
PP
373}
374
284102e8
JH
375trylocale("C");
376trylocale("POSIX");
377foreach (0..15) {
378 trylocale("ISO8859-$_");
284102e8 379 trylocale("iso8859$_");
097ee67d
JH
380 trylocale("iso8859-$_");
381 trylocale("iso_8859_$_");
382 trylocale("isolatin$_");
383 trylocale("isolatin-$_");
384 trylocale("iso_latin_$_");
8ebc5c01
PP
385}
386
645e49ed
JH
387# Sanitize the environment so that we can run the external 'locale'
388# program without the taint mode getting grumpy.
cce5967e
JH
389
390# $ENV{PATH} is special in VMS.
391delete $ENV{PATH} if $^O ne 'VMS' or $Config{d_setenv};
392
393# Other subversive stuff.
394delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
dd8482fc 395
21477fb4 396if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|")) {
dd8482fc 397 while (<LOCALES>) {
d281a6ac
NC
398 # It seems that /usr/bin/locale steadfastly outputs 8 bit data, which
399 # ain't great when we're running this testPERL_UNICODE= so that utf8
400 # locales will cause all IO hadles to default to (assume) utf8
401 next unless utf8::valid($_);
dd8482fc
JH
402 chomp;
403 trylocale($_);
284102e8 404 }
dd8482fc 405 close(LOCALES);
a6259068
PP
406} elsif ($^O eq 'VMS' && defined($ENV{'SYS$I18N_LOCALE'}) && -d 'SYS$I18N_LOCALE') {
407# The SYS$I18N_LOCALE logical name search list was not present on
408# VAX VMS V5.5-12, but was on AXP && VAX VMS V6.2 as well as later versions.
409 opendir(LOCALES, "SYS\$I18N_LOCALE:");
410 while ($_ = readdir(LOCALES)) {
411 chomp;
412 trylocale($_);
413 }
414 close(LOCALES);
87e33296
SP
415} elsif ($^O eq 'openbsd' && -e '/usr/share/locale') {
416
417 # OpenBSD doesn't have a locale executable, so reading /usr/share/locale
418 # is much easier and faster than the last resort method.
419
420 opendir(LOCALES, '/usr/share/locale');
421 while ($_ = readdir(LOCALES)) {
422 chomp;
423 trylocale($_);
424 }
425 close(LOCALES);
dd8482fc
JH
426} else {
427
428 # This is going to be slow.
429
430 foreach my $locale (split(/\n/, $locales)) {
431 my ($locale_name, $language_codes, $country_codes, $encodings) =
432 split(/:/, $locale);
433 my @enc = decode_encodings($encodings);
434 foreach my $loc (split(/ /, $locale_name)) {
435 trylocale($loc);
284102e8 436 foreach my $enc (@enc) {
dd8482fc 437 trylocale("$loc.$enc");
284102e8 438 }
dd8482fc 439 $loc = lc $loc;
284102e8 440 foreach my $enc (@enc) {
dd8482fc
JH
441 trylocale("$loc.$enc");
442 }
443 }
444 foreach my $lang (split(/ /, $language_codes)) {
445 trylocale($lang);
446 foreach my $country (split(/ /, $country_codes)) {
447 my $lc = "${lang}_${country}";
448 trylocale($lc);
449 foreach my $enc (@enc) {
450 trylocale("$lc.$enc");
451 }
452 my $lC = "${lang}_\U${country}";
453 trylocale($lC);
454 foreach my $enc (@enc) {
455 trylocale("$lC.$enc");
456 }
284102e8
JH
457 }
458 }
459 }
460}
4599a1de 461
d43ce814
JH
462setlocale(LC_ALL, "C");
463
86f50d7d 464if ($^O eq 'darwin') {
4373e181 465 # Darwin 8/Mac OS X 10.4 and 10.5 have bad Basque locales: perl bug #35895,
86f50d7d 466 # Apple bug ID# 4139653. It also has a problem in Byelorussian.
4373e181
RGS
467 (my $v) = $Config{osvers} =~ /^(\d+)/;
468 if ($v >= 8 and $v < 10) {
86f50d7d 469 debug "# Skipping eu_ES, be_BY locales -- buggy in Darwin\n";
a5ec937f 470 @Locale = grep ! m/^(eu_ES(?:\..*)?|be_BY\.CP1131)$/, @Locale;
dfa5c78f 471 } elsif ($v < 12) {
a44d0896
NC
472 debug "# Skipping be_BY locales -- buggy in Darwin\n";
473 @Locale = grep ! m/^be_BY\.CP1131$/, @Locale;
a5ec937f 474 }
86f50d7d
DD
475}
476
4599a1de
JH
477@Locale = sort @Locale;
478
887ef7ed
PP
479debug "# Locales =\n";
480for ( @Locale ) {
481 debug "# $_\n";
482}
8ebc5c01 483
284102e8 484my %Problem;
2a680da6
JH
485my %Okay;
486my %Testing;
097ee67d 487my @Neoalpha;
d8093b23 488my %Neoalpha;
284102e8 489
2a680da6
JH
490sub tryneoalpha {
491 my ($Locale, $i, $test) = @_;
2a680da6
JH
492 unless ($test) {
493 $Problem{$i}{$Locale} = 1;
494 debug "# failed $i with locale '$Locale'\n";
495 } else {
496 push @{$Okay{$i}}, $Locale;
497 }
498}
499
284102e8
JH
500foreach $Locale (@Locale) {
501 debug "# Locale = $Locale\n";
502 @Alnum_ = getalnum_();
db4b7445 503 debug "# w = ", join("",@Alnum_), "\n";
284102e8
JH
504
505 unless (setlocale(LC_ALL, $Locale)) {
506 foreach (99..103) {
507 $Problem{$_}{$Locale} = -1;
8ebc5c01 508 }
284102e8 509 next;
8ebc5c01 510 }
8ebc5c01 511
284102e8
JH
512 # Sieve the uppercase and the lowercase.
513
097ee67d
JH
514 my %UPPER = ();
515 my %lower = ();
516 my %BoThCaSe = ();
284102e8
JH
517 for (@Alnum_) {
518 if (/[^\d_]/) { # skip digits and the _
519 if (uc($_) eq $_) {
520 $UPPER{$_} = $_;
521 }
522 if (lc($_) eq $_) {
523 $lower{$_} = $_;
524 }
525 }
526 }
527 foreach (keys %UPPER) {
097ee67d 528 $BoThCaSe{$_}++ if exists $lower{$_};
284102e8
JH
529 }
530 foreach (keys %lower) {
097ee67d 531 $BoThCaSe{$_}++ if exists $UPPER{$_};
284102e8 532 }
097ee67d 533 foreach (keys %BoThCaSe) {
284102e8
JH
534 delete $UPPER{$_};
535 delete $lower{$_};
536 }
537
db4b7445
A
538 debug "# UPPER = ", join("", sort keys %UPPER ), "\n";
539 debug "# lower = ", join("", sort keys %lower ), "\n";
540 debug "# BoThCaSe = ", join("", sort keys %BoThCaSe), "\n";
284102e8
JH
541
542 # Find the alphabets that are not alphabets in the default locale.
8ebc5c01 543
284102e8
JH
544 {
545 no locale;
8ebc5c01 546
284102e8
JH
547 @Neoalpha = ();
548 for (keys %UPPER, keys %lower) {
549 push(@Neoalpha, $_) if (/\W/);
d8093b23 550 $Neoalpha{$_} = $_;
284102e8 551 }
8ebc5c01 552 }
8ebc5c01 553
284102e8 554 @Neoalpha = sort @Neoalpha;
8ebc5c01 555
db4b7445 556 debug "# Neoalpha = ", join("",@Neoalpha), "\n";
8ebc5c01 557
284102e8
JH
558 if (@Neoalpha == 0) {
559 # If we have no Neoalphas the remaining tests are no-ops.
6be75cd7 560 debug "# no Neoalpha, skipping tests 99..102 for locale '$Locale'\n";
a88c3d7c
GS
561 foreach (99..102) {
562 push @{$Okay{$_}}, $Locale;
563 }
6be75cd7 564 } else {
8ebc5c01 565
6be75cd7 566 # Test \w.
284102e8 567
ef4a39e5 568 my $word = join('', @Neoalpha);
8ebc5c01 569
5fef21a3
JH
570 my $badutf8;
571 {
572 local $SIG{__WARN__} = sub {
573 $badutf8 = $_[0] =~ /Malformed UTF-8/;
574 };
575 $Locale =~ /utf-?8/i;
576 }
577
578 if ($badutf8) {
579 debug "# Locale name contains bad UTF-8, skipping test 99 for locale '$Locale'\n";
580 } elsif ($Locale =~ /utf-?8/i) {
ef4a39e5
JH
581 debug "# unknown whether locale and Unicode have the same \\w, skipping test 99 for locale '$Locale'\n";
582 push @{$Okay{99}}, $Locale;
583 } else {
584 if ($word =~ /^(\w+)$/) {
585 tryneoalpha($Locale, 99, 1);
586 } else {
587 tryneoalpha($Locale, 99, 0);
588 }
8ac0d9e6 589 }
ef4a39e5 590
2a680da6 591 # Cross-check the whole 8-bit character set.
8ebc5c01 592
6be75cd7 593 for (map { chr } 0..255) {
2a680da6
JH
594 tryneoalpha($Locale, 100,
595 (/\w/ xor /\W/) ||
596 (/\d/ xor /\D/) ||
597 (/\s/ xor /\S/));
284102e8 598 }
8ebc5c01 599
6be75cd7 600 # Test for read-only scalars' locale vs non-locale comparisons.
284102e8 601
284102e8 602 {
6be75cd7
JH
603 no locale;
604 $a = "qwerty";
605 {
606 use locale;
2a680da6 607 tryneoalpha($Locale, 101, ($a cmp "qwerty") == 0);
8ebc5c01
PP
608 }
609 }
8ebc5c01 610
6be75cd7
JH
611 {
612 my ($from, $to, $lesser, $greater,
613 @test, %test, $test, $yes, $no, $sign);
614
615 for (0..9) {
616 # Select a slice.
617 $from = int(($_*@Alnum_)/10);
618 $to = $from + int(@Alnum_/10);
619 $to = $#Alnum_ if ($to > $#Alnum_);
620 $lesser = join('', @Alnum_[$from..$to]);
621 # Select a slice one character on.
622 $from++; $to++;
623 $to = $#Alnum_ if ($to > $#Alnum_);
624 $greater = join('', @Alnum_[$from..$to]);
625 ($yes, $no, $sign) = ($lesser lt $greater
626 ? (" ", "not ", 1)
627 : ("not ", " ", -1));
628 # all these tests should FAIL (return 0).
629 # Exact lt or gt cannot be tested because
630 # in some locales, say, eacute and E may test equal.
631 @test =
632 (
633 $no.' ($lesser le $greater)', # 1
634 'not ($lesser ne $greater)', # 2
635 ' ($lesser eq $greater)', # 3
636 $yes.' ($lesser ge $greater)', # 4
637 $yes.' ($lesser ge $greater)', # 5
638 $yes.' ($greater le $lesser )', # 7
639 'not ($greater ne $lesser )', # 8
640 ' ($greater eq $lesser )', # 9
641 $no.' ($greater ge $lesser )', # 10
0e053d1e 642 'not (($lesser cmp $greater) == -($sign))' # 11
6be75cd7
JH
643 );
644 @test{@test} = 0 x @test;
645 $test = 0;
284102e8 646 for my $ti (@test) {
6be75cd7
JH
647 $test{$ti} = eval $ti;
648 $test ||= $test{$ti}
284102e8 649 }
2a680da6 650 tryneoalpha($Locale, 102, $test == 0);
6be75cd7 651 if ($test) {
6be75cd7
JH
652 debug "# lesser = '$lesser'\n";
653 debug "# greater = '$greater'\n";
654 debug "# lesser cmp greater = ",
655 $lesser cmp $greater, "\n";
656 debug "# greater cmp lesser = ",
657 $greater cmp $lesser, "\n";
658 debug "# (greater) from = $from, to = $to\n";
659 for my $ti (@test) {
660 debugf("# %-40s %-4s", $ti,
661 $test{$ti} ? 'FAIL' : 'ok');
662 if ($ti =~ /\(\.*(\$.+ +cmp +\$[^\)]+)\.*\)/) {
663 debugf("(%s == %4d)", $1, eval $1);
664 }
665 debug "\n#";
666 }
284102e8 667
6be75cd7
JH
668 last;
669 }
284102e8 670 }
8ebc5c01
PP
671 }
672 }
6be75cd7
JH
673
674 use locale;
675
676 my ($x, $y) = (1.23, 1.23);
677
0e053d1e 678 $a = "$x";
6be75cd7 679 printf ''; # printf used to reset locale to "C"
0e053d1e 680 $b = "$y";
6be75cd7 681
2a680da6
JH
682 debug "# 103..107: a = $a, b = $b, Locale = $Locale\n";
683
684 tryneoalpha($Locale, 103, $a eq $b);
6be75cd7
JH
685
686 my $c = "$x";
687 my $z = sprintf ''; # sprintf used to reset locale to "C"
688 my $d = "$y";
689
2a680da6 690 debug "# 104..107: c = $c, d = $d, Locale = $Locale\n";
6be75cd7 691
2a680da6 692 tryneoalpha($Locale, 104, $c eq $d);
6be75cd7 693
2a680da6 694 {
9f1b1f2d 695 use warnings;
2a680da6 696 my $w = 0;
0e053d1e
JH
697 local $SIG{__WARN__} =
698 sub {
906f284f 699 print "# @_\n";
0e053d1e
JH
700 $w++;
701 };
6be75cd7 702
0e053d1e
JH
703 # The == (among other ops) used to warn for locales
704 # that had something else than "." as the radix character.
6be75cd7 705
2a680da6 706 tryneoalpha($Locale, 105, $c == 1.23);
6be75cd7 707
2a680da6 708 tryneoalpha($Locale, 106, $c == $x);
6be75cd7 709
2a680da6 710 tryneoalpha($Locale, 107, $c == $d);
6be75cd7 711
2a680da6 712 {
2de3dbcc 713# no locale; # XXX did this ever work correctly?
6be75cd7 714
2a680da6 715 my $e = "$x";
6be75cd7 716
2a680da6 717 debug "# 108..110: e = $e, Locale = $Locale\n";
6be75cd7 718
2a680da6 719 tryneoalpha($Locale, 108, $e == 1.23);
6be75cd7 720
2a680da6
JH
721 tryneoalpha($Locale, 109, $e == $x);
722
723 tryneoalpha($Locale, 110, $e == $c);
6be75cd7 724 }
2a680da6 725
2a680da6 726 my $f = "1.23";
906f284f 727 my $g = 2.34;
2a680da6 728
906f284f 729 debug "# 111..115: f = $f, g = $g, locale = $Locale\n";
2a680da6 730
906f284f 731 tryneoalpha($Locale, 111, $f == 1.23);
6be75cd7 732
906f284f 733 tryneoalpha($Locale, 112, $f == $x);
2a680da6 734
906f284f
NC
735 tryneoalpha($Locale, 113, $f == $c);
736
737 tryneoalpha($Locale, 114, abs(($f + $g) - 3.57) < 0.01);
738
739 tryneoalpha($Locale, 115, $w == 0);
6be75cd7
JH
740 }
741
26d80d95
LC
742 # Does taking lc separately differ from taking
743 # the lc "in-line"? (This was the bug 19990704.002, change #3568.)
744 # The bug was in the caching of the 'o'-magic.
2a680da6
JH
745 {
746 use locale;
6be75cd7 747
2a680da6
JH
748 sub lcA {
749 my $lc0 = lc $_[0];
750 my $lc1 = lc $_[1];
751 return $lc0 cmp $lc1;
752 }
6be75cd7 753
2a680da6
JH
754 sub lcB {
755 return lc($_[0]) cmp lc($_[1]);
756 }
6be75cd7 757
2a680da6
JH
758 my $x = "ab";
759 my $y = "aa";
760 my $z = "AB";
6be75cd7 761
906f284f 762 tryneoalpha($Locale, 116,
2a680da6
JH
763 lcA($x, $y) == 1 && lcB($x, $y) == 1 ||
764 lcA($x, $z) == 0 && lcB($x, $z) == 0);
6be75cd7 765 }
d8093b23 766
26d80d95
LC
767 # Does lc of an UPPER (if different from the UPPER) match
768 # case-insensitively the UPPER, and does the UPPER match
769 # case-insensitively the lc of the UPPER. And vice versa.
3ba0e062 770 {
ef4a39e5
JH
771 use locale;
772 no utf8;
773 my $re = qr/[\[\(\{\*\+\?\|\^\$\\]/;
774
775 my @f = ();
776 foreach my $x (keys %UPPER) {
777 my $y = lc $x;
778 next unless uc $y eq $x;
779 print "# UPPER $x lc $y ",
780 $x =~ /$y/i ? 1 : 0, " ",
781 $y =~ /$x/i ? 1 : 0, "\n" if 0;
83d38f53 782 #
ef4a39e5
JH
783 # If $x and $y contain regular expression characters
784 # AND THEY lowercase (/i) to regular expression characters,
785 # regcomp() will be mightily confused. No, the \Q doesn't
786 # help here (maybe regex engine internal lowercasing
787 # is done after the \Q?) An example of this happening is
788 # the bg_BG (Bulgarian) locale under EBCDIC (OS/390 USS):
789 # the chr(173) (the "[") is the lowercase of the chr(235).
83d38f53 790 #
ef4a39e5
JH
791 # Similarly losing EBCDIC locales include cs_cz, cs_CZ,
792 # el_gr, el_GR, en_us.IBM-037 (!), en_US.IBM-037 (!),
793 # et_ee, et_EE, hr_hr, hr_HR, hu_hu, hu_HU, lt_LT,
794 # mk_mk, mk_MK, nl_nl.IBM-037, nl_NL.IBM-037,
795 # pl_pl, pl_PL, ro_ro, ro_RO, ru_ru, ru_RU,
796 # sk_sk, sk_SK, sl_si, sl_SI, tr_tr, tr_TR.
83d38f53
JH
797 #
798 # Similar things can happen even under (bastardised)
799 # non-EBCDIC locales: in many European countries before the
800 # advent of ISO 8859-x nationally customised versions of
801 # ISO 646 were devised, reusing certain punctuation
802 # characters for modified characters needed by the
803 # country/language. For example, the "|" might have
804 # stood for U+00F6 or LATIN SMALL LETTER O WITH DIAERESIS.
805 #
ef4a39e5
JH
806 if ($x =~ $re || $y =~ $re) {
807 print "# Regex characters in '$x' or '$y', skipping test 117 for locale '$Locale'\n";
808 next;
8ac0d9e6 809 }
ef4a39e5
JH
810 # With utf8 both will fail since the locale concept
811 # of upper/lower does not work well in Unicode.
812 push @f, $x unless $x =~ /$y/i == $y =~ /$x/i;
c00ff1c7 813 }
ef4a39e5 814
c00ff1c7
DM
815 foreach my $x (keys %lower) {
816 my $y = uc $x;
817 next unless lc $y eq $x;
818 print "# lower $x uc $y ",
819 $x =~ /$y/i ? 1 : 0, " ",
820 $y =~ /$x/i ? 1 : 0, "\n" if 0;
821 if ($x =~ $re || $y =~ $re) { # See above.
822 print "# Regex characters in '$x' or '$y', skipping test 117 for locale '$Locale'\n";
823 next;
8ac0d9e6 824 }
c00ff1c7
DM
825 # With utf8 both will fail since the locale concept
826 # of upper/lower does not work well in Unicode.
827 push @f, $x unless $x =~ /$y/i == $y =~ /$x/i;
828 }
829 tryneoalpha($Locale, 117, @f == 0);
830 if (@f) {
831 print "# failed 117 locale '$Locale' characters @f\n"
832 }
d8093b23 833 }
8ebc5c01 834}
284102e8 835
2a680da6
JH
836# Recount the errors.
837
98daf176 838foreach (&last_without_setlocale()+1..$last_locales) {
2a680da6 839 if ($Problem{$_} || !defined $Okay{$_} || !@{$Okay{$_}}) {
097ee67d
JH
840 if ($_ == 102) {
841 print "# The failure of test 102 is not necessarily fatal.\n";
b4e009be 842 print "# It usually indicates a problem in the environment,\n";
284102e8
JH
843 print "# not in Perl itself.\n";
844 }
845 print "not ";
8ebc5c01 846 }
284102e8 847 print "ok $_\n";
8ebc5c01 848}
fb73857a 849
2a680da6
JH
850# Give final advice.
851
284102e8
JH
852my $didwarn = 0;
853
98daf176 854foreach (99..$last_locales) {
284102e8
JH
855 if ($Problem{$_}) {
856 my @f = sort keys %{ $Problem{$_} };
857 my $f = join(" ", @f);
858 $f =~ s/(.{50,60}) /$1\n#\t/g;
2a680da6
JH
859 print
860 "#\n",
861 "# The locale ", (@f == 1 ? "definition" : "definitions"), "\n#\n",
284102e8
JH
862 "#\t", $f, "\n#\n",
863 "# on your system may have errors because the locale test $_\n",
864 "# failed in ", (@f == 1 ? "that locale" : "those locales"),
865 ".\n";
2a680da6 866 print <<EOW;
284102e8
JH
867#
868# If your users are not using these locales you are safe for the moment,
869# but please report this failure first to perlbug\@perl.com using the
870# perlbug script (as described in the INSTALL file) so that the exact
871# details of the failures can be sorted out first and then your operating
872# system supplier can be alerted about these anomalies.
873#
874EOW
875 $didwarn = 1;
fb73857a
PP
876 }
877}
774d564b 878
26d80d95 879# Tell which locales were okay and which were not.
2a680da6 880
284102e8 881if ($didwarn) {
26d80d95 882 my (@s, @F);
284102e8
JH
883
884 foreach my $l (@Locale) {
885 my $p = 0;
98daf176 886 foreach my $t (102..$last_locales) {
284102e8 887 $p++ if $Problem{$t}{$l};
8ebc5c01 888 }
284102e8 889 push @s, $l if $p == 0;
26d80d95 890 push @F, $l unless $p == 0;
8ebc5c01 891 }
284102e8 892
68d47915
CK
893 if (@s) {
894 my $s = join(" ", @s);
895 $s =~ s/(.{50,60}) /$1\n#\t/g;
896
897 warn
898 "# The following locales\n#\n",
899 "#\t", $s, "\n#\n",
900 "# tested okay.\n#\n",
901 } else {
26d80d95
LC
902 warn "# None of your locales were fully okay.\n";
903 }
904
905 if (@F) {
906 my $F = join(" ", @F);
907 $F =~ s/(.{50,60}) /$1\n#\t/g;
908
909 warn
910 "# The following locales\n#\n",
0e053d1e 911 "#\t", $F, "\n#\n",
26d80d95
LC
912 "# had problems.\n#\n",
913 } else {
914 warn "# None of your locales were broken.\n";
68d47915 915 }
0e053d1e 916
c406fbf4
JH
917 if (@utf8locale) {
918 my $S = join(" ", @utf8locale);
919 $S =~ s/(.{50,60}) /$1\n#\t/g;
920
921 warn "#\n# The following locales\n#\n",
922 "#\t", $S, "\n#\n",
923 "# were skipped for the tests ",
924 join(" ", sort {$a<=>$b} keys %utf8skip), "\n",
925 "# because UTF-8 and locales do not work together in Perl.\n#\n";
926 }
8ebc5c01 927}
90248788 928
98daf176
KW
929sub last_locales { 117 }
930
906f284f
NC
931sub last { 117 }
932
90248788 933# eof