File: 01_basic.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 (91 lines) | stat: -rw-r--r-- 1,344 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!perl -w

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

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

fieldhash my %hash;
fieldhash our %ghash;

ok !scalar(%hash);

my $r = {};
$hash{$r} = 'r';
$ghash{$r} = 'g';

ok scalar(%hash);

is_deeply [values %hash],  ['r'];
is_deeply [values %ghash], ['g'];

{
	my $o = bless {foo => 'bar'};
	my $x = ['baz'];

	$hash{$o} = 10;

	is $hash{$o}, 10;

	$hash{$x} = 42;

	is $hash{$o}, 10;
	is $hash{$x}, 42;

	$ghash{$o} = 10;
	$ghash{$x} = 42;

	is_deeply [sort values %hash],  [sort('r', 10, 42)];
	is_deeply [sort values %ghash], [sort('g', 10, 42)];

	is_deeply $o, {foo => 'bar'};
	is_deeply $x, ['baz'];

	is ref($o), __PACKAGE__;
	is ref($x), 'ARRAY';
}

is_deeply [values %hash],  ['r'];
is_deeply [values %ghash], ['g'];

{
	my $o = bless {};

	$hash{$o} = 10;

	is $hash{$o}, 10;

	$hash{$o}++;

	is $hash{$o}, 11;
}

is_deeply [values %hash],  ['r'];
is_deeply [values %ghash], ['g'];

undef $r;

is_deeply \%hash,  {};
is_deeply \%ghash, {};

{
	my %hash = (foo => 'bar');
	fieldhash %hash;

	is_deeply \%hash, {};
}

eval{
	my %hash;
	foreach (1 .. 10){
		fieldhash %hash;
	}
};
is $@, '';

my $o = do{ fieldhash my %hash; bless \%hash };
is ref($o), __PACKAGE__;

#use Data::Dumper;
#print Dumper *{$Hash::FieldHash::{'::OBJECT_REGISTRY'}}{ARRAY};