removed whitespace
[gitmo/MooseX-Types-Structured.git] / t / bug-is-subtype.t
CommitLineData
8c187148 1use strict;
2use warnings;
3use Test::More;
4
5## Bug report was that if calling ->is_subtype on crap (not a type, etc) you
6## get a not very helpful error message. Fix was to make crap just return
7## boolean false to make this like the rest of Moose type constraints. I am
8## not convinced this is good, but at least is consistent.
9#
10# I also changed ->equals and ->is_a_type_of to be consistent
11
12{
13 package moosex::types::structured::bug_is_subtype;
14
15 use Moose;
16 use MooseX::Types -declare => [qw/ ThingType /];
17 use MooseX::Types::Moose qw/ Int Str /;
18 use MooseX::Types::Structured qw/ Dict /;
19
20 subtype ThingType, as Dict [ id => Int, name => Str, ];
21 has thing => ( is => 'ro', isa => ThingType, );
22}
23
24ok my $test = moosex::types::structured::bug_is_subtype->new,
25 'created class';
26
27is(
28 moosex::types::structured::bug_is_subtype::ThingType,
29 'moosex::types::structured::bug_is_subtype::ThingType',
30 'correct type',
31);
32
33use MooseX::Types::Moose 'HashRef';
34
35is(
36 HashRef,
37 'HashRef',
38 'correct type',
39);
40
41ok(
42 moosex::types::structured::bug_is_subtype::ThingType->is_subtype_of(HashRef),
43 'is a subtype',
44);
45
46ok(
47 !moosex::types::structured::bug_is_subtype::ThingType
48 ->is_subtype_of(moosex::types::structured::bug_is_subtype::ThingType),
49 'is not a subtype',
50);
51
52ok(
53 !moosex::types::structured::bug_is_subtype::ThingType
54 ->is_subtype_of('SomeCrap'),
55 'is not a subtype',
56);
57
58sub SomeCrap {}
59
60ok(
61 !moosex::types::structured::bug_is_subtype::ThingType
62 ->is_subtype_of(SomeCrap),
63 'is not a subtype',
64);
65
66ok(
67 !moosex::types::structured::bug_is_subtype::ThingType
68 ->is_subtype_of(undef),
69 'is not a subtype',
70);
71
72ok(
73 !moosex::types::structured::bug_is_subtype::ThingType
74 ->equal(undef),
75 'is not a subtype',
76);
77
78ok(
79 !moosex::types::structured::bug_is_subtype::ThingType
80 ->is_a_type_of(undef),
81 'is not a subtype',
82);
83
8c187148 84done_testing;