File: 35-hash.t

package info (click to toggle)
libtangram-perl 2.10-1.1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 1,064 kB
  • ctags: 703
  • sloc: perl: 9,665; makefile: 35
file content (72 lines) | stat: -rw-r--r-- 1,548 bytes parent folder | download | duplicates (6)
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
#  -*- perl -*-


use strict;
use lib 't/springfield';
use Springfield;
use Test::More tests => 4;

use vars qw( $intrusive );

my $opinions = $intrusive ? 'ih_opinions' : 'h_opinions';
(my $other = $opinions) =~ s{^(i)?}{($1 ? "" : "i")}e;

#$Tangram::TRACE = \*STDOUT;

sub graph {
    my $homer =
    NaturalPerson->new( firstName => 'Homer',
			name => 'Simpson',
			$opinions =>
			{ work => Opinion->new(statement => 'bad'),
			  food => Opinion->new(statement => 'good'),
			  beer => Opinion->new(statement => 'better') },
			# this is for is_deeply...
			$other => undef,
		      );
}

{
	my $storage = Springfield::connect_empty();

	my $homer = graph();

	$storage->insert($homer);

	$storage->disconnect();
}

is(leaked, 0, "leaktest");

{
	my $storage = Springfield::connect();
	my ($homer) = $storage->select('NaturalPerson');

	# Test::More can be awfully pedantic at times :)
	my $homer_eg = graph();
	my $opinions_h = $homer_eg->{$opinions};

	my $ih_parent;
	if ($intrusive) {
	    $ih_parent = $homer_eg;
	}
	while (my($k,$v)= each %$opinions_h) {
	    $v->{ih_parent} = $ih_parent;
	}

	is_deeply([ sort keys %{ $homer->{$opinions}} ],
		  [ sort keys %{$opinions_h} ],
		  "Hash returned intact");
	is_deeply([ sort map { $_->{statement} } values %{ $homer->{$opinions}} ],
		  [ sort map { $_->{statement} } values %{ $opinions_h } ],
		  "Hash returned intact");

	# smash circular references...
	while (my($k,$v)= each %$opinions_h) {
	    $v->{ih_parent} = undef;
	}

	$storage->disconnect();
}

is(leaked, 0, "leaktest");