Fix test added in change 23645 with an eval()
[p5sagit/p5-mst-13.2.git] / t / op / substr.t
index 17f86e3..9549d29 100755 (executable)
@@ -1,6 +1,6 @@
 #!./perl
 
-print "1..175\n";
+print "1..190\n";
 
 #P = start of string  Q = start of substr  R = end of substr  S = end of string
 
@@ -592,3 +592,69 @@ ok 174, $x eq "\x{100}\x{200}\xFFb";
     $r[$_] = \ substr $s, $_, 1 for (0, 1);
     ok 175, join("", map { $$_ } @r) eq "ab";
 }
+
+# [perl #23207]
+{
+    sub ss {
+       substr($_[0],0,1) ^= substr($_[0],1,1) ^=
+       substr($_[0],0,1) ^= substr($_[0],1,1);
+    }
+    my $x = my $y = 'AB'; ss $x; ss $y;
+    ok 176, $x eq $y;
+}
+
+# [perl #24605]
+{
+    my $x = "0123456789\x{500}";
+    my $y = substr $x, 4;
+    ok 177, substr($x, 7, 1) eq "7";
+}
+
+# multiple assignments to lvalue [perl #24346]   
+{
+    my $x = "abcdef";
+    for (substr($x,1,3)) {
+       ok 178, $_ eq 'bcd';
+       $_ = 'XX';
+       ok 179, $_ eq 'XX';
+       ok 180, $x eq 'aXXef'; 
+       $_ = "\xFF";
+       ok 181, $_ eq "\xFF";   
+       ok 182, $x eq "a\xFFef";
+       $_ = "\xF1\xF2\xF3\xF4\xF5\xF6";
+       ok 183, $_ eq "\xF1\xF2\xF3\xF4\xF5\xF6";
+       ok 184, $x eq "a\xF1\xF2\xF3\xF4\xF5\xF6ef"; 
+       $_ = 'YYYY';
+       ok 185, $_ eq 'YYYY';   
+       ok 186, $x eq 'aYYYYef';
+    }
+}
+
+# [perl #24200] string corruption with lvalue sub
+
+{
+    my $foo = "a";
+    sub bar: lvalue { substr $foo, 0 }
+    bar = "XXX";
+    ok 187, bar eq 'XXX';
+    $foo = '123456789';
+    ok 188, bar eq '123456789';
+}
+
+# [perl #29149]
+{
+    my $text  = "0123456789\xED ";
+    utf8::upgrade($text);
+    my $pos = 5;
+    pos($text) = $pos;
+    my $a = substr($text, $pos, $pos);
+    ok 189, substr($text,$pos,1) eq $pos;
+
+}
+
+# [perl #23765]
+{
+    my $a = pack("C", 0xbf);
+    substr($a, -1) &= chr(0xfeff);
+    ok 190, $a eq "\xbf";
+}