Regenerate test files
[gitmo/Mouse.git] / t-failing / 040_type_constraints / 024_role_type_constraint.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 $TODO = q{Mouse is not yet completed};
11 use Test::Exception;
12
13 BEGIN {
14     use_ok('Mouse::Util::TypeConstraints');
15 }
16
17 {
18     package Gorch;
19     use Mouse::Role;
20
21     package Bar;
22     use Mouse::Role;
23
24     package Foo;
25     use Mouse::Role;
26
27     with qw(Bar Gorch);
28
29     package FooC;
30     use Mouse;
31     with qw(Foo);
32
33     package BarC;
34     use Mouse;
35     with qw(Bar);
36
37 }
38
39 lives_ok { role_type('Boop', message { "${_} is not a Boop" }) }
40   'role_type keywork works with message';
41
42 my $type = find_type_constraint("Foo");
43
44 is( $type->role, "Foo", "role attribute" );
45
46 ok( $type->is_subtype_of("Gorch"), "subtype of gorch" );
47
48 ok( $type->is_subtype_of("Bar"), "subtype of bar" );
49
50 ok( $type->is_subtype_of("Object"), "subtype of Object" );
51
52 ok( !$type->is_subtype_of("ThisTypeDoesNotExist"), "not subtype of unknown type name" );
53 ok( !$type->is_a_type_of("ThisTypeDoesNotExist"), "not type of unknown type name" );
54
55 ok( find_type_constraint("Bar")->check(FooC->new), "Foo passes Bar" );
56 ok( find_type_constraint("Bar")->check(BarC->new), "Bar passes Bar" );
57 ok( !find_type_constraint("Gorch")->check(BarC->new), "but Bar doesn't pass Gorch");
58
59 my $boop = find_type_constraint("Boop");
60 ok( $boop->has_message, 'Boop has a message');
61 my $error = $boop->get_message(FooC->new);
62 like( $error, qr/is not a Boop/,  'boop gives correct error message');
63
64
65 ok( $type->equals($type), "equals self" );
66 ok( $type->equals(Mouse::Meta::TypeConstraint->new( name => "__ANON__", role => "Foo" )), "equals anon constraint of same value" );
67 ok( $type->equals(Mouse::Meta::TypeConstraint->new( name => "Oink", role => "Foo" )), "equals differently named constraint of same value" );
68 ok( !$type->equals(Mouse::Meta::TypeConstraint->new( name => "__ANON__", role => "Bar" )), "doesn't equal other anon constraint" );
69 ok( $type->is_subtype_of(Mouse::Meta::TypeConstraint->new( name => "__ANON__", role => "Bar" )), "subtype of other anon constraint" );
70
71 done_testing;