summaryrefslogtreecommitdiff
path: root/cpan/Object-Accessor/t/06_Object-Accessor-alias.t
diff options
context:
space:
mode:
Diffstat (limited to 'cpan/Object-Accessor/t/06_Object-Accessor-alias.t')
-rw-r--r--cpan/Object-Accessor/t/06_Object-Accessor-alias.t63
1 files changed, 43 insertions, 20 deletions
diff --git a/cpan/Object-Accessor/t/06_Object-Accessor-alias.t b/cpan/Object-Accessor/t/06_Object-Accessor-alias.t
index 2a8aa81f0d..f302a09523 100644
--- a/cpan/Object-Accessor/t/06_Object-Accessor-alias.t
+++ b/cpan/Object-Accessor/t/06_Object-Accessor-alias.t
@@ -9,25 +9,48 @@ my $Class = 'Object::Accessor';
use_ok($Class);
-my $Object = $Class->new;
-my $Acc = 'foo';
-my $Alias = 'bar';
-
-### basic sanity test
-{ ok( $Object, "Object created" );
-
- ok( $Object->mk_accessors( $Acc ),
- " Accessor ->$Acc created" );
- ok( $Object->$Acc( $$ ), " ->$Acc set to $$" );
+my $Object = $Class->new;
+my $Acc = 'foo';
+my $Alias = 'bar';
+
+ok( $Object, "Object created" );
+isa_ok( $Object, $Class, " Object" );
+
+### add an accessor
+{ my $rv = $Object->mk_accessors( $Acc );
+ ok( $rv, "Created accessor '$Acc'" );
+ ok( $Object->$Acc( $$ )," Set value" );
+ is( $Object->$Acc, $$, " Retrieved value" );
+}
+
+### add an alias
+{ my $rv = $Object->mk_aliases( $Alias => $Acc );
+ ok( $rv, "Created alias '$Alias'" );
+ ok( $Object->can( $Alias ),
+ " Alias '$Alias' exists" );
+ is( $Object->$Alias, $Object->$Acc,
+ " Alias & original return the same value" );
+
+ ok( $Object->$Alias( $$.$$ ),
+ " Changed value using alias" );
+ is( $Object->$Alias, $Object->$Acc,
+ " Alias & original return the same value" );
+}
+
+### test if cloning works
+{ my $clone = $Object->mk_clone;
+ ok( $clone, "Cloned object" );
+
+ is_deeply( [sort $clone->ls_accessors], [sort $Object->ls_accessors],
+ " All accessors cloned" );
+
+ ok( $clone->$Acc( $$ ), " Set value" );
+ is( $clone->$Alias, $clone->$Acc,
+ " Alias & original return the same value" );
+
+ ok( $clone->$Alias( $$.$$ ),
+ " Changed value using alias" );
+ is( $clone->$Alias, $clone->$Acc,
+ " Alias & original return the same value" );
}
-### alias tests
-{ ok( $Object->mk_aliases( $Alias => $Acc ),
- "Alias ->$Alias => ->$Acc" );
- ok( $Object->$Alias, " ->$Alias returns value" );
- is( $Object->$Acc, $Object->$Alias,
- " ->$Alias eq ->$Acc" );
- ok( $Object->$Alias( $0 ), " Set value via alias ->$Alias" );
- is( $Object->$Acc, $Object->$Alias,
- " ->$Alias eq ->$Acc" );
-}