Commit | Line | Data |
a687059c |
1 | #!./perl |
2 | |
c39c4c41 |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | } |
a687059c |
7 | |
c39c4c41 |
8 | require './test.pl'; |
9 | plan( 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 |
14 | is($first, "Now is "); |
a687059c |
15 | |
16 | $last = substr($foo,rindex($foo,'the'),100); |
c39c4c41 |
17 | is($last, "their country."); |
a687059c |
18 | |
19 | $last = substr($foo,index($foo,'Now'),2); |
c39c4c41 |
20 | is($last, "No"); |
a687059c |
21 | |
22 | $last = substr($foo,rindex($foo,'Now'),2); |
c39c4c41 |
23 | is($last, "No"); |
a687059c |
24 | |
25 | $last = substr($foo,index($foo,'.'),100); |
c39c4c41 |
26 | is($last, "."); |
a687059c |
27 | |
28 | $last = substr($foo,rindex($foo,'.'),100); |
c39c4c41 |
29 | is($last, "."); |
d9d8d8de |
30 | |
c39c4c41 |
31 | is(index("ababa","a",-1), 0); |
32 | is(index("ababa","a",0), 0); |
33 | is(index("ababa","a",1), 2); |
34 | is(index("ababa","a",2), 2); |
35 | is(index("ababa","a",3), 4); |
36 | is(index("ababa","a",4), 4); |
37 | is(index("ababa","a",5), -1); |
d9d8d8de |
38 | |
c39c4c41 |
39 | is(rindex("ababa","a",-1), -1); |
40 | is(rindex("ababa","a",0), 0); |
41 | is(rindex("ababa","a",1), 0); |
42 | is(rindex("ababa","a",2), 2); |
43 | is(rindex("ababa","a",3), 2); |
44 | is(rindex("ababa","a",4), 4); |
45 | is(rindex("ababa","a",5), 4); |
4f593451 |
46 | |
47 | $a = "foo \x{1234}bar"; |
48 | |
c39c4c41 |
49 | is(index($a, "\x{1234}"), 4); |
50 | is(index($a, "bar", ), 5); |
4f593451 |
51 | |
c39c4c41 |
52 | is(rindex($a, "\x{1234}"), 4); |
53 | is(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 | } |