This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Brendan Byrd is now a perl AUTHOR
[perl5.git] / ext / arybase / t / splice.t
1 use warnings; no warnings 'deprecated';
2 use strict;
3
4 use Test::More tests => 23;
5
6 our @t;
7 our @i5 = (3, 3, 3, 3, 3);
8
9 $[ = 3;
10
11 @t = qw(a b c d e f);
12 is_deeply [ scalar splice @t ], [qw(f)];
13 is_deeply \@t, [];
14
15 @t = qw(a b c d e f);
16 is_deeply [ splice @t ], [qw(a b c d e f)];
17 is_deeply \@t, [];
18
19 @t = qw(a b c d e f);
20 is_deeply [ scalar splice @t, 5 ], [qw(f)];
21 is_deeply \@t, [qw(a b)];
22
23 @t = qw(a b c d e f);
24 is_deeply [ splice @t, 5 ], [qw(c d e f)];
25 is_deeply \@t, [qw(a b)];
26
27 @t = qw(a b c d e f);
28 is_deeply [ scalar splice @t, @i5 ], [qw(f)];
29 is_deeply \@t, [qw(a b)];
30
31 @t = qw(a b c d e f);
32 is_deeply [ splice @t, @i5 ], [qw(c d e f)];
33 is_deeply \@t, [qw(a b)];
34
35 @t = qw(a b c d e f);
36 is_deeply [ scalar splice @t, 5, 2 ], [qw(d)];
37 is_deeply \@t, [qw(a b e f)];
38
39 @t = qw(a b c d e f);
40 is_deeply [ splice @t, 5, 2 ], [qw(c d)];
41 is_deeply \@t, [qw(a b e f)];
42
43 @t = qw(a b c d e f);
44 is_deeply [ scalar splice @t, 5, 2, qw(x y z) ], [qw(d)];
45 is_deeply \@t, [qw(a b x y z e f)];
46
47 @t = qw(a b c d e f);
48 is_deeply [ splice @t, 5, 2, qw(x y z) ], [qw(c d)];
49 is_deeply \@t, [qw(a b x y z e f)];
50
51 @t = qw(a b c d e f);
52 splice @t, -4, 1;
53 is_deeply \@t, [qw(a b d e f)];
54
55 @t = qw(a b c d e f);
56 splice @t, 1, 1;
57 is_deeply \@t, [qw(a b c d f)];
58
59 $[ = -3;
60
61 @t = qw(a b c d e f);
62 splice @t, -3, 1;
63 is_deeply \@t, [qw(b c d e f)];
64
65 1;