fixing version numbers and writing the changelog
[gitmo/Class-MOP.git] / t / 020_attribute.t
index 3e255f6..56a0acf 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 62;
+use Test::More tests => 67;
 use Test::Exception;
 
 BEGIN {
@@ -24,10 +24,23 @@ BEGIN {
     ok(!$attr->has_writer, '... $attr does not have an writer');
     ok(!$attr->has_default, '... $attr does not have an default');  
     
+    my $class = Class::MOP::Class->initialize('Foo');
+    isa_ok($class, 'Class::MOP::Class');
+    
+    lives_ok {
+        $attr->attach_to_class($class);
+    } '... attached a class successfully';
+    
+    is($attr->associated_class, $class, '... the class was associated correctly');
+    
     my $attr_clone = $attr->clone();
     isa_ok($attr_clone, 'Class::MOP::Attribute');
     isnt($attr, $attr_clone, '... but they are different instances');
     
+    is($attr->associated_class, $attr_clone->associated_class, '... the associated classes are the same though');
+    is($attr->associated_class, $class, '... the associated classes are the same though');    
+    is($attr_clone->associated_class, $class, '... the associated classes are the same though');    
+    
     is_deeply($attr, $attr_clone, '... but they are the same inside');
 }
 
@@ -53,6 +66,10 @@ BEGIN {
     isa_ok($attr_clone, 'Class::MOP::Attribute');
     isnt($attr, $attr_clone, '... but they are different instances');
     
+    is($attr->associated_class, $attr_clone->associated_class, '... the associated classes are the same though');
+    is($attr->associated_class, undef, '... the associated class is actually undef');    
+    is($attr_clone->associated_class, undef, '... the associated class is actually undef');    
+    
     is_deeply($attr, $attr_clone, '... but they are the same inside');                
 }
 
@@ -114,61 +131,17 @@ BEGIN {
     is_deeply($attr, $attr_clone, '... but they are the same inside');       
 }
 
-# NOTE:
-# the next three tests once tested that 
-# the code would fail, but we lifted the 
-# restriction so you can have an accessor 
-# along with a reader/writer pair (I mean 
-# why not really). So now they test that 
-# it works, which is kinda silly, but it 
-# tests the API change, so I keep it.
-
-lives_ok {
-    Class::MOP::Attribute->new('$foo', (
-        accessor => 'foo',
-        reader   => 'get_foo',
-    ));
-} '... can create accessors with reader/writers';
-
-lives_ok {
-    Class::MOP::Attribute->new('$foo', (
-        accessor => 'foo',
-        writer   => 'set_foo',
-    ));
-} '... can create accessors with reader/writers';
-
-lives_ok {
-    Class::MOP::Attribute->new('$foo', (
-        accessor => 'foo',
-        reader   => 'get_foo',        
-        writer   => 'set_foo',
-    ));
-} '... can create accessors with reader/writers';
-
-dies_ok {
-    Class::MOP::Attribute->new();
-} '... no name argument';
-
-dies_ok {
-    Class::MOP::Attribute->new('');
-} '... bad name argument';
-
-dies_ok {
-    Class::MOP::Attribute->new(0);
-} '... bad name argument';
-
-dies_ok {
-    Class::MOP::Attribute->install_accessors();
-} '... bad install_accessors argument';
-
-dies_ok {
-    Class::MOP::Attribute->install_accessors(bless {} => 'Fail');
-} '... bad install_accessors argument';
-
-dies_ok {
-    Class::MOP::Attribute->remove_accessors();
-} '... bad remove_accessors argument';
+{
+    my $attr = Class::MOP::Attribute->new('$foo');
+    isa_ok($attr, 'Class::MOP::Attribute');
+    
+    my $attr_clone = $attr->clone('name' => '$bar');
+    isa_ok($attr_clone, 'Class::MOP::Attribute');
+    isnt($attr, $attr_clone, '... but they are different instances');
+    
+    isnt($attr->name, $attr_clone->name, '... we changes the name parameter');
+    
+    is($attr->name, '$foo', '... $attr->name == $foo');
+    is($attr_clone->name, '$bar', '... $attr_clone->name == $bar');    
+}
 
-dies_ok {
-    Class::MOP::Attribute->remove_accessors(bless {} => 'Fail');
-} '... bad remove_accessors argument';