1N/A#!./perl
1N/A
1N/Aprint "1..12\n";
1N/A
1N/A@a = (1..10);
1N/A
1N/Asub j { join(":",@_) }
1N/A
1N/Aprint "not " unless j(splice(@a,@a,0,11,12)) eq "" && j(@a) eq j(1..12);
1N/Aprint "ok 1\n";
1N/A
1N/Aprint "not " unless j(splice(@a,-1)) eq "12" && j(@a) eq j(1..11);
1N/Aprint "ok 2\n";
1N/A
1N/Aprint "not " unless j(splice(@a,0,1)) eq "1" && j(@a) eq j(2..11);
1N/Aprint "ok 3\n";
1N/A
1N/Aprint "not " unless j(splice(@a,0,0,0,1)) eq "" && j(@a) eq j(0..11);
1N/Aprint "ok 4\n";
1N/A
1N/Aprint "not " unless j(splice(@a,5,1,5)) eq "5" && j(@a) eq j(0..11);
1N/Aprint "ok 5\n";
1N/A
1N/Aprint "not " unless j(splice(@a, @a, 0, 12, 13)) eq "" && j(@a) eq j(0..13);
1N/Aprint "ok 6\n";
1N/A
1N/Aprint "not " unless j(splice(@a, -@a, @a, 1, 2, 3)) eq j(0..13) && j(@a) eq j(1..3);
1N/Aprint "ok 7\n";
1N/A
1N/Aprint "not " unless j(splice(@a, 1, -1, 7, 7)) eq "2" && j(@a) eq j(1,7,7,3);
1N/Aprint "ok 8\n";
1N/A
1N/Aprint "not " unless j(splice(@a,-3,-2,2)) eq j(7) && j(@a) eq j(1,2,7,3);
1N/Aprint "ok 9\n";
1N/A
1N/A# Bug 20000223.001 - no test for splice(@array). Destructive test!
1N/Aprint "not " unless j(splice(@a)) eq j(1,2,7,3) && j(@a) eq '';
1N/Aprint "ok 10\n";
1N/A
1N/A# Tests 11 and 12:
1N/A# [ID 20010711.005] in Tie::Array, SPLICE ignores context, breaking SHIFT
1N/A
1N/Amy $foo;
1N/A
1N/A@a = ('red', 'green', 'blue');
1N/A$foo = splice @a, 1, 2;
1N/Aprint "not " unless $foo eq 'blue';
1N/Aprint "ok 11\n";
1N/A
1N/A@a = ('red', 'green', 'blue');
1N/A$foo = shift @a;
1N/Aprint "not " unless $foo eq 'red';
1N/Aprint "ok 12\n";
1N/A