Commit | Line | Data |
a687059c |
1 | #!./perl |
2 | |
79072805 |
3 | # $RCSfile: index.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:59 $ |
a687059c |
4 | |
4f593451 |
5 | print "1..24\n"; |
a687059c |
6 | |
7 | $foo = 'Now is the time for all good men to come to the aid of their country.'; |
8 | |
9 | $first = substr($foo,0,index($foo,'the')); |
10 | print ($first eq "Now is " ? "ok 1\n" : "not ok 1\n"); |
11 | |
12 | $last = substr($foo,rindex($foo,'the'),100); |
13 | print ($last eq "their country." ? "ok 2\n" : "not ok 2\n"); |
14 | |
15 | $last = substr($foo,index($foo,'Now'),2); |
16 | print ($last eq "No" ? "ok 3\n" : "not ok 3\n"); |
17 | |
18 | $last = substr($foo,rindex($foo,'Now'),2); |
19 | print ($last eq "No" ? "ok 4\n" : "not ok 4\n"); |
20 | |
21 | $last = substr($foo,index($foo,'.'),100); |
22 | print ($last eq "." ? "ok 5\n" : "not ok 5\n"); |
23 | |
24 | $last = substr($foo,rindex($foo,'.'),100); |
25 | print ($last eq "." ? "ok 6\n" : "not ok 6\n"); |
d9d8d8de |
26 | |
27 | print index("ababa","a",-1) == 0 ? "ok 7\n" : "not ok 7\n"; |
28 | print index("ababa","a",0) == 0 ? "ok 8\n" : "not ok 8\n"; |
29 | print index("ababa","a",1) == 2 ? "ok 9\n" : "not ok 9\n"; |
30 | print index("ababa","a",2) == 2 ? "ok 10\n" : "not ok 10\n"; |
31 | print index("ababa","a",3) == 4 ? "ok 11\n" : "not ok 11\n"; |
32 | print index("ababa","a",4) == 4 ? "ok 12\n" : "not ok 12\n"; |
33 | print index("ababa","a",5) == -1 ? "ok 13\n" : "not ok 13\n"; |
34 | |
35 | print rindex("ababa","a",-1) == -1 ? "ok 14\n" : "not ok 14\n"; |
36 | print rindex("ababa","a",0) == 0 ? "ok 15\n" : "not ok 15\n"; |
37 | print rindex("ababa","a",1) == 0 ? "ok 16\n" : "not ok 16\n"; |
38 | print rindex("ababa","a",2) == 2 ? "ok 17\n" : "not ok 17\n"; |
39 | print rindex("ababa","a",3) == 2 ? "ok 18\n" : "not ok 18\n"; |
40 | print rindex("ababa","a",4) == 4 ? "ok 19\n" : "not ok 19\n"; |
41 | print rindex("ababa","a",5) == 4 ? "ok 20\n" : "not ok 20\n"; |
4f593451 |
42 | |
43 | $a = "foo \x{1234}bar"; |
44 | |
45 | print index($a, "\x{1234}") == 4 ? "ok 21\n" : "not ok 21\n"; |
46 | print index($a, "bar", ) == 5 ? "ok 22\n" : "not ok 22\n"; |
47 | |
48 | print rindex($a, "\x{1234}") == 4 ? "ok 23\n" : "not ok 23\n"; |
49 | print rindex($a, "foo", ) == 0 ? "ok 24\n" : "not ok 24\n"; |