File: 06_ensure_released.t

package info (click to toggle)
libhash-fieldhash-perl 0.15-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 1,249; ansic: 207; makefile: 10
file content (38 lines) | stat: -rw-r--r-- 587 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!perl -w

use strict;
use Test::More tests => 4;

#use Hash::Util::FieldHash::Compat qw(fieldhash fieldhashes);
use Hash::FieldHash qw(:all);

my $count = 0;
{
	package CountedObject;
	sub new{ $count++; return bless {}, shift }
	sub DESTROY{ $count-- }
}

fieldhash my %a;

{
	my $o = {};
	$a{$o} = CountedObject->new;

	delete $a{$o};

	is $count, 0, 'field is released';

	$o = CountedObject->new;
	$a{$o}++;
	delete $a{$o};
	undef $o;

	is $count, 0, 'key object is released';

	$o = CountedObject->new;
	$a{$o} = CountedObject->new;
}

is_deeply \%a, {};
is $count, 0, 'finished';