tweaking the attribute initializer stuff a little
[gitmo/Class-MOP.git] / t / 024_attribute_initializer.t
index db9aca5..c3cfc89 100644 (file)
@@ -5,7 +5,7 @@ use warnings;
 
 use Scalar::Util 'blessed', 'reftype';
 
-use Test::More tests => 4;
+use Test::More tests => 10;
 
 BEGIN {
     use_ok('Class::MOP');
@@ -22,11 +22,15 @@ This checks that the initializer is used to set the initial value.
     use metaclass;
     
     Foo->meta->add_attribute('bar' => 
-        reader => 'get_bar',
-        writer => 'set_bar',
+        reader      => 'get_bar',
+        writer      => 'set_bar',
         initializer => sub {
-          my ($self, $value, $callback, $attr) = @_;
-          $callback->($value * 2);
+            my ($self, $value, $callback, $attr) = @_;
+            
+            ::isa_ok($attr, 'Class::MOP::Attribute');
+            ::is($attr->name, 'bar', '... the attribute is our own');
+            
+            $callback->($value * 2);
         },
     );  
 }
@@ -35,9 +39,25 @@ can_ok('Foo', 'get_bar');
 can_ok('Foo', 'set_bar');    
 
 my $foo = Foo->meta->construct_instance(bar => 10);
-is(
-  $foo->get_bar,
-  20,
-  "initial argument was doubled as expected",
-);
+is($foo->get_bar, 20, "... initial argument was doubled as expected");
+
+$foo->set_bar(30);
+
+is($foo->get_bar, 30, "... and setter works correctly");
+
+# meta tests ...
+
+my $bar = Foo->meta->get_attribute('bar');
+isa_ok($bar, 'Class::MOP::Attribute');
+
+ok($bar->has_initializer, '... bar has an initializer');
+is(reftype $bar->initializer, 'CODE', '... the initializer is a CODE ref');
+
+
+
+
+
+
+
+