This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
applied patch, tweak for threads awareness
[perl5.git] / t / op / delete.t
CommitLineData
378cc40b
LW
1#!./perl
2
79072805 3# $RCSfile: delete.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:44 $
378cc40b 4
5f05dabc 5print "1..16\n";
378cc40b
LW
6
7$foo{1} = 'a';
8$foo{2} = 'b';
9$foo{3} = 'c';
5f05dabc 10$foo{4} = 'd';
11$foo{5} = 'e';
378cc40b
LW
12
13$foo = delete $foo{2};
14
a687059c
LW
15if ($foo eq 'b') {print "ok 1\n";} else {print "not ok 1 $foo\n";}
16if ($foo{2} eq '') {print "ok 2\n";} else {print "not ok 2 $foo{2}\n";}
378cc40b
LW
17if ($foo{1} eq 'a') {print "ok 3\n";} else {print "not ok 3\n";}
18if ($foo{3} eq 'c') {print "ok 4\n";} else {print "not ok 4\n";}
5f05dabc 19if ($foo{4} eq 'd') {print "ok 5\n";} else {print "not ok 5\n";}
20if ($foo{5} eq 'e') {print "ok 6\n";} else {print "not ok 6\n";}
21
22@foo = delete @foo{4, 5};
23
24if (@foo == 2) {print "ok 7\n";} else {print "not ok 7 ", @foo+0, "\n";}
25if ($foo[0] eq 'd') {print "ok 8\n";} else {print "not ok 8 ", $foo[0], "\n";}
26if ($foo[1] eq 'e') {print "ok 9\n";} else {print "not ok 9 ", $foo[1], "\n";}
27if ($foo{4} eq '') {print "ok 10\n";} else {print "not ok 10 $foo{4}\n";}
28if ($foo{5} eq '') {print "ok 11\n";} else {print "not ok 11 $foo{5}\n";}
29if ($foo{1} eq 'a') {print "ok 12\n";} else {print "not ok 12\n";}
30if ($foo{3} eq 'c') {print "ok 13\n";} else {print "not ok 13\n";}
378cc40b 31
c6aa4a32 32$foo = join('',values(%foo));
5f05dabc 33if ($foo eq 'ac' || $foo eq 'ca') {print "ok 14\n";} else {print "not ok 14\n";}
378cc40b 34
c6aa4a32 35foreach $key (keys %foo) {
378cc40b
LW
36 delete $foo{$key};
37}
38
39$foo{'foo'} = 'x';
40$foo{'bar'} = 'y';
41
c6aa4a32 42$foo = join('',values(%foo));
5f05dabc 43print +($foo eq 'xy' || $foo eq 'yx') ? "ok 15\n" : "not ok 15\n";
a0d0e21e
LW
44
45$refhash{"top"}->{"foo"} = "FOO";
46$refhash{"top"}->{"bar"} = "BAR";
47
48delete $refhash{"top"}->{"bar"};
49@list = keys %{$refhash{"top"}};
50
5f05dabc 51print "@list" eq "foo" ? "ok 16\n" : "not ok 16 @list\n";