Change 28404 broke the construct s/foo/<<BAR/e. So, try to be more
[p5sagit/p5-mst-13.2.git] / t / op / index.t
index d223265..88c0372 100755 (executable)
@@ -7,7 +7,7 @@ BEGIN {
 
 use strict;
 require './test.pl';
-plan( tests => 46 );
+plan( tests => 66 );
 
 my $foo = 'Now is the time for all good men to come to the aid of their country.';
 
@@ -45,6 +45,20 @@ is(rindex("ababa","a",3), 2);
 is(rindex("ababa","a",4), 4);
 is(rindex("ababa","a",5), 4);
 
+# tests for empty search string
+is(index("abc", "", -1), 0);
+is(index("abc", "", 0), 0);
+is(index("abc", "", 1), 1);
+is(index("abc", "", 2), 2);
+is(index("abc", "", 3), 3);
+is(index("abc", "", 4), 3);
+is(rindex("abc", "", -1), 0);
+is(rindex("abc", "", 0), 0);
+is(rindex("abc", "", 1), 1);
+is(rindex("abc", "", 2), 2);
+is(rindex("abc", "", 3), 3);
+is(rindex("abc", "", 4), 3);
+
 $a = "foo \x{1234}bar";
 
 is(index($a, "\x{1234}"), 4);
@@ -107,3 +121,15 @@ is(rindex($a, "foo",    ), 0);
     is (index($text, $search_octets), -1);
     is (rindex($text, $search_octets), -1);
 }
+
+foreach my $utf8 ('', ', utf-8') {
+    foreach my $arraybase (0, 1, -1, -2) {
+       my $expect_pos = 2 + $arraybase;
+
+       my $prog = "\$[ = $arraybase; \$big = \"N\\xabN\\xab\"; ";
+       $prog .= '$big .= chr 256; chop $big; ' if $utf8;
+       $prog .= 'print rindex $big, "N", 2 + $[';
+
+       fresh_perl_is($prog, $expect_pos, {}, "\$[ = $arraybase$utf8");
+    }
+}