perl 3.0: (no announcement message available)
[p5sagit/p5-mst-13.2.git] / t / op.array
1 #!./perl
2
3 # $Header: op.array,v 3.0 89/10/18 15:26:55 lwall Locked $
4
5 print "1..30\n";
6
7 @ary = (1,2,3,4,5);
8 if (join('',@ary) eq '12345') {print "ok 1\n";} else {print "not ok 1\n";}
9
10 $tmp = $ary[$#ary]; --$#ary;
11 if ($tmp == 5) {print "ok 2\n";} else {print "not ok 2\n";}
12 if ($#ary == 3) {print "ok 3\n";} else {print "not ok 3\n";}
13 if (join('',@ary) eq '1234') {print "ok 4\n";} else {print "not ok 4\n";}
14
15 $[ = 1;
16 @ary = (1,2,3,4,5);
17 if (join('',@ary) eq '12345') {print "ok 5\n";} else {print "not ok 5\n";}
18
19 $tmp = $ary[$#ary]; --$#ary;
20 if ($tmp == 5) {print "ok 6\n";} else {print "not ok 6\n";}
21 if ($#ary == 4) {print "ok 7\n";} else {print "not ok 7\n";}
22 if (join('',@ary) eq '1234') {print "ok 8\n";} else {print "not ok 8\n";}
23
24 if ($ary[5] eq '') {print "ok 9\n";} else {print "not ok 9\n";}
25
26 $#ary += 1;     # see if we can recover element 5
27 if ($#ary == 5) {print "ok 10\n";} else {print "not ok 10\n";}
28 if ($ary[5] == 5) {print "ok 11\n";} else {print "not ok 11\n";}
29
30 $[ = 0;
31 @foo = ();
32 $r = join(',', $#foo, @foo);
33 if ($r eq "-1") {print "ok 12\n";} else {print "not ok 12 $r\n";}
34 $foo[0] = '0';
35 $r = join(',', $#foo, @foo);
36 if ($r eq "0,0") {print "ok 13\n";} else {print "not ok 13 $r\n";}
37 $foo[2] = '2';
38 $r = join(',', $#foo, @foo);
39 if ($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);
44 if ($r eq "1,0,1") {print "ok 15\n";} else {print "not ok 15 $r\n";}
45 @bar = ();
46 $r = join(',', $#bar, @bar);
47 if ($r eq "-1") {print "ok 16\n";} else {print "not ok 16 $r\n";}
48 $bar[0] = '0';
49 $r = join(',', $#bar, @bar);
50 if ($r eq "0,0") {print "ok 17\n";} else {print "not ok 17 $r\n";}
51 $bar[2] = '2';
52 $r = join(',', $#bar, @bar);
53 if ($r eq "2,0,,2") {print "ok 18\n";} else {print "not ok 18 $r\n";}
54 reset 'b';
55 @bar = ();
56 $bar[0] = '0';
57 $r = join(',', $#bar, @bar);
58 if ($r eq "0,0") {print "ok 19\n";} else {print "not ok 19 $r\n";}
59 $bar[2] = '2';
60 $r = join(',', $#bar, @bar);
61 if ($r eq "2,0,,2") {print "ok 20\n";} else {print "not ok 20 $r\n";}
62
63 $foo = 'now is the time';
64 if (($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 }
72 else {
73     print "not ok 21\n";
74 }
75
76 $foo = 'lskjdf';
77 if ($cnt = (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))) {
78     print "not ok 22 $cnt $F1:$F2:$Etc\n";
79 }
80 else {
81     print "ok 22\n";
82 }
83
84 %foo = ('blurfl','dyick','foo','bar','etc.','etc.');
85 %bar = %foo;
86 print $bar{'foo'} eq 'bar' ? "ok 23\n" : "not ok 23\n";
87 %bar = ();
88 print $bar{'foo'} eq '' ? "ok 24\n" : "not ok 24\n";
89 (%bar,$a,$b) = (%foo,'how','now');
90 print $bar{'foo'} eq 'bar' ? "ok 25\n" : "not ok 25\n";
91 print $bar{'how'} eq 'now' ? "ok 26\n" : "not ok 26\n";
92 @bar{keys %foo} = values %foo;
93 print $bar{'foo'} eq 'bar' ? "ok 27\n" : "not ok 27\n";
94 print $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'));
97 print 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'));
100 print join(' ',@foo) eq 'now is for all good to to' ? "ok 30\n" : "not ok 30\n";