6 use Test::More tests => 62;
11 use_ok('Class::MOP::Attribute');
15 my $attr = Class::MOP::Attribute->new('$foo');
16 isa_ok($attr, 'Class::MOP::Attribute');
18 is($attr->name, '$foo', '... $attr->name == $foo');
19 ok($attr->has_init_arg, '... $attr does have an init_arg');
20 is($attr->init_arg, '$foo', '... $attr init_arg is the name');
22 ok(!$attr->has_accessor, '... $attr does not have an accessor');
23 ok(!$attr->has_reader, '... $attr does not have an reader');
24 ok(!$attr->has_writer, '... $attr does not have an writer');
25 ok(!$attr->has_default, '... $attr does not have an default');
27 my $attr_clone = $attr->clone();
28 isa_ok($attr_clone, 'Class::MOP::Attribute');
29 isnt($attr, $attr_clone, '... but they are different instances');
31 is_deeply($attr, $attr_clone, '... but they are the same inside');
35 my $attr = Class::MOP::Attribute->new('$foo', (
39 isa_ok($attr, 'Class::MOP::Attribute');
41 is($attr->name, '$foo', '... $attr->name == $foo');
43 ok($attr->has_init_arg, '... $attr does have an init_arg');
44 is($attr->init_arg, '-foo', '... $attr->init_arg == -foo');
45 ok($attr->has_default, '... $attr does have an default');
46 is($attr->default, 'BAR', '... $attr->default == BAR');
48 ok(!$attr->has_accessor, '... $attr does not have an accessor');
49 ok(!$attr->has_reader, '... $attr does not have an reader');
50 ok(!$attr->has_writer, '... $attr does not have an writer');
52 my $attr_clone = $attr->clone();
53 isa_ok($attr_clone, 'Class::MOP::Attribute');
54 isnt($attr, $attr_clone, '... but they are different instances');
56 is_deeply($attr, $attr_clone, '... but they are the same inside');
60 my $attr = Class::MOP::Attribute->new('$foo', (
65 isa_ok($attr, 'Class::MOP::Attribute');
67 is($attr->name, '$foo', '... $attr->name == $foo');
69 ok($attr->has_init_arg, '... $attr does have an init_arg');
70 is($attr->init_arg, '-foo', '... $attr->init_arg == -foo');
71 ok($attr->has_default, '... $attr does have an default');
72 is($attr->default, 'BAR', '... $attr->default == BAR');
74 ok($attr->has_accessor, '... $attr does have an accessor');
75 is($attr->accessor, 'foo', '... $attr->accessor == foo');
77 ok(!$attr->has_reader, '... $attr does not have an reader');
78 ok(!$attr->has_writer, '... $attr does not have an writer');
80 my $attr_clone = $attr->clone();
81 isa_ok($attr_clone, 'Class::MOP::Attribute');
82 isnt($attr, $attr_clone, '... but they are different instances');
84 is_deeply($attr, $attr_clone, '... but they are the same inside');
88 my $attr = Class::MOP::Attribute->new('$foo', (
94 isa_ok($attr, 'Class::MOP::Attribute');
96 is($attr->name, '$foo', '... $attr->name == $foo');
98 ok($attr->has_init_arg, '... $attr does have an init_arg');
99 is($attr->init_arg, '-foo', '... $attr->init_arg == -foo');
100 ok($attr->has_default, '... $attr does have an default');
101 is($attr->default, 'BAR', '... $attr->default == BAR');
103 ok($attr->has_reader, '... $attr does have an reader');
104 is($attr->reader, 'get_foo', '... $attr->reader == get_foo');
105 ok($attr->has_writer, '... $attr does have an writer');
106 is($attr->writer, 'set_foo', '... $attr->writer == set_foo');
108 ok(!$attr->has_accessor, '... $attr does not have an accessor');
110 my $attr_clone = $attr->clone();
111 isa_ok($attr_clone, 'Class::MOP::Attribute');
112 isnt($attr, $attr_clone, '... but they are different instances');
114 is_deeply($attr, $attr_clone, '... but they are the same inside');
118 # the next three tests once tested that
119 # the code would fail, but we lifted the
120 # restriction so you can have an accessor
121 # along with a reader/writer pair (I mean
122 # why not really). So now they test that
123 # it works, which is kinda silly, but it
124 # tests the API change, so I keep it.
127 Class::MOP::Attribute->new('$foo', (
131 } '... can create accessors with reader/writers';
134 Class::MOP::Attribute->new('$foo', (
138 } '... can create accessors with reader/writers';
141 Class::MOP::Attribute->new('$foo', (
146 } '... can create accessors with reader/writers';
149 Class::MOP::Attribute->new();
150 } '... no name argument';
153 Class::MOP::Attribute->new('');
154 } '... bad name argument';
157 Class::MOP::Attribute->new(0);
158 } '... bad name argument';
161 Class::MOP::Attribute->install_accessors();
162 } '... bad install_accessors argument';
165 Class::MOP::Attribute->install_accessors(bless {} => 'Fail');
166 } '... bad install_accessors argument';
169 Class::MOP::Attribute->remove_accessors();
170 } '... bad remove_accessors argument';
173 Class::MOP::Attribute->remove_accessors(bless {} => 'Fail');
174 } '... bad remove_accessors argument';