defined @array and defined %hash need no warnings 'deprecated';
[p5sagit/p5-mst-13.2.git] / t / op / index.t
old mode 100755 (executable)
new mode 100644 (file)
index 38da96c..6cc3f42
@@ -7,7 +7,7 @@ BEGIN {
 }
 
 use strict;
-plan( tests => 69 );
+plan( tests => 111 );
 
 run_tests() unless caller;
 
@@ -137,7 +137,8 @@ foreach my $utf8 ('', ', utf-8') {
     foreach my $arraybase (0, 1, -1, -2) {
        my $expect_pos = 2 + $arraybase;
 
-       my $prog = "\$[ = $arraybase; \$big = \"N\\xabN\\xab\"; ";
+       my $prog = "no warnings 'deprecated';\n";
+       $prog .= "\$[ = $arraybase; \$big = \"N\\xabN\\xab\"; ";
        $prog .= '$big .= chr 256; chop $big; ' if $utf8;
        $prog .= 'print rindex $big, "N", 2 + $[';
 
@@ -160,4 +161,42 @@ SKIP: {
     is(index($t, 'xyz'), 4, "0xfffffffd and utf8cache");
 }
 
+
+# Tests for NUL characters.
+{
+    my @tests = (
+        ["",            -1, -1, -1],
+        ["foo",         -1, -1, -1],
+        ["\0",           0, -1, -1],
+        ["\0\0",         0,  0, -1],
+        ["\0\0\0",       0,  0,  0],
+        ["foo\0",        3, -1, -1],
+        ["foo\0foo\0\0", 3,  7, -1],
+    );
+    foreach my $l (1 .. 3) {
+        my $q = "\0" x $l;
+        my $i = 0;
+        foreach my $test (@tests) {
+            $i ++;
+            my $str = $$test [0];
+            my $res = $$test [$l];
+
+            {
+                is (index ($str, $q), $res, "Find NUL character(s)");
+            }
+
+            #
+            # Bug #53746 shows a difference between variables and literals,
+            # so test literals as well.
+            #
+            my $test_str = qq {is (index ("$str", "$q"), $res, } .
+                           qq {"Find NUL character(s)")};
+               $test_str =~ s/\0/\\0/g;
+
+            eval $test_str;
+            die $@ if $@;
+        }
+    }
+}
+
 }