Skip to content

Commit 206a348

Browse files
khwilliamsonscottchiefbaker
authored andcommitted
run/locale.t: Add test for UTF-8 string non-UTF8 locale
This was suggested by Tony Cook at Perl#22811 (comment)
1 parent f12f8fc commit 206a348

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

t/run/locale.t

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,32 @@ else {
584584
EOF
585585
}
586586

587+
SKIP:
588+
{
589+
my @locales = find_locales( [ qw(LC_CTYPE LC_COLLATE) ] );
590+
my (undef, $non_utf8_ref) = classify_locales_wrt_utf8ness(\@locales);
591+
my @non_utf8_locales = grep { $_ !~ / \b C \b | POSIX /x }
592+
$non_utf8_ref->@*;
593+
skip "didn't find a suitable non-UTF-8 locale", 1 unless
594+
@non_utf8_locales;
595+
my $locale = $non_utf8_locales[0];
596+
597+
fresh_perl_is(<<"EOF", "ok\n", {}, "Handles above Latin1 and NUL in non-UTF8 locale");
598+
use locale;
599+
use POSIX qw(setlocale LC_COLLATE);
600+
if (setlocale(LC_COLLATE, '$locale')) {
601+
my \$x = "A\\xB5\\x00B";
602+
utf8::upgrade(\$x);
603+
my \$y = "\\x{100}";
604+
my \$cmp = \$x cmp \$y;
605+
print \$cmp <= 0 ? "ok\n" : "not ok\n";
606+
}
607+
else {
608+
print "ok\n";
609+
}
610+
EOF
611+
}
612+
587613
SKIP: { # GH #20085
588614
my @utf8_locales = find_utf8_ctype_locales();
589615
skip "didn't find a UTF-8 locale", 1 unless @utf8_locales;

0 commit comments

Comments
 (0)