run/locale.t: Add test for UTF-8 string non-UTF8 locale

This was suggested by Tony Cook at
https://github.com/Perl/perl5/pull/22811#discussion_r1868633416
This commit is contained in:
Karl Williamson 2025-01-30 18:09:27 -07:00 committed by Karl Williamson
parent 305b3e1a8c
commit fecfa476eb

View File

@ -584,6 +584,32 @@ else {
EOF
}
SKIP:
{
my @locales = find_locales( [ qw(LC_CTYPE LC_COLLATE) ] );
my (undef, $non_utf8_ref) = classify_locales_wrt_utf8ness(\@locales);
my @non_utf8_locales = grep { $_ !~ / \b C \b | POSIX /x }
$non_utf8_ref->@*;
skip "didn't find a suitable non-UTF-8 locale", 1 unless
@non_utf8_locales;
my $locale = $non_utf8_locales[0];
fresh_perl_is(<<"EOF", "ok\n", {}, "Handles above Latin1 and NUL in non-UTF8 locale");
use locale;
use POSIX qw(setlocale LC_COLLATE);
if (setlocale(LC_COLLATE, '$locale')) {
my \$x = "A\\xB5\\x00B";
utf8::upgrade(\$x);
my \$y = "\\x{100}";
my \$cmp = \$x cmp \$y;
print \$cmp <= 0 ? "ok\n" : "not ok\n";
}
else {
print "ok\n";
}
EOF
}
SKIP: { # GH #20085
my @utf8_locales = find_utf8_ctype_locales();
skip "didn't find a UTF-8 locale", 1 unless @utf8_locales;