Fix test added in change 23645 with an eval()
[p5sagit/p5-mst-13.2.git] / t / op / index.t
CommitLineData
a687059c 1#!./perl
2
c39c4c41 3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
a687059c 7
c39c4c41 8require './test.pl';
9plan( tests => 28 );
a687059c 10
11$foo = 'Now is the time for all good men to come to the aid of their country.';
12
13$first = substr($foo,0,index($foo,'the'));
c39c4c41 14is($first, "Now is ");
a687059c 15
16$last = substr($foo,rindex($foo,'the'),100);
c39c4c41 17is($last, "their country.");
a687059c 18
19$last = substr($foo,index($foo,'Now'),2);
c39c4c41 20is($last, "No");
a687059c 21
22$last = substr($foo,rindex($foo,'Now'),2);
c39c4c41 23is($last, "No");
a687059c 24
25$last = substr($foo,index($foo,'.'),100);
c39c4c41 26is($last, ".");
a687059c 27
28$last = substr($foo,rindex($foo,'.'),100);
c39c4c41 29is($last, ".");
d9d8d8de 30
c39c4c41 31is(index("ababa","a",-1), 0);
32is(index("ababa","a",0), 0);
33is(index("ababa","a",1), 2);
34is(index("ababa","a",2), 2);
35is(index("ababa","a",3), 4);
36is(index("ababa","a",4), 4);
37is(index("ababa","a",5), -1);
d9d8d8de 38
c39c4c41 39is(rindex("ababa","a",-1), -1);
40is(rindex("ababa","a",0), 0);
41is(rindex("ababa","a",1), 0);
42is(rindex("ababa","a",2), 2);
43is(rindex("ababa","a",3), 2);
44is(rindex("ababa","a",4), 4);
45is(rindex("ababa","a",5), 4);
4f593451 46
47$a = "foo \x{1234}bar";
48
c39c4c41 49is(index($a, "\x{1234}"), 4);
50is(index($a, "bar", ), 5);
4f593451 51
c39c4c41 52is(rindex($a, "\x{1234}"), 4);
53is(rindex($a, "foo", ), 0);
d69d2d9f 54
55{
d69d2d9f 56 my $needle = "\x{1230}\x{1270}";
57 my @needles = split ( //, $needle );
58 my $haystack = "\x{1228}\x{1228}\x{1230}\x{1270}";
59 foreach ( @needles ) {
60 my $a = index ( "\x{1228}\x{1228}\x{1230}\x{1270}", $_ );
61 my $b = index ( $haystack, $_ );
c39c4c41 62 is($a, $b, q{[perl #22375] 'split'/'index' problem for utf8});
d69d2d9f 63 }
64 $needle = "\x{1270}\x{1230}"; # Transpose them.
65 @needles = split ( //, $needle );
66 foreach ( @needles ) {
67 my $a = index ( "\x{1228}\x{1228}\x{1230}\x{1270}", $_ );
68 my $b = index ( $haystack, $_ );
c39c4c41 69 is($a, $b, q{[perl #22375] 'split'/'index' problem for utf8});
d69d2d9f 70 }
71}