Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 020_attributes / 030_non_alpha_attr_names.t
1 use strict;
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 use warnings;
6
7 use Test::More;
8 use Test::Mouse;
9
10 {
11     package Foo;
12     use Mouse;
13     has 'type' => (
14         required => 0,
15         reader   => 'get_type',
16         default  => 1,
17     );
18
19     # Assigning types to these non-alpha attrs exposed a bug in Mouse.
20     has '@type' => (
21         isa      => 'Str',
22         required => 0,
23         reader   => 'get_at_type',
24         writer   => 'set_at_type',
25         default  => 'at type',
26     );
27
28     has 'has spaces' => (
29         isa      => 'Int',
30         required => 0,
31         reader   => 'get_hs',
32         default  => 42,
33     );
34
35     has '!req' => (
36         required => 1,
37         reader   => 'req'
38     );
39
40     no Mouse;
41 }
42
43 with_immutable {
44     ok( Foo->meta->has_attribute($_), "Foo has '$_' attribute" )
45         for 'type', '@type', 'has spaces';
46
47     my $foo = Foo->new( '!req' => 42 );
48
49     is( $foo->get_type,    1,         q{'type' attribute default is 1} );
50     is( $foo->get_at_type, 'at type', q{'@type' attribute default is 1} );
51     is( $foo->get_hs, 42, q{'has spaces' attribute default is 42} );
52
53     $foo = Foo->new(
54         type         => 'foo',
55         '@type'      => 'bar',
56         'has spaces' => 200,
57         '!req'       => 84,
58     );
59
60     isa_ok( $foo, 'Foo' );
61     is( $foo->get_at_type, 'bar', q{reader for '@type'} );
62     is( $foo->get_hs,      200, q{reader for 'has spaces'} );
63
64     $foo->set_at_type(99);
65     is( $foo->get_at_type, 99, q{writer for '@type' worked} );
66 }
67 'Foo';
68
69 done_testing;