Remove numbers from our tests
[gitmo/Moose.git] / t / roles / role_attrs.t
diff --git a/t/roles/role_attrs.t b/t/roles/role_attrs.t
new file mode 100644 (file)
index 0000000..6c1ea8b
--- /dev/null
@@ -0,0 +1,53 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use Moose ();
+use Moose::Meta::Role;
+use Moose::Util;
+
+my $role1 = Moose::Meta::Role->initialize('Foo');
+$role1->add_attribute( foo => ( is => 'ro' ) );
+
+ok( $role1->has_attribute('foo'), 'Foo role has a foo attribute' );
+
+my $foo_attr = $role1->get_attribute('foo');
+is(
+    $foo_attr->associated_role->name, 'Foo',
+    'associated_role for foo attr is Foo role'
+);
+
+isa_ok(
+    $foo_attr->attribute_for_class('Moose::Meta::Attribute'),
+    'Moose::Meta::Attribute',
+    'attribute returned by ->attribute_for_class'
+);
+
+my $role2 = Moose::Meta::Role->initialize('Bar');
+$role1->apply($role2);
+
+ok( $role2->has_attribute('foo'), 'Bar role has a foo attribute' );
+
+is(
+    $foo_attr->associated_role->name, 'Foo',
+    'associated_role for foo attr is still Foo role'
+);
+
+isa_ok(
+    $foo_attr->attribute_for_class('Moose::Meta::Attribute'),
+    'Moose::Meta::Attribute',
+    'attribute returned by ->attribute_for_class'
+);
+
+my $role3 = Moose::Meta::Role->initialize('Baz');
+my $combined = Moose::Meta::Role->combine( [ $role1->name ], [ $role3->name ] );
+
+ok( $combined->has_attribute('foo'), 'combined role has a foo attribute' );
+
+is(
+    $foo_attr->associated_role->name, 'Foo',
+    'associated_role for foo attr is still Foo role'
+);
+
+done_testing;