In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/b3766b12c64c46e0bcc2c1dc58cc7b96d8bef10c?hp=02512a66ad35b8ddc69cacdee9807210c5e13167>

- Log -----------------------------------------------------------------
commit b3766b12c64c46e0bcc2c1dc58cc7b96d8bef10c
Author: Nicholas Clark <[email protected]>
Date:   Thu Oct 22 16:39:38 2009 +0100

    Test requiring files with non-BMP characters (encoded as surrogate pairs).
-----------------------------------------------------------------------

Summary of changes:
 t/comp/utf.t |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/t/comp/utf.t b/t/comp/utf.t
index 69ede95..00523f9 100644
--- a/t/comp/utf.t
+++ b/t/comp/utf.t
@@ -1,6 +1,6 @@
 #!./perl -w
 
-print "1..76\n";
+print "1..100\n";
 my $test = 0;
 
 my %templates = (
@@ -13,7 +13,23 @@ sub bytes_to_utf {
     my ($enc, $content, $do_bom) = @_;
     my $template = $templates{$enc};
     die "Unsupported encoding $enc" unless $template;
-    return pack "$template*", ($do_bom ? 0xFEFF : ()), unpack "U*", $content;
+    my @chars = unpack "U*", $content;
+    if ($enc ne 'utf8') {
+       # Make surrogate pairs
+       my @remember_that_utf_16_is_variable_length;
+       foreach my $ord (@chars) {
+           if ($ord < 0x10000) {
+               push @remember_that_utf_16_is_variable_length,
+                   $ord;
+           } else {
+               $ord -= 0x10000;
+               push @remember_that_utf_16_is_variable_length,
+                   (0xD800 | ($ord >> 10)), (0xDC00 | ($ord & 0x3FF));
+           }
+       }
+       @chars = @remember_that_utf_16_is_variable_length;
+    }
+    return pack "$template*", ($do_bom ? 0xFEFF : ()), @chars;
 }
 
 sub test {
@@ -45,8 +61,9 @@ for my $bom (0, 1) {
            # right now, as here we're testing the input filter itself.
 
            for my $expect ("N", "\xFF", "\x{100}", "\x{010a}", "\x{0a23}",
+                           "\x{10000}", "\x{64321}", "\x{10FFFD}",
                           ) {
-               # A space so that the UTF-16 heuristc triggers - " '" gives two
+               # A space so that the UTF-16 heuristic triggers - " '" gives two
                # characters of ASCII.
                my $write = " '$expect'";
                my $name = 'chrs ' . join ', ', map {ord $_} split '', $expect;

--
Perl5 Master Repository

Reply via email to