This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
test case for change#4694
[perl5.git] / t / op / delete.t
1 #!./perl
2
3 print "1..17\n";
4
5 $foo{1} = 'a';
6 $foo{2} = 'b';
7 $foo{3} = 'c';
8 $foo{4} = 'd';
9 $foo{5} = 'e';
10
11 $foo = delete $foo{2};
12
13 if ($foo eq 'b') {print "ok 1\n";} else {print "not ok 1 $foo\n";}
14 if ($foo{2} eq '') {print "ok 2\n";} else {print "not ok 2 $foo{2}\n";}
15 if ($foo{1} eq 'a') {print "ok 3\n";} else {print "not ok 3\n";}
16 if ($foo{3} eq 'c') {print "ok 4\n";} else {print "not ok 4\n";}
17 if ($foo{4} eq 'd') {print "ok 5\n";} else {print "not ok 5\n";}
18 if ($foo{5} eq 'e') {print "ok 6\n";} else {print "not ok 6\n";}
19
20 @foo = delete @foo{4, 5};
21
22 if (@foo == 2) {print "ok 7\n";} else {print "not ok 7 ", @foo+0, "\n";}
23 if ($foo[0] eq 'd') {print "ok 8\n";} else {print "not ok 8 ", $foo[0], "\n";}
24 if ($foo[1] eq 'e') {print "ok 9\n";} else {print "not ok 9 ", $foo[1], "\n";}
25 if ($foo{4} eq '') {print "ok 10\n";} else {print "not ok 10 $foo{4}\n";}
26 if ($foo{5} eq '') {print "ok 11\n";} else {print "not ok 11 $foo{5}\n";}
27 if ($foo{1} eq 'a') {print "ok 12\n";} else {print "not ok 12\n";}
28 if ($foo{3} eq 'c') {print "ok 13\n";} else {print "not ok 13\n";}
29
30 $foo = join('',values(%foo));
31 if ($foo eq 'ac' || $foo eq 'ca') {print "ok 14\n";} else {print "not ok 14\n";}
32
33 foreach $key (keys %foo) {
34     delete $foo{$key};
35 }
36
37 $foo{'foo'} = 'x';
38 $foo{'bar'} = 'y';
39
40 $foo = join('',values(%foo));
41 print +($foo eq 'xy' || $foo eq 'yx') ? "ok 15\n" : "not ok 15\n";
42
43 $refhash{"top"}->{"foo"} = "FOO";
44 $refhash{"top"}->{"bar"} = "BAR";
45
46 delete $refhash{"top"}->{"bar"};
47 @list = keys %{$refhash{"top"}};
48
49 print "@list" eq "foo" ? "ok 16\n" : "not ok 16 @list\n";
50
51 {
52     my %a = ('bar', 33);
53     my($a) = \(values %a);
54     my $b = \$a{bar};
55     my $c = \delete $a{bar};
56
57     print "not " unless $a == $b && $b == $c;
58     print "ok 17\n";
59 }