/
03_properties.t
104 lines (81 loc) · 2.26 KB
/
03_properties.t
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
92
93
94
95
96
97
98
99
100
101
102
103
use strict;
use lib ".";
use Test::More;
use Class::InsideOut ();
$|++; # keep stdout and stderr in order on Win32
plan tests => 15;
#--------------------------------------------------------------------------#
my $class = "t::Object::Animal::Jackalope";
# sort alpha
my $properties = {
"t::Object::Animal" => {
nickname=> "public", #20997: Duplicate property name
name => "public",
species => "public",
Genus => "public", # David Schmitt: uppercase!
},
"t::Object::Animal::Antelope" => {
color => "public",
panicked => "private",
points => "public",
},
"t::Object::Animal::JackRabbit" => {
speed => "public",
},
"t::Object::Animal::Jackalope" => {
kills => "public",
sidekick => "private",
whiskers => "private",
},
};
my ($o, $p);
#--------------------------------------------------------------------------#
require_ok( $class );
is_deeply( Class::InsideOut::_properties( $class ),
$properties,
"$class has/inherited its expected properties"
);
is( Class::InsideOut::_object_count( $class ), 0,
"$class has no objects registered"
);
ok( ($o = $class->new()) && $o->isa($class),
"Creating a $class object"
);
ok( ($p = $class->new()) && $p->isa($class),
"Creating another $class object"
);
is( $o->name( "Larry" ), "Larry",
"Setting a name for the first object"
);
is( $p->name( "Damian" ), "Damian",
"Setting a name for the second object"
);
isnt( $o->name, $p->name,
"Objects have different names"
);
is( $o->color( "brown" ), "brown",
"Setting a color for the first object"
);
is( $o->speed( "42" ), "42",
"Setting a speed for the first object"
);
is( $o->points( 13 ), 13,
"Setting points for the first object"
);
is( $p->kills( "23" ), "23",
"Setting a kill-count for the second object"
);
Class::InsideOut::_deregister( $o ) if $] < 5.006;
undef $o;
ok( ! defined $o,
"Destroying the first object"
);
Class::InsideOut::_deregister( $p ) if $] < 5.006;
undef $p;
ok( ! defined $p,
"Destroying the second object"
);
my @leaks = Class::InsideOut::_leaking_memory;
is( scalar @leaks, 0,
"$class is not leaking memory"
) or diag "Leaks detected in:\n" . join( "\n", map { q{ } . $_ } @leaks );