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