Fix a typo
[gitmo/Mouse.git] / Moose-t-failing / 040_type_constraints / 024_role_type_constraint.t
CommitLineData
b2b106d7 1#!/usr/bin/perl
c47cf415 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
b2b106d7 5
6use strict;
7use warnings;
8
c47cf415 9use Test::More;
10$TODO = q{Mouse is not yet completed};
b2b106d7 11use Test::Exception;
12
13BEGIN {
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
39lives_ok { role_type('Boop', message { "${_} is not a Boop" }) }
40 'role_type keywork works with message';
41
42my $type = find_type_constraint("Foo");
43
44is( $type->role, "Foo", "role attribute" );
45
46ok( $type->is_subtype_of("Gorch"), "subtype of gorch" );
47
48ok( $type->is_subtype_of("Bar"), "subtype of bar" );
49
50ok( $type->is_subtype_of("Object"), "subtype of Object" );
51
52ok( !$type->is_subtype_of("ThisTypeDoesNotExist"), "not subtype of unknown type name" );
53ok( !$type->is_a_type_of("ThisTypeDoesNotExist"), "not type of unknown type name" );
54
55ok( find_type_constraint("Bar")->check(FooC->new), "Foo passes Bar" );
56ok( find_type_constraint("Bar")->check(BarC->new), "Bar passes Bar" );
57ok( !find_type_constraint("Gorch")->check(BarC->new), "but Bar doesn't pass Gorch");
58
59my $boop = find_type_constraint("Boop");
60ok( $boop->has_message, 'Boop has a message');
61my $error = $boop->get_message(FooC->new);
62like( $error, qr/is not a Boop/, 'boop gives correct error message');
63
64
65ok( $type->equals($type), "equals self" );
c47cf415 66ok( $type->equals(Mouse::Meta::TypeConstraint->new( name => "__ANON__", role => "Foo" )), "equals anon constraint of same value" );
67ok( $type->equals(Mouse::Meta::TypeConstraint->new( name => "Oink", role => "Foo" )), "equals differently named constraint of same value" );
68ok( !$type->equals(Mouse::Meta::TypeConstraint->new( name => "__ANON__", role => "Bar" )), "doesn't equal other anon constraint" );
69ok( $type->is_subtype_of(Mouse::Meta::TypeConstraint->new( name => "__ANON__", role => "Bar" )), "subtype of other anon constraint" );
b2b106d7 70
c47cf415 71done_testing;