9 @tests = split(/\n/, <<EOF);
11 0 0 a b c, , a b c 0 1 2 3 4 5 6 7
12 8 0 a b c, , 0 1 2 3 4 5 6 7 a b c
13 7 0 6.5, , 0 1 2 3 4 5 6 6.5 7
14 1 0 a b c d e f g h i j,, 0 a b c d e f g h i j 1 2 3 4 5 6 7
15 0 1 a, 0, a 1 2 3 4 5 6 7
16 1 6 x y z, 1 2 3 4 5 6, 0 x y z 7
17 0 7 x y z, 0 1 2 3 4 5 6, x y z 7
18 1 7 x y z, 1 2 3 4 5 6 7, 0 x y z
23 plan tests => 14 + @tests*4;
24 die "blech" unless @tests;
28 is( join(':',@x), '1:2:3:1:2:3', 'push array onto array');
30 is( join(':',@x), '1:2:3:1:2:3:4', 'push integer onto array');
32 no warnings 'experimental::autoderef';
34 # test for push/pop on arrayref
36 is( join(':',@x), '1:2:3:1:2:3:4:5', 'push arrayref');
38 is( join(':',@x), '1:2:3:1:2:3:4', 'pop arrayref');
40 # test autovivification
41 push @$undef1, 1, 2, 3;
42 is( join(':',@$undef1), '1:2:3', 'autovivify array');
44 # test push on undef (error)
45 eval { push $undef2, 1, 2, 3 };
46 like( $@, qr/Not an ARRAY/, 'push on undef generates an error');
49 use constant CONST_ARRAYREF => [qw/a b c/];
50 push CONST_ARRAYREF(), qw/d e f/;
51 is( join(':',@{CONST_ARRAYREF()}), 'a:b:c:d:e:f', 'test constant');
53 # test implicit dereference errors
54 eval "push 42, 0, 1, 2, 3";
55 like ( $@, qr/must be array/, 'push onto a literal integer');
58 eval { push $hashref, 0, 1, 2, 3 };
59 like( $@, qr/Not an ARRAY reference/, 'push onto a hashref');
61 eval { push bless([]), 0, 1, 2, 3 };
62 like( $@, qr/Not an unblessed ARRAY reference/, 'push onto a blessed array ref');
68 my($first, $second) = ([1], [2]);
69 sub two_things { return +($first, $second) }
71 is( join(':',@$first), '1', "\$first = [ @$first ];");
72 is( join(':',@$second), '2:3', "\$second = [ @$second ]");
74 push @{ two_things() }, 4;
75 is( join(':',@$first), '1', "\$first = [ @$first ];");
76 is( join(':',@$second), '2:3:4', "\$second = [ @$second ]");
79 foreach $line (@tests) {
80 ($list,$get,$leave) = split(/,\t*/,$line);
81 ($pos, $len, @list) = split(' ',$list);
82 @get = split(' ',$get);
83 @leave = split(' ',$leave);
84 @x = (0,1,2,3,4,5,6,7);
85 $y = [0,1,2,3,4,5,6,7];
87 @got = splice(@x, $pos, $len, @list);
88 @got2 = splice($y, $pos, $len, @list);
91 @got = splice(@x, $pos);
92 @got2 = splice($y, $pos);
94 is(join(':',@got), join(':',@get), "got: @got == @get");
95 is(join(':',@x), join(':',@leave), "left: @x == @leave");
96 is(join(':',@got2), join(':',@get), "ref got: @got2 == @get");
97 is(join(':',@$y), join(':',@leave), "ref left: @$y == @leave");
100 1; # this file is require'd by lib/tie-stdpush.t