From fecfa476ebefab8d99c628450d82a8b28a2fff42 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Thu, 30 Jan 2025 18:09:27 -0700 Subject: [PATCH] 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 --- t/run/locale.t | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/t/run/locale.t b/t/run/locale.t index 11f97f146e..dbaba7e4ed 100644 --- a/t/run/locale.t +++ b/t/run/locale.t @@ -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;