File: inline_typing.t

package info (click to toggle)
libmoosex-attributeshortcuts-perl 0.024-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 312 kB
  • ctags: 9
  • sloc: perl: 326; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,329 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use strict;
use warnings;

use Test::More;
use Test::Moose::More;

{
    package TestClass;

    use Moose;
    use namespace::autoclean;
    use MooseX::AttributeShortcuts;
    use Test::Warn;

    warnings_exist {
            has bar => (is => 'ro',  isa_class => 'SomeClass');
            has baz => (is => 'rwp', isa_role  => 'SomeRole');
        }
        [ qr/Naughty! isa_class, isa_role, and isa_enum will be removed on or after 01 July 2014!/ ],
        'expected warnings thrown for isa_class, isa_role usage',
        ;
}

# TODO shift the constraint checking out into TMM?

validate_class TestClass => (
    attributes => [ qw{ bar baz } ],
);

subtest 'isa_class check' => sub {
    my $att = 'bar';
    my $meta = TestClass->meta->get_attribute($att);
    ok $meta->has_type_constraint, "$att has a type constraint";
    my $tc = $meta->type_constraint;
    isa_ok $tc, 'Moose::Meta::TypeConstraint::Class';
    is $tc->class, 'SomeClass', 'tc looks for correct class';
};

subtest 'isa_role check' => sub {
    my $att = 'baz';
    my $meta = TestClass->meta->get_attribute($att);
    ok $meta->has_type_constraint, "$att has a type constraint";
    my $tc = $meta->type_constraint;
    isa_ok $tc, 'Moose::Meta::TypeConstraint::Role';
    is $tc->role, 'SomeRole', 'tc looks for correct role';
};


done_testing;