Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 020_attributes / 008_attribute_type_unions.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;
15     use Mouse;
16
17     has 'bar' => (is => 'rw', isa => 'ArrayRef | HashRef');
18 }
19
20 my $foo = Foo->new;
21 isa_ok($foo, 'Foo');
22
23 lives_ok {
24     $foo->bar([])
25 } '... set bar successfully with an ARRAY ref';
26
27 lives_ok {
28     $foo->bar({})
29 } '... set bar successfully with a HASH ref';
30
31 dies_ok {
32     $foo->bar(100)
33 } '... couldnt set bar successfully with a number';
34
35 dies_ok {
36     $foo->bar(sub {})
37 } '... couldnt set bar successfully with a CODE ref';
38
39 # check the constructor
40
41 lives_ok {
42     Foo->new(bar => [])
43 } '... created new Foo with bar successfully set with an ARRAY ref';
44
45 lives_ok {
46     Foo->new(bar => {})
47 } '... created new Foo with bar successfully set with a HASH ref';
48
49 dies_ok {
50     Foo->new(bar => 50)
51 } '... didnt create a new Foo with bar as a number';
52
53 dies_ok {
54     Foo->new(bar => sub {})
55 } '... didnt create a new Foo with bar as a CODE ref';
56
57 {
58     package Bar;
59     use Mouse;
60
61     has 'baz' => (is => 'rw', isa => 'Str | CodeRef');
62 }
63
64 my $bar = Bar->new;
65 isa_ok($bar, 'Bar');
66
67 lives_ok {
68     $bar->baz('a string')
69 } '... set baz successfully with a string';
70
71 lives_ok {
72     $bar->baz(sub { 'a sub' })
73 } '... set baz successfully with a CODE ref';
74
75 dies_ok {
76     $bar->baz(\(my $var1))
77 } '... couldnt set baz successfully with a SCALAR ref';
78
79 dies_ok {
80     $bar->baz({})
81 } '... couldnt set bar successfully with a HASH ref';
82
83 # check the constructor
84
85 lives_ok {
86     Bar->new(baz => 'a string')
87 } '... created new Bar with baz successfully set with a string';
88
89 lives_ok {
90     Bar->new(baz => sub { 'a sub' })
91 } '... created new Bar with baz successfully set with a CODE ref';
92
93 dies_ok {
94     Bar->new(baz => \(my $var2))
95 } '... didnt create a new Bar with baz as a number';
96
97 dies_ok {
98     Bar->new(baz => {})
99 } '... didnt create a new Bar with baz as a HASH ref';
100
101 done_testing;