use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 62;
use Test::Exception;
BEGIN {
+ use_ok('Class::MOP');
use_ok('Class::MOP::Attribute');
}
isa_ok($attr, 'Class::MOP::Attribute');
is($attr->name, '$foo', '... $attr->name == $foo');
+ ok($attr->has_init_arg, '... $attr does have an init_arg');
+ is($attr->init_arg, '$foo', '... $attr init_arg is the name');
ok(!$attr->has_accessor, '... $attr does not have an accessor');
ok(!$attr->has_reader, '... $attr does not have an reader');
ok(!$attr->has_writer, '... $attr does not have an writer');
- ok(!$attr->has_init_arg, '... $attr does not have an init_arg');
- ok(!$attr->has_default, '... $attr does not have an default');
+ ok(!$attr->has_default, '... $attr does not have an default');
+
+ my $attr_clone = $attr->clone();
+ isa_ok($attr_clone, 'Class::MOP::Attribute');
+ isnt($attr, $attr_clone, '... but they are different instances');
+
+ is_deeply($attr, $attr_clone, '... but they are the same inside');
}
{
ok(!$attr->has_accessor, '... $attr does not have an accessor');
ok(!$attr->has_reader, '... $attr does not have an reader');
- ok(!$attr->has_writer, '... $attr does not have an writer');
+ ok(!$attr->has_writer, '... $attr does not have an writer');
+
+ my $attr_clone = $attr->clone();
+ isa_ok($attr_clone, 'Class::MOP::Attribute');
+ isnt($attr, $attr_clone, '... but they are different instances');
+
+ is_deeply($attr, $attr_clone, '... but they are the same inside');
}
{
is($attr->accessor, 'foo', '... $attr->accessor == foo');
ok(!$attr->has_reader, '... $attr does not have an reader');
- ok(!$attr->has_writer, '... $attr does not have an writer');
+ ok(!$attr->has_writer, '... $attr does not have an writer');
+
+ my $attr_clone = $attr->clone();
+ isa_ok($attr_clone, 'Class::MOP::Attribute');
+ isnt($attr, $attr_clone, '... but they are different instnaces');
+
+ is_deeply($attr, $attr_clone, '... but they are the same inside');
}
{
ok($attr->has_writer, '... $attr does have an writer');
is($attr->writer, 'set_foo', '... $attr->writer == set_foo');
- ok(!$attr->has_accessor, '... $attr does not have an accessor');
+ ok(!$attr->has_accessor, '... $attr does not have an accessor');
+
+ my $attr_clone = $attr->clone();
+ isa_ok($attr_clone, 'Class::MOP::Attribute');
+ isnt($attr, $attr_clone, '... but they are different instnaces');
+
+ is_deeply($attr, $attr_clone, '... but they are the same inside');
}
-dies_ok {
- my $attr = Class::MOP::Attribute->new('$foo', (
+# 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',
));
-} '... cannot create accessors with reader/writers';
+} '... can create accessors with reader/writers';
-dies_ok {
- my $attr = Class::MOP::Attribute->new('$foo', (
+lives_ok {
+ Class::MOP::Attribute->new('$foo', (
accessor => 'foo',
writer => 'set_foo',
));
-} '... cannot create accessors with reader/writers';
+} '... can create accessors with reader/writers';
-dies_ok {
- my $attr = Class::MOP::Attribute->new('$foo', (
+lives_ok {
+ Class::MOP::Attribute->new('$foo', (
accessor => 'foo',
reader => 'get_foo',
writer => 'set_foo',
));
-} '... cannot create accessors with reader/writers';
+} '... can create accessors with reader/writers';
+
+dies_ok {
+ Class::MOP::Attribute->new();
+} '... no name argument';
+dies_ok {
+ Class::MOP::Attribute->new('');
+} '... bad name argument';
-{
- my $meta = Class::MOP::Attribute->meta();
- isa_ok($meta, 'Class::MOP::Class');
-
- foreach my $method_name (qw(
- meta
- new
- has_accessor accessor
- has_writer writer
- has_reader reader
- has_init_arg init_arg
- has_default default
- install_accessors
- remove_accessors
- )) {
- ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
- }
-
-
-}
+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';
+
+dies_ok {
+ Class::MOP::Attribute->remove_accessors(bless {} => 'Fail');
+} '... bad remove_accessors argument';