merging the immutable branch into trunk
[gitmo/Class-MOP.git] / t / 102_InsideOutClass_test.t
index ccee85e..615203d 100644 (file)
@@ -3,8 +3,9 @@
 use strict;
 use warnings;
 
-use Test::More tests => 65;
+use Test::More tests => 89;
 use File::Spec;
+use Scalar::Util 'reftype';
 
 BEGIN { 
     use_ok('Class::MOP');    
@@ -17,8 +18,9 @@ BEGIN {
     use strict;
     use warnings;    
     
-    use metaclass 'Class::MOP::Class' => (
-        ':instance_metaclass'  => 'InsideOutClass::Instance'
+    use metaclass (
+        'attribute_metaclass' => 'InsideOutClass::Attribute',
+        'instance_metaclass'  => 'InsideOutClass::Instance'
     );
     
     Foo->meta->add_attribute('foo' => (
@@ -53,8 +55,9 @@ BEGIN {
     
     use strict;
     use warnings;
-    use metaclass 'Class::MOP::Class' => (     
-        ':instance_metaclass' => 'InsideOutClass::Instance'
+    use metaclass (     
+        'attribute_metaclass' => 'InsideOutClass::Attribute',
+        'instance_metaclass'  => 'InsideOutClass::Instance'
     );
     
     Baz->meta->add_attribute('bling' => (
@@ -73,6 +76,8 @@ BEGIN {
 my $foo = Foo->new();
 isa_ok($foo, 'Foo');
 
+is(reftype($foo), 'SCALAR', '... Foo is made with SCALAR');
+
 can_ok($foo, 'foo');
 can_ok($foo, 'has_foo');
 can_ok($foo, 'get_bar');
@@ -93,6 +98,8 @@ is($foo->get_bar(), 42, '... Foo::bar == 42');
 my $foo2 = Foo->new();
 isa_ok($foo2, 'Foo');
 
+is(reftype($foo2), 'SCALAR', '... Foo is made with SCALAR');
+
 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
@@ -108,6 +115,8 @@ my $bar = Bar->new();
 isa_ok($bar, 'Bar');
 isa_ok($bar, 'Foo');
 
+is(reftype($bar), 'SCALAR', '... Bar is made with SCALAR');
+
 can_ok($bar, 'foo');
 can_ok($bar, 'has_foo');
 can_ok($bar, 'get_bar');
@@ -142,6 +151,8 @@ isa_ok($baz, 'Bar');
 isa_ok($baz, 'Foo');
 isa_ok($baz, 'Baz');
 
+is(reftype($baz), 'SCALAR', '... Bar::Baz is made with SCALAR');
+
 can_ok($baz, 'foo');
 can_ok($baz, 'has_foo');
 can_ok($baz, 'get_bar');
@@ -173,3 +184,34 @@ is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
 
+{
+    no strict 'refs';
+    
+    ok(*{'Foo::foo'}{HASH}, '... there is a foo package variable in Foo');
+    ok(*{'Foo::bar'}{HASH}, '... there is a bar package variable in Foo');
+
+    is(scalar(keys(%{'Foo::foo'})), 4, '... got the right number of entries for Foo::foo');
+    is(scalar(keys(%{'Foo::bar'})), 4, '... got the right number of entries for Foo::bar');    
+
+    ok(!*{'Bar::foo'}{HASH}, '... no foo package variable in Bar');
+    ok(!*{'Bar::bar'}{HASH}, '... no bar package variable in Bar');
+    ok(*{'Bar::baz'}{HASH}, '... there is a baz package variable in Bar');
+
+    is(scalar(keys(%{'Bar::foo'})), 0, '... got the right number of entries for Bar::foo');
+    is(scalar(keys(%{'Bar::bar'})), 0, '... got the right number of entries for Bar::bar');
+    is(scalar(keys(%{'Bar::baz'})), 2, '... got the right number of entries for Bar::baz');
+    
+    ok(*{'Baz::bling'}{HASH}, '... there is a bar package variable in Baz');
+
+    is(scalar(keys(%{'Baz::bling'})), 1, '... got the right number of entries for Baz::bling');        
+    
+    ok(!*{'Bar::Baz::foo'}{HASH}, '... no foo package variable in Bar::Baz');
+    ok(!*{'Bar::Baz::bar'}{HASH}, '... no bar package variable in Bar::Baz');
+    ok(!*{'Bar::Baz::baz'}{HASH}, '... no baz package variable in Bar::Baz');
+    ok(!*{'Bar::Baz::bling'}{HASH}, '... no bar package variable in Baz::Baz');
+
+    is(scalar(keys(%{'Bar::Baz::foo'})), 0, '... got the right number of entries for Bar::Baz::foo');
+    is(scalar(keys(%{'Bar::Baz::bar'})), 0, '... got the right number of entries for Bar::Baz::bar');
+    is(scalar(keys(%{'Bar::Baz::baz'})), 0, '... got the right number of entries for Bar::Baz::baz');    
+    is(scalar(keys(%{'Bar::Baz::bling'})), 0, '... got the right number of entries for Bar::Baz::bling');        
+}
\ No newline at end of file