fix unicode split /\s+/
[p5sagit/p5-mst-13.2.git] / t / op / split.t
index 55b2839..f5d0c41 100755 (executable)
@@ -6,7 +6,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan tests => 52;
+plan tests => 80;
 
 $FS = ':';
 
@@ -50,12 +50,8 @@ $_ = join(':', split(/:/,'1:2:3:4:5:6:::', 999));
 is($_ , '1:2:3:4:5:6:::');
 
 # Does assignment to a list imply split to one more field than that?
-if ($^O eq 'MSWin32') { $foo = `.\\perl -D1024 -e "(\$a,\$b) = split;" 2>&1` }
-elsif ($^O eq 'NetWare') { $foo = `perl -D1024 -e "(\$a,\$b) = split;" 2>&1` }
-elsif ($^O eq 'VMS')  { $foo = `./perl "-D1024" -e "(\$a,\$b) = split;" 2>&1` }
-elsif ($^O eq 'MacOS'){ $foo = `$^X "-D1024" -e "(\$a,\$b) = split;"` }
-else                  { $foo = `./perl -D1024 -e '(\$a,\$b) = split;' 2>&1` }
-ok($foo =~ /DEBUGGING/ || $foo =~ /SV = (VOID|IV\(3\))/);
+$foo = runperl( switches => ['-Dt'], stderr => 1, prog => '($a,$b)=split;' );
+ok($foo =~ /DEBUGGING/ || $foo =~ /const\n?\Q(IV(3))\E/);
 
 # Can we say how many fields to split to when assigning to a list?
 ($a,$b) = split(' ','1 2 3 4 5 6', 2);
@@ -279,6 +275,60 @@ ok(@ary == 3 &&
 {
     $p="a,b";
     utf8::upgrade $p;
-    @a=split(/[, ]+/,$p);
+    eval { @a=split(/[, ]+/,$p) };
     is ("$@-@a-", '-a b-', '#20912 - split() to array with /[]+/ and utf8');
 }
+
+{
+    is (\@a, \@{"a"}, '@a must be global for following test');
+    $p="";
+    $n = @a = split /,/,$p;
+    is ($n, 0, '#21765 - pmreplroot hack used to return undef for 0 iters');
+}
+
+{
+    # [perl #28938]
+    # assigning off the end of the array after a split could leave garbage
+    # in the inner elements
+
+    my $x;
+    @a = split /,/, ',,,,,';
+    $a[3]=1;
+    $x = \$a[2];
+    is (ref $x, 'SCALAR', '#28938 - garbage after extend');
+}
+{
+    # check the special casing of split /\s/ and unicode
+    use charnames qw(:full);
+    # below test data is extracted from
+    # PropList-5.0.0.txt
+    # Date: 2006-06-07, 23:22:52 GMT [MD]
+    #
+    # Unicode Character Database
+    # Copyright (c) 1991-2006 Unicode, Inc.
+    # For terms of use, see http://www.unicode.org/terms_of_use.html
+    # For documentation, see UCD.html
+    my @spaces=(
+        0x0009..0x000A, # Cc   [5] <control-0009>..<control-000D>
+        0x000C..0x000D, # EXCLUDING \v aka ctl-000B aka vert-tab
+        0x0020,         # Zs       SPACE
+        0x0085,         # Cc       <control-0085>
+        0x00A0,         # Zs       NO-BREAK SPACE
+        0x1680,         # Zs       OGHAM SPACE MARK
+        0x180E,         # Zs       MONGOLIAN VOWEL SEPARATOR
+        0x2000..0x200A, # Zs  [11] EN QUAD..HAIR SPACE
+        0x2028,         # Zl       LINE SEPARATOR
+        0x2029,         # Zp       PARAGRAPH SEPARATOR
+        0x202F,         # Zs       NARROW NO-BREAK SPACE
+        0x205F,         # Zs       MEDIUM MATHEMATICAL SPACE
+        0x3000          # Zs       IDEOGRAPHIC SPACE
+    );
+    #diag "Have @{[0+@spaces]} to test\n";
+    foreach my $cp (@spaces) {
+        my $space = chr($cp);
+        my $str="A:$space:B\x{FFFF}";
+        chop $str;
+        my @res=split(/\s+/,$str);
+        is(0+@res,2) or do { diag sprintf "Char failed: 0x%x",$cp }
+    }
+}