12 # @foo, @bar, and @ary are also used from tie-stdarray after tie-ing them
16 if (join('',@ary) eq '12345') {print "ok 1\n";} else {print "not ok 1\n";}
18 $tmp = $ary[$#ary]; --$#ary;
19 if ($tmp == 5) {print "ok 2\n";} else {print "not ok 2\n";}
20 if ($#ary == 3) {print "ok 3\n";} else {print "not ok 3\n";}
21 if (join('',@ary) eq '1234') {print "ok 4\n";} else {print "not ok 4\n";}
25 if (join('',@ary) eq '12345') {print "ok 5\n";} else {print "not ok 5\n";}
27 $tmp = $ary[$#ary]; --$#ary;
28 if ($tmp == 5) {print "ok 6\n";} else {print "not ok 6\n";}
29 if ($#ary == 4) {print "ok 7\n";} else {print "not ok 7\n";}
30 if (join('',@ary) eq '1234') {print "ok 8\n";} else {print "not ok 8\n";}
32 if ($ary[5] eq '') {print "ok 9\n";} else {print "not ok 9\n";}
34 $#ary += 1; # see if element 5 gone for good
35 if ($#ary == 5) {print "ok 10\n";} else {print "not ok 10\n";}
36 if (defined $ary[5]) {print "not ok 11\n";} else {print "ok 11\n";}
40 $r = join(',', $#foo, @foo);
41 if ($r eq "-1") {print "ok 12\n";} else {print "not ok 12 $r\n";}
43 $r = join(',', $#foo, @foo);
44 if ($r eq "0,0") {print "ok 13\n";} else {print "not ok 13 $r\n";}
46 $r = join(',', $#foo, @foo);
47 if ($r eq "2,0,,2") {print "ok 14\n";} else {print "not ok 14 $r\n";}
51 $r = join(',', $#bar, @bar);
52 if ($r eq "1,0,1") {print "ok 15\n";} else {print "not ok 15 $r\n";}
54 $r = join(',', $#bar, @bar);
55 if ($r eq "-1") {print "ok 16\n";} else {print "not ok 16 $r\n";}
57 $r = join(',', $#bar, @bar);
58 if ($r eq "0,0") {print "ok 17\n";} else {print "not ok 17 $r\n";}
60 $r = join(',', $#bar, @bar);
61 if ($r eq "2,0,,2") {print "ok 18\n";} else {print "not ok 18 $r\n";}
65 $r = join(',', $#bar, @bar);
66 if ($r eq "0,0") {print "ok 19\n";} else {print "not ok 19 $r\n";}
68 $r = join(',', $#bar, @bar);
69 if ($r eq "2,0,,2") {print "ok 20\n";} else {print "not ok 20 $r\n";}
71 $foo = 'now is the time';
72 if (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/)) {
73 if ($F1 eq 'now' && $F2 eq 'is' && $Etc eq 'the time') {
85 if ($cnt = (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))) {
86 print "not ok 22 $cnt $F1:$F2:$Etc\n";
92 %foo = ('blurfl','dyick','foo','bar','etc.','etc.');
94 print $bar{'foo'} eq 'bar' ? "ok 23\n" : "not ok 23\n";
96 print $bar{'foo'} eq '' ? "ok 24\n" : "not ok 24\n";
97 (%bar,$a,$b) = (%foo,'how','now');
98 print $bar{'foo'} eq 'bar' ? "ok 25\n" : "not ok 25\n";
99 print $bar{'how'} eq 'now' ? "ok 26\n" : "not ok 26\n";
100 @bar{keys %foo} = values %foo;
101 print $bar{'foo'} eq 'bar' ? "ok 27\n" : "not ok 27\n";
102 print $bar{'how'} eq 'now' ? "ok 28\n" : "not ok 28\n";
104 @foo = grep(/e/,split(' ','now is the time for all good men to come to'));
105 print join(' ',@foo) eq 'the time men come' ? "ok 29\n" : "not ok 29\n";
107 @foo = grep(!/e/,split(' ','now is the time for all good men to come to'));
108 print join(' ',@foo) eq 'now is for all good to to' ? "ok 30\n" : "not ok 30\n";
110 $foo = join('',('a','b','c','d','e','f')[0..5]);
111 print $foo eq 'abcdef' ? "ok 31\n" : "not ok 31\n";
113 $foo = join('',('a','b','c','d','e','f')[0..1]);
114 print $foo eq 'ab' ? "ok 32\n" : "not ok 32\n";
116 $foo = join('',('a','b','c','d','e','f')[6]);
117 print $foo eq '' ? "ok 33\n" : "not ok 33\n";
119 @foo = ('a','b','c','d','e','f')[0,2,4];
120 @bar = ('a','b','c','d','e','f')[1,3,5];
121 $foo = join('',(@foo,@bar)[0..5]);
122 print $foo eq 'acebdf' ? "ok 34\n" : "not ok 34\n";
124 $foo = ('a','b','c','d','e','f')[0,2,4];
125 print $foo eq 'e' ? "ok 35\n" : "not ok 35\n";
127 $foo = ('a','b','c','d','e','f')[1];
128 print $foo eq 'b' ? "ok 36\n" : "not ok 36\n";
130 @foo = ( 'foo', 'bar', 'burbl');
132 print $#foo == 3 ? "ok 37\n" : "not ok 37\n";
134 # various AASSIGN_COMMON checks (see newASSIGNOP() in op.c)
137 sub t { ++$test; print "not " unless $_[0]; print "ok $test\n"; }
140 t("@foo" eq "foo bar burbl blah"); # 38
143 t("@foo" eq "bar burbl blah"); # 39
145 @foo = ('XXX',@foo, 'YYY');
146 t("@foo" eq "XXX bar burbl blah YYY"); # 40
148 @foo = @foo = qw(foo b\a\r bu\\rbl blah);
149 t("@foo" eq 'foo b\a\r bu\\rbl blah'); # 41
151 @bar = @foo = qw(foo bar); # 42
152 t("@foo" eq "foo bar");
153 t("@bar" eq "foo bar"); # 43
155 # try the same with local
156 # XXX tie-stdarray fails the tests involving local, so we use
157 # different variable names to escape the 'tie'
159 @bee = ( 'foo', 'bar', 'burbl', 'blah');
163 t("@bee" eq "foo bar burbl blah"); # 44
165 local (undef,@bee) = @bee;
166 t("@bee" eq "bar burbl blah"); # 45
168 local @bee = ('XXX',@bee,'YYY');
169 t("@bee" eq "XXX bar burbl blah YYY"); # 46
171 local @bee = local(@bee) = qw(foo bar burbl blah);
172 t("@bee" eq "foo bar burbl blah"); # 47
174 local (@bim) = local(@bee) = qw(foo bar);
175 t("@bee" eq "foo bar"); # 48
176 t("@bim" eq "foo bar"); # 49
178 t("@bee" eq "foo bar burbl blah"); # 50
180 t("@bee" eq "XXX bar burbl blah YYY"); # 51
182 t("@bee" eq "bar burbl blah"); # 52
184 t("@bee" eq "foo bar burbl blah"); # 53
187 # try the same with my
191 t("@bee" eq "foo bar burbl blah"); # 54
193 my (undef,@bee) = @bee;
194 t("@bee" eq "bar burbl blah"); # 55
196 my @bee = ('XXX',@bee,'YYY');
197 t("@bee" eq "XXX bar burbl blah YYY"); # 56
199 my @bee = my @bee = qw(foo bar burbl blah);
200 t("@bee" eq "foo bar burbl blah"); # 57
202 my (@bim) = my(@bee) = qw(foo bar);
203 t("@bee" eq "foo bar"); # 58
204 t("@bim" eq "foo bar"); # 59
206 t("@bee" eq "foo bar burbl blah"); # 60
208 t("@bee" eq "XXX bar burbl blah YYY"); # 61
210 t("@bee" eq "bar burbl blah"); # 62
212 t("@bee" eq "foo bar burbl blah"); # 63
215 # make sure reification behaves
217 sub reify { $_[1] = ++$t; print "@_\n"; }
221 # qw() is no more a runtime split, it's compiletime.
222 print "not " unless qw(foo bar snorfle)[2] eq 'snorfle';
225 @ary = (12,23,34,45,56);
227 print "not " unless shift(@ary) == 12;
230 print "not " unless pop(@ary) == 56;
233 print "not " unless push(@ary,56) == 4;
236 print "not " unless unshift(@ary,12) == 5;
241 $foo[1] eq "a" or print "not ";
244 # $[ should have the same effect regardless of whether the aelem
245 # op is optimized to aelemfast.
250 print "not " unless $tary[5] == $tary[$five];
260 # bugid #15439 - clearing an array calls destructors which may try
261 # to modify the array - caused 'Attempt to free unreferenced scalar'
265 sub X::DESTROY { @a = () }
266 @a = (bless {}, 'X');
273 print "# $got\nnot " unless $got eq '';