perl 4.0.00: (no release announcement available)
[p5sagit/p5-mst-13.2.git] / t / op / substr.t
CommitLineData
a687059c 1#!./perl
2
fe14fcc3 3# $Header: substr.t,v 4.0 91/03/20 01:55:05 lwall Locked $
a687059c 4
d9d8d8de 5print "1..22\n";
a687059c 6
7$a = 'abcdefxyz';
8
9print (substr($a,0,3) eq 'abc' ? "ok 1\n" : "not ok 1\n");
10print (substr($a,3,3) eq 'def' ? "ok 2\n" : "not ok 2\n");
11print (substr($a,6,999) eq 'xyz' ? "ok 3\n" : "not ok 3\n");
12print (substr($a,999,999) eq '' ? "ok 4\n" : "not ok 4\n");
13print (substr($a,6,-1) eq '' ? "ok 5\n" : "not ok 5\n");
14print (substr($a,-3,1) eq 'x' ? "ok 6\n" : "not ok 6\n");
15
16$[ = 1;
17
18print (substr($a,1,3) eq 'abc' ? "ok 7\n" : "not ok 7\n");
19print (substr($a,4,3) eq 'def' ? "ok 8\n" : "not ok 8\n");
20print (substr($a,7,999) eq 'xyz' ? "ok 9\n" : "not ok 9\n");
21print (substr($a,999,999) eq '' ? "ok 10\n" : "not ok 10\n");
22print (substr($a,7,-1) eq '' ? "ok 11\n" : "not ok 11\n");
23print (substr($a,-3,1) eq 'x' ? "ok 12\n" : "not ok 12\n");
24
25$[ = 0;
26
27substr($a,3,3) = 'XYZ';
28print $a eq 'abcXYZxyz' ? "ok 13\n" : "not ok 13\n";
29substr($a,0,2) = '';
30print $a eq 'cXYZxyz' ? "ok 14\n" : "not ok 14\n";
31y/a/a/;
32substr($a,0,0) = 'ab';
33print $a eq 'abcXYZxyz' ? "ok 15\n" : "not ok 15 $a\n";
34substr($a,0,0) = '12345678';
35print $a eq '12345678abcXYZxyz' ? "ok 16\n" : "not ok 16\n";
36substr($a,-3,3) = 'def';
37print $a eq '12345678abcXYZdef' ? "ok 17\n" : "not ok 17\n";
38substr($a,-3,3) = '<';
39print $a eq '12345678abcXYZ<' ? "ok 18\n" : "not ok 18\n";
40substr($a,-1,1) = '12345678';
41print $a eq '12345678abcXYZ12345678' ? "ok 19\n" : "not ok 19\n";
42
d9d8d8de 43$a = 'abcdefxyz';
44
45print (substr($a,6) eq 'xyz' ? "ok 20\n" : "not ok 20\n");
46print (substr($a,-3) eq 'xyz' ? "ok 21\n" : "not ok 21\n");
47print (substr($a,999) eq '' ? "ok 22\n" : "not ok 22\n");