6 set_up_inc( qw(. ../lib) );
11 # delete() on hash elements
21 $foo = delete $foo{2};
23 cmp_ok($foo,'eq','b','delete 2');
24 ok(!(exists $foo{2}),'b absent');
25 cmp_ok($foo{1},'eq','a','a exists');
26 cmp_ok($foo{3},'eq','c','c exists');
27 cmp_ok($foo{4},'eq','d','d exists');
28 cmp_ok($foo{5},'eq','e','e exists');
30 @foo = delete @foo{4, 5};
32 cmp_ok(scalar(@foo),'==',2,'deleted slice');
33 cmp_ok($foo[0],'eq','d','slice 1');
34 cmp_ok($foo[1],'eq','e','slice 2');
35 ok(!(exists $foo{4}),'d absent');
36 ok(!(exists $foo{5}),'e absent');
37 cmp_ok($foo{1},'eq','a','a still exists');
38 cmp_ok($foo{3},'eq','c','c still exists');
40 @foo = delete %foo{6,7};
42 cmp_ok(scalar(@foo),'==',4,'deleted kvslice');
43 cmp_ok($foo[0],'eq','6','slice k1');
44 cmp_ok($foo[1],'eq','f','slice v1');
45 cmp_ok($foo[2],'eq','7','slice k2');
46 cmp_ok($foo[3],'eq','g','slice v2');
47 ok(!(exists $foo{5}),'f absent');
48 ok(!(exists $foo{6}),'g absent');
49 cmp_ok($foo{1},'eq','a','a still exists');
50 cmp_ok($foo{3},'eq','c','c still exists');
52 $foo = join('',values(%foo));
53 ok($foo eq 'ac' || $foo eq 'ca','remaining keys');
55 foreach $key (keys %foo) {
62 $foo = join('',values(%foo));
63 ok($foo eq 'xy' || $foo eq 'yx','fresh keys');
65 $refhash{"top"}->{"foo"} = "FOO";
66 $refhash{"top"}->{"bar"} = "BAR";
68 delete $refhash{"top"}->{"bar"};
69 @list = keys %{$refhash{"top"}};
71 cmp_ok("@list",'eq',"foo", 'autoviv and delete hashref');
75 my($a) = \(values %a);
77 my $c = \delete $a{bar};
79 ok($a == $b && $b == $c,'a b c equivalent');
82 # delete() on array elements
93 $foo = delete $foo[2];
95 cmp_ok($foo,'eq','b','ary delete 2');
96 ok(!(exists $foo[2]),'ary b absent');
97 cmp_ok($foo[1],'eq','a','ary a exists');
98 cmp_ok($foo[3],'eq','c','ary c exists');
99 cmp_ok($foo[4],'eq','d','ary d exists');
100 cmp_ok($foo[5],'eq','e','ary e exists');
102 @bar = delete @foo[4,5];
104 cmp_ok(scalar(@bar),'==',2,'ary deleted slice');
105 cmp_ok($bar[0],'eq','d','ary slice 1');
106 cmp_ok($bar[1],'eq','e','ary slice 2');
107 ok(!(exists $foo[4]),'ary d absent');
108 ok(!(exists $foo[5]),'ary e absent');
109 cmp_ok($foo[1],'eq','a','ary a still exists');
110 cmp_ok($foo[3],'eq','c','ary c still exists');
112 @bar = delete %foo[6,7];
114 cmp_ok(scalar(@bar),'==',4,'deleted kvslice');
115 cmp_ok($bar[0],'eq','6','slice k1');
116 cmp_ok($bar[1],'eq','f','slice v1');
117 cmp_ok($bar[2],'eq','7','slice k2');
118 cmp_ok($bar[3],'eq','g','slice v2');
119 ok(!(exists $bar[5]),'f absent');
120 ok(!(exists $bar[6]),'g absent');
121 cmp_ok($foo[1],'eq','a','a still exists');
122 cmp_ok($foo[3],'eq','c','c still exists');
124 $foo = join('',@foo);
125 cmp_ok($foo,'eq','ac','ary elems');
126 cmp_ok(scalar(@foo),'==',4,'four is the number thou shalt count');
128 foreach $key (0 .. $#foo) {
132 cmp_ok(scalar(@foo),'==',0,'and then there were none');
138 cmp_ok($foo,'eq','x y','two fresh');
140 $refary[0]->[0] = "FOO";
141 $refary[0]->[3] = "BAR";
143 delete $refary[0]->[3];
145 cmp_ok( scalar(@{$refary[0]}),'==',1,'one down');
151 my $c = \delete $a[bar];
153 ok($a == $b && $b == $c,'a b c also equivalent');
158 my ($x,$y) = (1, scalar delete @h{()});
159 ok(!defined($y),q([perl #29127] scalar delete of empty slice returned garbage));
164 sub X::DESTROY { $x++ }
167 $a[0] = bless [], 'X';
168 my $y = delete $a[0];
170 cmp_ok($x,'==',1,q([perl #30733] array delete didn't free returned element));