This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test for +x bits for all the files in exec-bit.txt
[perl5.git] / t / op / unshift.t
CommitLineData
8d063cd8
LW
1#!./perl
2
ad2250c8
DFC
3BEGIN {
4 require "test.pl";
5}
8d063cd8 6
ad2250c8 7plan(18);
8d063cd8 8
ad2250c8 9@array = (1, 2, 3);
8d063cd8 10
ad2250c8
DFC
11{
12 no warnings 'syntax';
13 $count3 = unshift (@array);
14}
15is(join(' ',@array), '1 2 3', 'unshift null');
16cmp_ok($count3, '==', 3, 'unshift count == 3');
17
18$count3_2 = unshift (@array, ());
19is(join(' ',@array), '1 2 3', 'unshift null empty');
20cmp_ok($count3_2, '==', 3, 'unshift count == 3 again');
21
22$count4 = unshift (@array, 0);
23is(join(' ',@array), '0 1 2 3', 'unshift singleton list');
24cmp_ok($count4, '==', 4, 'unshift count == 4');
25
26$count7 = unshift (@array, 3, 2, 1);
27is(join(' ',@array), '3 2 1 0 1 2 3', 'unshift list');
28cmp_ok($count7, '==', 7, 'unshift count == 7');
29
30@list = (5, 4);
31$count9 = unshift (@array, @list);
32is(join(' ',@array), '5 4 3 2 1 0 1 2 3', 'unshift array');
33cmp_ok($count9, '==', 9, 'unshift count == 9');
34
35@list = (7);
36@list2 = (6);
37$count11 = unshift (@array, @list, @list2);
38is(join(' ',@array), '7 6 5 4 3 2 1 0 1 2 3', 'unshift arrays');
39cmp_ok($count11, '==', 11, 'unshift count == 11');
40
41# ignoring counts
42@alpha = ('y', 'z');
43
44{
45 no warnings 'syntax';
46 unshift (@alpha);
47}
48is(join(' ',@alpha), 'y z', 'void unshift null');
49
50unshift (@alpha, ());
51is(join(' ',@alpha), 'y z', 'void unshift null empty');
52
53unshift (@alpha, 'x');
54is(join(' ',@alpha), 'x y z', 'void unshift singleton list');
55
56unshift (@alpha, 'u', 'v', 'w');
57is(join(' ',@alpha), 'u v w x y z', 'void unshift list');
58
59@bet = ('s', 't');
60unshift (@alpha, @bet);
61is(join(' ',@alpha), 's t u v w x y z', 'void unshift array');
62
63@bet = ('q');
64@gimel = ('r');
65unshift (@alpha, @bet, @gimel);
66is(join(' ',@alpha), 'q r s t u v w x y z', 'void unshift arrays');
8d063cd8 67