lib/locale.t: Refactor some tests
authorKarl Williamson <public@khwilliamson.com>
Sat, 31 Aug 2013 18:42:46 +0000 (12:42 -0600)
committerKarl Williamson <public@khwilliamson.com>
Sat, 31 Aug 2013 19:58:33 +0000 (13:58 -0600)
The tests were to make sure that UTF-8 is returned when it should be.
This makes somewhat these somewhat cleaner

lib/locale.t

index d0d6963..7319e98 100644 (file)
@@ -1699,13 +1699,7 @@ foreach $Locale (@Locale) {
                 $! = eval "&Errno::$err";   # Convert to strerror() output
                 my $strerror = "$!";
                 if ("$strerror" =~ /\P{ASCII}/) {
-                    my $utf8_strerror = $strerror;
-                    utf8::upgrade($utf8_strerror);
-
-                    # If $! was already in UTF-8, the upgrade was a no-op;
-                    # otherwise they will be different byte strings.
-                    use bytes;
-                    $ok14 = $utf8_strerror eq $strerror;
+                    $ok14 = utf8::is_utf8($strerror);
                     last;
                 }
             }
@@ -1715,15 +1709,10 @@ foreach $Locale (@Locale) {
             # stringification.
 
             my $string_g = "$g";
+            my $sprintf_g = sprintf("%g", $g);
 
-            my $utf8_string_g = "$g";
-            utf8::upgrade($utf8_string_g);
-
-            my $utf8_sprintf_g = sprintf("%g", $g);
-            utf8::upgrade($utf8_sprintf_g);
-            use bytes;
-            $ok15 = $utf8_string_g eq $string_g;
-            $ok16 = $utf8_sprintf_g eq $string_g;
+            $ok15 = $string_g =~ / ^ \p{ASCII}+ $ /x || utf8::is_utf8($string_g);
+            $ok16 = $sprintf_g eq $string_g;
         }
         {
             no locale;