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