fix for bug and prep for cpan
[gitmo/MooseX-Types-Structured.git] / t / bug-is-subtype.t
1 use strict;
2 use warnings;
3 use 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
24 ok my $test = moosex::types::structured::bug_is_subtype->new,
25   'created class';
26
27 is(
28   moosex::types::structured::bug_is_subtype::ThingType,
29   'moosex::types::structured::bug_is_subtype::ThingType',
30   'correct type',
31 );
32
33 use MooseX::Types::Moose 'HashRef';
34
35 is(
36   HashRef,
37   'HashRef',
38   'correct type',
39 );
40
41 ok(
42   moosex::types::structured::bug_is_subtype::ThingType->is_subtype_of(HashRef),
43   'is a subtype',
44 );
45
46 ok(
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
52 ok(
53   !moosex::types::structured::bug_is_subtype::ThingType
54     ->is_subtype_of('SomeCrap'),
55   'is not a subtype',
56 );
57
58 sub SomeCrap {}
59
60 ok(
61   !moosex::types::structured::bug_is_subtype::ThingType
62     ->is_subtype_of(SomeCrap),
63   'is not a subtype',
64 );
65
66 ok(
67   !moosex::types::structured::bug_is_subtype::ThingType
68     ->is_subtype_of(undef),
69   'is not a subtype',
70 );
71
72 ok(
73   !moosex::types::structured::bug_is_subtype::ThingType
74     ->equal(undef),
75   'is not a subtype',
76 );
77
78 ok(
79   !moosex::types::structured::bug_is_subtype::ThingType
80     ->is_a_type_of(undef),
81   'is not a subtype',
82 );
83
84
85 done_testing;