Move the require './test.pl' to the end of t/comp/hints.t
[p5sagit/p5-mst-13.2.git] / t / op / splice.t
CommitLineData
48cdf507 1#!./perl
2
50528de0 3print "1..18\n";
48cdf507 4
5@a = (1..10);
6
7sub j { join(":",@_) }
8
9print "not " unless j(splice(@a,@a,0,11,12)) eq "" && j(@a) eq j(1..12);
10print "ok 1\n";
11
12print "not " unless j(splice(@a,-1)) eq "12" && j(@a) eq j(1..11);
13print "ok 2\n";
14
15print "not " unless j(splice(@a,0,1)) eq "1" && j(@a) eq j(2..11);
16print "ok 3\n";
17
18print "not " unless j(splice(@a,0,0,0,1)) eq "" && j(@a) eq j(0..11);
19print "ok 4\n";
20
21print "not " unless j(splice(@a,5,1,5)) eq "5" && j(@a) eq j(0..11);
22print "ok 5\n";
23
8cbc2e3b 24print "not " unless j(splice(@a, @a, 0, 12, 13)) eq "" && j(@a) eq j(0..13);
48cdf507 25print "ok 6\n";
26
27print "not " unless j(splice(@a, -@a, @a, 1, 2, 3)) eq j(0..13) && j(@a) eq j(1..3);
28print "ok 7\n";
29
30print "not " unless j(splice(@a, 1, -1, 7, 7)) eq "2" && j(@a) eq j(1,7,7,3);
31print "ok 8\n";
32
33print "not " unless j(splice(@a,-3,-2,2)) eq j(7) && j(@a) eq j(1,2,7,3);
34print "ok 9\n";
f507e126 35
36# Bug 20000223.001 - no test for splice(@array). Destructive test!
37print "not " unless j(splice(@a)) eq j(1,2,7,3) && j(@a) eq '';
38print "ok 10\n";
39
aae9faae 40# Tests 11 and 12:
41# [ID 20010711.005] in Tie::Array, SPLICE ignores context, breaking SHIFT
42
43my $foo;
44
45@a = ('red', 'green', 'blue');
46$foo = splice @a, 1, 2;
47print "not " unless $foo eq 'blue';
48print "ok 11\n";
49
50@a = ('red', 'green', 'blue');
51$foo = shift @a;
52print "not " unless $foo eq 'red';
53print "ok 12\n";
f507e126 54
50528de0 55# Bug [perl #30568] - insertions of deleted elements
56@a = (1, 2, 3);
57splice( @a, 0, 3, $a[1], $a[0] );
58print "not " unless j(@a) eq j(2,1);
59print "ok 13\n";
60
61@a = (1, 2, 3);
62splice( @a, 0, 3 ,$a[0], $a[1] );
63print "not " unless j(@a) eq j(1,2);
64print "ok 14\n";
65
66@a = (1, 2, 3);
67splice( @a, 0, 3 ,$a[2], $a[1], $a[0] );
68print "not " unless j(@a) eq j(3,2,1);
69print "ok 15\n";
70
71@a = (1, 2, 3);
72splice( @a, 0, 3, $a[0], $a[1], $a[2], $a[0], $a[1], $a[2] );
73print "not " unless j(@a) eq j(1,2,3,1,2,3);
74print "ok 16\n";
75
76@a = (1, 2, 3);
77splice( @a, 1, 2, $a[2], $a[1] );
78print "not " unless j(@a) eq j(1,3,2);
79print "ok 17\n";
80
81@a = (1, 2, 3);
82splice( @a, 1, 2, $a[1], $a[1] );
83print "not " unless j(@a) eq j(1,2,2);
84print "ok 18\n";