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