[inseparable changes from patch from perl5.003_15 to perl5.003_16]
[p5sagit/p5-mst-13.2.git] / t / op / array.t
CommitLineData
a687059c 1#!./perl
2
79072805 3# $RCSfile: array.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:37 $
a687059c 4
79a0689e 5print "1..36\n";
a687059c 6
7@ary = (1,2,3,4,5);
8if (join('',@ary) eq '12345') {print "ok 1\n";} else {print "not ok 1\n";}
9
10$tmp = $ary[$#ary]; --$#ary;
11if ($tmp == 5) {print "ok 2\n";} else {print "not ok 2\n";}
12if ($#ary == 3) {print "ok 3\n";} else {print "not ok 3\n";}
13if (join('',@ary) eq '1234') {print "ok 4\n";} else {print "not ok 4\n";}
14
15$[ = 1;
16@ary = (1,2,3,4,5);
17if (join('',@ary) eq '12345') {print "ok 5\n";} else {print "not ok 5\n";}
18
19$tmp = $ary[$#ary]; --$#ary;
20if ($tmp == 5) {print "ok 6\n";} else {print "not ok 6\n";}
21if ($#ary == 4) {print "ok 7\n";} else {print "not ok 7\n";}
22if (join('',@ary) eq '1234') {print "ok 8\n";} else {print "not ok 8\n";}
23
24if ($ary[5] eq '') {print "ok 9\n";} else {print "not ok 9\n";}
25
a0d0e21e 26$#ary += 1; # see if element 5 gone for good
a687059c 27if ($#ary == 5) {print "ok 10\n";} else {print "not ok 10\n";}
a0d0e21e 28if (defined $ary[5]) {print "not ok 11\n";} else {print "ok 11\n";}
a687059c 29
30$[ = 0;
31@foo = ();
32$r = join(',', $#foo, @foo);
33if ($r eq "-1") {print "ok 12\n";} else {print "not ok 12 $r\n";}
34$foo[0] = '0';
35$r = join(',', $#foo, @foo);
36if ($r eq "0,0") {print "ok 13\n";} else {print "not ok 13 $r\n";}
37$foo[2] = '2';
38$r = join(',', $#foo, @foo);
39if ($r eq "2,0,,2") {print "ok 14\n";} else {print "not ok 14 $r\n";}
40@bar = ();
41$bar[0] = '0';
42$bar[1] = '1';
43$r = join(',', $#bar, @bar);
44if ($r eq "1,0,1") {print "ok 15\n";} else {print "not ok 15 $r\n";}
45@bar = ();
46$r = join(',', $#bar, @bar);
47if ($r eq "-1") {print "ok 16\n";} else {print "not ok 16 $r\n";}
48$bar[0] = '0';
49$r = join(',', $#bar, @bar);
50if ($r eq "0,0") {print "ok 17\n";} else {print "not ok 17 $r\n";}
51$bar[2] = '2';
52$r = join(',', $#bar, @bar);
53if ($r eq "2,0,,2") {print "ok 18\n";} else {print "not ok 18 $r\n";}
54reset 'b';
55@bar = ();
56$bar[0] = '0';
57$r = join(',', $#bar, @bar);
58if ($r eq "0,0") {print "ok 19\n";} else {print "not ok 19 $r\n";}
59$bar[2] = '2';
60$r = join(',', $#bar, @bar);
61if ($r eq "2,0,,2") {print "ok 20\n";} else {print "not ok 20 $r\n";}
62
63$foo = 'now is the time';
64if (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/)) {
65 if ($F1 eq 'now' && $F2 eq 'is' && $Etc eq 'the time') {
66 print "ok 21\n";
67 }
68 else {
69 print "not ok 21\n";
70 }
71}
72else {
73 print "not ok 21\n";
74}
75
76$foo = 'lskjdf';
77if ($cnt = (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))) {
78 print "not ok 22 $cnt $F1:$F2:$Etc\n";
79}
80else {
81 print "ok 22\n";
82}
83
84%foo = ('blurfl','dyick','foo','bar','etc.','etc.');
85%bar = %foo;
86print $bar{'foo'} eq 'bar' ? "ok 23\n" : "not ok 23\n";
87%bar = ();
88print $bar{'foo'} eq '' ? "ok 24\n" : "not ok 24\n";
89(%bar,$a,$b) = (%foo,'how','now');
90print $bar{'foo'} eq 'bar' ? "ok 25\n" : "not ok 25\n";
91print $bar{'how'} eq 'now' ? "ok 26\n" : "not ok 26\n";
92@bar{keys %foo} = values %foo;
93print $bar{'foo'} eq 'bar' ? "ok 27\n" : "not ok 27\n";
94print $bar{'how'} eq 'now' ? "ok 28\n" : "not ok 28\n";
95
96@foo = grep(/e/,split(' ','now is the time for all good men to come to'));
97print join(' ',@foo) eq 'the time men come' ? "ok 29\n" : "not ok 29\n";
98
99@foo = grep(!/e/,split(' ','now is the time for all good men to come to'));
100print join(' ',@foo) eq 'now is for all good to to' ? "ok 30\n" : "not ok 30\n";
79a0689e 101
102$foo = join('',('a','b','c','d','e','f')[0..5]);
103print $foo eq 'abcdef' ? "ok 31\n" : "not ok 31\n";
104
105$foo = join('',('a','b','c','d','e','f')[0..1]);
106print $foo eq 'ab' ? "ok 32\n" : "not ok 32\n";
107
108$foo = join('',('a','b','c','d','e','f')[6]);
109print $foo eq '' ? "ok 33\n" : "not ok 33\n";
110
111@foo = ('a','b','c','d','e','f')[0,2,4];
112@bar = ('a','b','c','d','e','f')[1,3,5];
113$foo = join('',(@foo,@bar)[0..5]);
114print $foo eq 'acebdf' ? "ok 34\n" : "not ok 34\n";
115
116$foo = ('a','b','c','d','e','f')[0,2,4];
117print $foo eq 'e' ? "ok 35\n" : "not ok 35\n";
118
119$foo = ('a','b','c','d','e','f')[1];
120print $foo eq 'b' ? "ok 36\n" : "not ok 36\n";