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