]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: fold: add tests for multi-byte width
authorPádraig Brady <P@draigBrady.com>
Wed, 27 Aug 2025 13:34:46 +0000 (14:34 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 27 Aug 2025 15:41:07 +0000 (16:41 +0100)
* tests/fold/fold.pl: The i18n patch didn't actually test folding
of multi-byte characters, so add tests for various multi-byte forms.

tests/fold/fold.pl

index de34177fdae4a1f5bd10842928a8b4eabdeecad9..ea9bc5c6af4cac210b15e61614e8d78921e29bc3 100755 (executable)
@@ -50,12 +50,25 @@ my @Tests =
      {OUT=>"123456\n7890\nabcdef\nghij\n123456\n7890"}],
   );
 
+# define UTF-8 encoded multi-byte characters for tests
+my $eaC = "\xC3\xA9";      # e acute NFC form
+my $eaD = "\x65\xCC\x81";  # e acute NFD form (zero width combining)
+my $eFW = "\xEF\xBD\x85";  # e fullwidth
+
+my @mbTests =
+  (
+     ['smb1', '-w2', {IN=>$eaC x 3}, {OUT=>$eaC x 2 . "\n" . $eaC}],
+     ['smb2', '-w2', {IN=>$eaD x 3}, {OUT=>$eaD x 2 . "\n" . $eaD}],
+     ['smb3', '-w2', {IN=>$eFW x 2}, {OUT=>$eFW . "\n" . $eFW}],
+  );
+
 if ($mb_locale ne 'C')
   {
     # Duplicate each test vector, appending "-mb" to the test name and
     # inserting {ENV => "LC_ALL=$mb_locale"} in the copy, so that we
     # provide coverage for multi-byte code paths.
     my @new;
+
     foreach my $t (@Tests)
       {
         my @new_t = @$t;
@@ -64,6 +77,15 @@ if ($mb_locale ne 'C')
         push @new, ["$test_name-mb", @new_t, {ENV => "LC_ALL=$mb_locale"}];
       }
     push @Tests, @new;
+
+    @new = ();
+    foreach my $t (@mbTests)
+      {
+        my @new_t = @$t;
+
+        push @new, [@new_t, {ENV => "LC_ALL=$mb_locale"}];
+      }
+    push @Tests, @new;
   }
 
 @Tests = triple_test \@Tests;