Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
ad2250c8 | 3 | BEGIN { |
b5efbd1f | 4 | chdir 't' if -d 't'; |
1ae3d757 | 5 | require "./test.pl"; |
ad2250c8 | 6 | } |
8d063cd8 | 7 | |
3275d25a | 8 | plan(19); |
8d063cd8 | 9 | |
ad2250c8 | 10 | @array = (1, 2, 3); |
8d063cd8 | 11 | |
ad2250c8 DFC |
12 | { |
13 | no warnings 'syntax'; | |
14 | $count3 = unshift (@array); | |
15 | } | |
16 | is(join(' ',@array), '1 2 3', 'unshift null'); | |
17 | cmp_ok($count3, '==', 3, 'unshift count == 3'); | |
cba5a3b0 | 18 | |
ad2250c8 DFC |
19 | |
20 | $count3_2 = unshift (@array, ()); | |
21 | is(join(' ',@array), '1 2 3', 'unshift null empty'); | |
22 | cmp_ok($count3_2, '==', 3, 'unshift count == 3 again'); | |
23 | ||
24 | $count4 = unshift (@array, 0); | |
25 | is(join(' ',@array), '0 1 2 3', 'unshift singleton list'); | |
26 | cmp_ok($count4, '==', 4, 'unshift count == 4'); | |
27 | ||
28 | $count7 = unshift (@array, 3, 2, 1); | |
29 | is(join(' ',@array), '3 2 1 0 1 2 3', 'unshift list'); | |
30 | cmp_ok($count7, '==', 7, 'unshift count == 7'); | |
31 | ||
32 | @list = (5, 4); | |
33 | $count9 = unshift (@array, @list); | |
34 | is(join(' ',@array), '5 4 3 2 1 0 1 2 3', 'unshift array'); | |
35 | cmp_ok($count9, '==', 9, 'unshift count == 9'); | |
cba5a3b0 | 36 | |
ad2250c8 DFC |
37 | |
38 | @list = (7); | |
39 | @list2 = (6); | |
40 | $count11 = unshift (@array, @list, @list2); | |
41 | is(join(' ',@array), '7 6 5 4 3 2 1 0 1 2 3', 'unshift arrays'); | |
42 | cmp_ok($count11, '==', 11, 'unshift count == 11'); | |
43 | ||
44 | # ignoring counts | |
45 | @alpha = ('y', 'z'); | |
46 | ||
47 | { | |
48 | no warnings 'syntax'; | |
49 | unshift (@alpha); | |
50 | } | |
51 | is(join(' ',@alpha), 'y z', 'void unshift null'); | |
52 | ||
53 | unshift (@alpha, ()); | |
54 | is(join(' ',@alpha), 'y z', 'void unshift null empty'); | |
55 | ||
56 | unshift (@alpha, 'x'); | |
57 | is(join(' ',@alpha), 'x y z', 'void unshift singleton list'); | |
58 | ||
59 | unshift (@alpha, 'u', 'v', 'w'); | |
60 | is(join(' ',@alpha), 'u v w x y z', 'void unshift list'); | |
61 | ||
62 | @bet = ('s', 't'); | |
63 | unshift (@alpha, @bet); | |
64 | is(join(' ',@alpha), 's t u v w x y z', 'void unshift array'); | |
65 | ||
66 | @bet = ('q'); | |
67 | @gimel = ('r'); | |
68 | unshift (@alpha, @bet, @gimel); | |
69 | is(join(' ',@alpha), 'q r s t u v w x y z', 'void unshift arrays'); | |
8d063cd8 | 70 | |
3275d25a AC |
71 | # See RT#131000 |
72 | { | |
73 | local $@; | |
74 | my @readonly_array = 10..11; | |
75 | Internals::SvREADONLY(@readonly_array, 1); | |
76 | eval { unshift @readonly_array, () }; | |
77 | like $@, qr/^Modification of a read-only value/, | |
78 | "croak when unshifting onto readonly array"; | |
79 | } |