Re: [perl #36622] y/// at end of file
[p5sagit/p5-mst-13.2.git] / t / op / index.t
index 9e21e58..d223265 100755 (executable)
@@ -5,15 +5,16 @@ BEGIN {
     @INC = '../lib';
 }
 
+use strict;
 require './test.pl';
-plan( tests => 28 );
+plan( tests => 46 );
 
-$foo = 'Now is the time for all good men to come to the aid of their country.';
+my $foo = 'Now is the time for all good men to come to the aid of their country.';
 
-$first = substr($foo,0,index($foo,'the'));
+my $first = substr($foo,0,index($foo,'the'));
 is($first, "Now is ");
 
-$last = substr($foo,rindex($foo,'the'),100);
+my $last = substr($foo,rindex($foo,'the'),100);
 is($last, "their country.");
 
 $last = substr($foo,index($foo,'Now'),2);
@@ -69,3 +70,40 @@ is(rindex($a, "foo",    ), 0);
        is($a, $b, q{[perl #22375] 'split'/'index' problem for utf8});
     }
 }
+
+{
+    my $search = "foo \xc9 bar";
+    my $text = "a\xa3\xa3a $search    $search quux";
+
+    my $text_utf8 = $text;
+    utf8::upgrade($text_utf8);
+    my $search_utf8 = $search;
+    utf8::upgrade($search_utf8);
+
+    is (index($text, $search), 5);
+    is (rindex($text, $search), 18);
+    is (index($text, $search_utf8), 5);
+    is (rindex($text, $search_utf8), 18);
+    is (index($text_utf8, $search), 5);
+    is (rindex($text_utf8, $search), 18);
+    is (index($text_utf8, $search_utf8), 5);
+    is (rindex($text_utf8, $search_utf8), 18);
+
+    my $text_octets = $text_utf8;
+    utf8::encode ($text_octets);
+    my $search_octets = $search_utf8;
+    utf8::encode ($search_octets);
+
+    is (index($text_octets, $search_octets), 7, "index octets, octets")
+       or _diag ($text_octets, $search_octets);
+    is (rindex($text_octets, $search_octets), 21, "rindex octets, octets");
+    is (index($text_octets, $search_utf8), -1);
+    is (rindex($text_octets, $search_utf8), -1);
+    is (index($text_utf8, $search_octets), -1);
+    is (rindex($text_utf8, $search_octets), -1);
+
+    is (index($text_octets, $search), -1);
+    is (rindex($text_octets, $search), -1);
+    is (index($text, $search_octets), -1);
+    is (rindex($text, $search_octets), -1);
+}