This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #93320] localising @DB::args leads to coredump
[perl5.git] / t / op / unshift.t
1 #!./perl
2
3 BEGIN {
4     require "test.pl";
5 }
6
7 plan(36);
8
9 @array = (1, 2, 3);
10 $aref  = [1, 2, 3];
11
12 {
13     no warnings 'syntax';
14     $count3 = unshift (@array);
15     $count3r = unshift ($aref);
16 }
17 is(join(' ',@array), '1 2 3', 'unshift null');
18 cmp_ok($count3, '==', 3, 'unshift count == 3');
19 is(join(' ',@$aref), '1 2 3', 'unshift null (ref)');
20 cmp_ok($count3r, '==', 3, 'unshift count == 3 (ref)');
21
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');
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)');
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');
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)');
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');
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)');
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');
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
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');
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)');
61
62 # ignoring counts
63 @alpha = ('y', 'z');
64 $alpharef = ['y', 'z'];
65
66 {
67     no warnings 'syntax';
68     unshift (@alpha);
69     unshift ($alpharef);
70 }
71 is(join(' ',@alpha), 'y z', 'void unshift null');
72 is(join(' ',@$alpharef), 'y z', 'void unshift null (ref)');
73
74 unshift (@alpha, ());
75 is(join(' ',@alpha), 'y z', 'void unshift null empty');
76 unshift ($alpharef, ());
77 is(join(' ',@$alpharef), 'y z', 'void unshift null empty (ref)');
78
79 unshift (@alpha, 'x');
80 is(join(' ',@alpha), 'x y z', 'void unshift singleton list');
81 unshift ($alpharef, 'x');
82 is(join(' ',@$alpharef), 'x y z', 'void unshift singleton list (ref)');
83
84 unshift (@alpha, 'u', 'v', 'w');
85 is(join(' ',@alpha), 'u v w x y z', 'void unshift list');
86 unshift ($alpharef, 'u', 'v', 'w');
87 is(join(' ',@$alpharef), 'u v w x y z', 'void unshift list (ref)');
88
89 @bet = ('s', 't');
90 unshift (@alpha, @bet);
91 is(join(' ',@alpha), 's t u v w x y z', 'void unshift array');
92 unshift ($alpharef, @bet);
93 is(join(' ',@$alpharef), 's t u v w x y z', 'void unshift array (ref)');
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');
99 unshift ($alpharef, @bet, @gimel);
100 is(join(' ',@$alpharef), 'q r s t u v w x y z', 'void unshift arrays (ref)');
101