Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 020_attributes / 005_attribute_does.t
1 #!/usr/bin/perl
2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
5
6 use strict;
7 use warnings;
8
9 use Test::More;
10 use Test::Exception;
11
12
13 {
14     package Foo::Role;
15     use Mouse::Role;
16     use Mouse::Util::TypeConstraints;
17
18     # if does() exists on its own, then
19     # we create a type constraint for
20     # it, just as we do for isa()
21     has 'bar' => (is => 'rw', does => 'Bar::Role');
22     has 'baz' => (
23         is   => 'rw',
24         does => role_type('Bar::Role')
25     );
26
27     package Foo::Class;
28     use Mouse;
29
30     with 'Foo::Role';
31
32     package Bar::Role;
33     use Mouse::Role;
34
35     # if isa and does appear together, then see if Class->does(Role)
36     # if it does work... then the does() check is actually not needed
37     # since the isa() check will imply the does() check
38     has 'foo' => (is => 'rw', isa => 'Foo::Class', does => 'Foo::Role');
39
40     package Bar::Class;
41     use Mouse;
42
43     with 'Bar::Role';
44 }
45
46 my $foo = Foo::Class->new;
47 isa_ok($foo, 'Foo::Class');
48
49 my $bar = Bar::Class->new;
50 isa_ok($bar, 'Bar::Class');
51
52 lives_ok {
53     $foo->bar($bar);
54 } '... bar passed the type constraint okay';
55
56 dies_ok {
57     $foo->bar($foo);
58 } '... foo did not pass the type constraint okay';
59
60 lives_ok {
61     $foo->baz($bar);
62 } '... baz passed the type constraint okay';
63
64 dies_ok {
65     $foo->baz($foo);
66 } '... foo did not pass the type constraint okay';
67
68 lives_ok {
69     $bar->foo($foo);
70 } '... foo passed the type constraint okay';
71
72
73
74 # some error conditions
75
76 {
77     package Baz::Class;
78     use Mouse;
79
80     # if isa and does appear together, then see if Class->does(Role)
81     # if it does not,.. we have a conflict... so we die loudly
82     ::dies_ok {
83         has 'foo' => (isa => 'Foo::Class', does => 'Bar::Class');
84     } '... cannot have a does() which is not done by the isa()';
85 }
86
87 {
88     package Bling;
89     use strict;
90     use warnings;
91
92     sub bling { 'Bling::bling' }
93
94     package Bling::Bling;
95     use Mouse;
96
97     # if isa and does appear together, then see if Class->does(Role)
98     # if it does not,.. we have a conflict... so we die loudly
99     ::dies_ok {
100         has 'foo' => (isa => 'Bling', does => 'Bar::Class');
101     } '... cannot have a isa() which is cannot does()';
102 }
103
104 done_testing;