]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: expr: exercise the C.UTF-8 locale
authorSylvestre Ledru <sylvestre@debian.org>
Sun, 26 Jul 2026 14:59:29 +0000 (16:59 +0200)
committerPádraig Brady <P@draigBrady.com>
Mon, 27 Jul 2026 12:52:51 +0000 (13:52 +0100)
* tests/expr/expr-multibyte.pl: Add 'cu' prefixed cases running in
C.UTF-8, which names no language but has a UTF-8 codeset, ensuring
length, index, substr and match still operate on characters there.
Skip them where that locale is unavailable.

Link: https://github.com/coreutils/coreutils/pull/323
tests/expr/expr-multibyte.pl

index 199c337958e1b59e7cebdbdbcefe52f7b5d71c9f..92644482dd66e4cfe1ae9fde3316f550cc59285f 100755 (executable)
@@ -177,6 +177,18 @@ my @Tests =
    ['mb-m7', "match \xCE\xB1bc\xCE\xB4e '\\([\xCE\xB1]\\)'", {OUT=>"\xCE\xB1"}],
    ['st-m7', "match \xCE\xB1bc\xCE\xB4e '\\([\xCE\xB1]\\)'", {OUT=>"\xCE"}],
 
+
+   ### C.UTF-8 locale ###
+
+   # C.UTF-8 names no language, but its codeset is UTF-8, so expr must
+   # still operate on characters rather than on octets there.
+   # Tests starting with 'cu' repeat a subset of the 'mb' cases above and
+   # expect the same results.
+   ['cu-l1', "length abc\xCE\xB4ef",   {OUT=>"6"}],
+   ['cu-i1', "index \xCE\xB1bc\xCE\xB4ef \xCE\xB4",   {OUT=>"4"}],
+   ['cu-s1', "substr \xCE\xB1bc\xCE\xB4ef 3 2",   {OUT=>"c\xCE\xB4"}],
+   ['cu-m1', "match \xCE\xB1bc\xCE\xB4ef .bc",   {OUT=>"3"}],
+
   );
 
 
@@ -219,6 +231,17 @@ if ($locale ne 'C')
   }
 
 
+# Run the 'cu' tests in the C.UTF-8 locale, and drop them where it is
+# unavailable.
+my $c_utf8_avail = qx(LC_ALL=C.UTF-8 locale charmap 2>/dev/null) =~ /^UTF-8$/m;
+@Tests = grep {$_->[0] !~ /^cu/} @Tests
+  if ! $c_utf8_avail;
+foreach my $t (@Tests)
+  {
+    push @$t, {ENV => 'LC_ALL=C.UTF-8'}
+      if $t->[0] =~ /^cu/;
+  }
+
 my $save_temps = $ENV{DEBUG};
 my $verbose = $ENV{VERBOSE};