Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
ad2250c8 DFC |
3 | BEGIN { |
4 | require "test.pl"; | |
5 | } | |
8d063cd8 | 6 | |
cba5a3b0 | 7 | plan(36); |
8d063cd8 | 8 | |
ad2250c8 | 9 | @array = (1, 2, 3); |
cba5a3b0 | 10 | $aref = [1, 2, 3]; |
8d063cd8 | 11 | |
d401967c | 12 | no warnings 'experimental::autoderef'; |
ad2250c8 DFC |
13 | { |
14 | no warnings 'syntax'; | |
15 | $count3 = unshift (@array); | |
cba5a3b0 | 16 | $count3r = unshift ($aref); |
ad2250c8 DFC |
17 | } |
18 | is(join(' ',@array), '1 2 3', 'unshift null'); | |
19 | cmp_ok($count3, '==', 3, 'unshift count == 3'); | |
cba5a3b0 DG |
20 | is(join(' ',@$aref), '1 2 3', 'unshift null (ref)'); |
21 | cmp_ok($count3r, '==', 3, 'unshift count == 3 (ref)'); | |
22 | ||
ad2250c8 DFC |
23 | |
24 | $count3_2 = unshift (@array, ()); | |
25 | is(join(' ',@array), '1 2 3', 'unshift null empty'); | |
26 | cmp_ok($count3_2, '==', 3, 'unshift count == 3 again'); | |
cba5a3b0 DG |
27 | $count3_2r = unshift ($aref, ()); |
28 | is(join(' ',@$aref), '1 2 3', 'unshift null empty (ref)'); | |
29 | cmp_ok($count3_2r, '==', 3, 'unshift count == 3 again (ref)'); | |
ad2250c8 DFC |
30 | |
31 | $count4 = unshift (@array, 0); | |
32 | is(join(' ',@array), '0 1 2 3', 'unshift singleton list'); | |
33 | cmp_ok($count4, '==', 4, 'unshift count == 4'); | |
cba5a3b0 DG |
34 | $count4r = unshift ($aref, 0); |
35 | is(join(' ',@$aref), '0 1 2 3', 'unshift singleton list (ref)'); | |
36 | cmp_ok($count4r, '==', 4, 'unshift count == 4 (ref)'); | |
ad2250c8 DFC |
37 | |
38 | $count7 = unshift (@array, 3, 2, 1); | |
39 | is(join(' ',@array), '3 2 1 0 1 2 3', 'unshift list'); | |
40 | cmp_ok($count7, '==', 7, 'unshift count == 7'); | |
cba5a3b0 DG |
41 | $count7r = unshift ($aref, 3, 2, 1); |
42 | is(join(' ',@$aref), '3 2 1 0 1 2 3', 'unshift list (ref)'); | |
43 | cmp_ok($count7r, '==', 7, 'unshift count == 7 (ref)'); | |
ad2250c8 DFC |
44 | |
45 | @list = (5, 4); | |
46 | $count9 = unshift (@array, @list); | |
47 | is(join(' ',@array), '5 4 3 2 1 0 1 2 3', 'unshift array'); | |
48 | cmp_ok($count9, '==', 9, 'unshift count == 9'); | |
cba5a3b0 DG |
49 | $count9r = unshift ($aref, @list); |
50 | is(join(' ',@$aref), '5 4 3 2 1 0 1 2 3', 'unshift array (ref)'); | |
51 | cmp_ok($count9r, '==', 9, 'unshift count == 9 (ref)'); | |
52 | ||
ad2250c8 DFC |
53 | |
54 | @list = (7); | |
55 | @list2 = (6); | |
56 | $count11 = unshift (@array, @list, @list2); | |
57 | is(join(' ',@array), '7 6 5 4 3 2 1 0 1 2 3', 'unshift arrays'); | |
58 | cmp_ok($count11, '==', 11, 'unshift count == 11'); | |
cba5a3b0 DG |
59 | $count11r = unshift ($aref, @list, @list2); |
60 | is(join(' ',@$aref), '7 6 5 4 3 2 1 0 1 2 3', 'unshift arrays (ref)'); | |
61 | cmp_ok($count11r, '==', 11, 'unshift count == 11 (ref)'); | |
ad2250c8 DFC |
62 | |
63 | # ignoring counts | |
64 | @alpha = ('y', 'z'); | |
cba5a3b0 | 65 | $alpharef = ['y', 'z']; |
ad2250c8 DFC |
66 | |
67 | { | |
68 | no warnings 'syntax'; | |
69 | unshift (@alpha); | |
cba5a3b0 | 70 | unshift ($alpharef); |
ad2250c8 DFC |
71 | } |
72 | is(join(' ',@alpha), 'y z', 'void unshift null'); | |
cba5a3b0 | 73 | is(join(' ',@$alpharef), 'y z', 'void unshift null (ref)'); |
ad2250c8 DFC |
74 | |
75 | unshift (@alpha, ()); | |
76 | is(join(' ',@alpha), 'y z', 'void unshift null empty'); | |
cba5a3b0 DG |
77 | unshift ($alpharef, ()); |
78 | is(join(' ',@$alpharef), 'y z', 'void unshift null empty (ref)'); | |
ad2250c8 DFC |
79 | |
80 | unshift (@alpha, 'x'); | |
81 | is(join(' ',@alpha), 'x y z', 'void unshift singleton list'); | |
cba5a3b0 DG |
82 | unshift ($alpharef, 'x'); |
83 | is(join(' ',@$alpharef), 'x y z', 'void unshift singleton list (ref)'); | |
ad2250c8 DFC |
84 | |
85 | unshift (@alpha, 'u', 'v', 'w'); | |
86 | is(join(' ',@alpha), 'u v w x y z', 'void unshift list'); | |
cba5a3b0 DG |
87 | unshift ($alpharef, 'u', 'v', 'w'); |
88 | is(join(' ',@$alpharef), 'u v w x y z', 'void unshift list (ref)'); | |
ad2250c8 DFC |
89 | |
90 | @bet = ('s', 't'); | |
91 | unshift (@alpha, @bet); | |
92 | is(join(' ',@alpha), 's t u v w x y z', 'void unshift array'); | |
cba5a3b0 DG |
93 | unshift ($alpharef, @bet); |
94 | is(join(' ',@$alpharef), 's t u v w x y z', 'void unshift array (ref)'); | |
ad2250c8 DFC |
95 | |
96 | @bet = ('q'); | |
97 | @gimel = ('r'); | |
98 | unshift (@alpha, @bet, @gimel); | |
99 | is(join(' ',@alpha), 'q r s t u v w x y z', 'void unshift arrays'); | |
cba5a3b0 DG |
100 | unshift ($alpharef, @bet, @gimel); |
101 | is(join(' ',@$alpharef), 'q r s t u v w x y z', 'void unshift arrays (ref)'); | |
8d063cd8 | 102 |