This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.t: Add TODO tests
authorKarl Williamson <public@khwilliamson.com>
Mon, 31 Dec 2012 03:39:37 +0000 (20:39 -0700)
committerKarl Williamson <public@khwilliamson.com>
Mon, 31 Dec 2012 18:03:28 +0000 (11:03 -0700)
It turns out that Perl has always assumed that the Posix character
classes are closed under folding.  For example, if a character is in
[:alpha:], its fold will be in [:alpha:] as well.

This seems like a reasonable assumption except for two classes, where it
is almost certainly wrong.  If a character matches [:upper:], its fold
likely won't.  Same for [:lower:].  What this means is that a regex of
the form

    /[[:lower:]]/i

has never properly matched the uppercased versions of the characters in
the target string.

This commit adds TODO tests for these.

lib/locale.t

index 36544d1..8237e24 100644 (file)
@@ -763,38 +763,53 @@ foreach $Locale (@Locale) {
     debug "# BoThCaSe = ", join("", sort keys %BoThCaSe), "\n";
 
     my @failures;
+    my @fold_failures;
     foreach my $x (sort keys %UPPER) {
         my $ok;
+        my $fold_ok;
         if ($is_utf8_locale) {
             use locale ':not_characters';
             $ok = $x =~ /[[:upper:]]/;
+            $fold_ok = $x =~ /[[:lower:]]/i;
         }
         else {
             use locale;
             $ok = $x =~ /[[:upper:]]/;
+            $fold_ok = $x =~ /[[:lower:]]/i;
         }
         push @failures, $x unless $ok;
+        push @fold_failures, $x unless $fold_ok;
     }
     my $message = "";
     $locales_test_number++;
     $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/ matches sieved uppercase characters.';
     $message = 'Failed for ' . join ", ", @failures if @failures;
     tryneoalpha($Locale, $locales_test_number, scalar @failures == 0, $message);
+    $message = "";
+    $locales_test_number++;
+    $test_names{$locales_test_number} = 'TODO Verify that /[[:lower:]]/i matches sieved uppercase characters.';
+    $message = 'Failed for ' . join ", ", @fold_failures if @fold_failures;
+    tryneoalpha($Locale, $locales_test_number, scalar @fold_failures == 0, $message);
 
     $message = "";
     undef @failures;
+    undef @fold_failures;
 
     foreach my $x (sort keys %lower) {
         my $ok;
+        my $fold_ok;
         if ($is_utf8_locale) {
             use locale ':not_characters';
             $ok = $x =~ /[[:lower:]]/;
+            $fold_ok = $x =~ /[[:upper:]]/i;
         }
         else {
             use locale;
             $ok = $x =~ /[[:lower:]]/;
+            $fold_ok = $x =~ /[[:upper:]]/i;
         }
         push @failures, $x unless $ok;
+        push @fold_failures, $x unless $fold_ok;
     }
 
     $locales_test_number++;
@@ -802,6 +817,10 @@ foreach $Locale (@Locale) {
     $message = 'Failed for ' . join ", ", @failures if @failures;
     tryneoalpha($Locale, $locales_test_number, scalar @failures == 0, $message);
     $message = "";
+    $locales_test_number++;
+    $test_names{$locales_test_number} = 'TODO Verify that /[[:upper:]]/i matches sieved lowercase characters.';
+    $message = 'TODO Failed for ' . join ", ", @fold_failures if @fold_failures;
+    tryneoalpha($Locale, $locales_test_number, scalar @fold_failures == 0, $message);
 
     {   # Find the alphabetic characters that are not considered alphabetics
         # in the default (C) locale.