fix for bug and prep for cpan
[gitmo/MooseX-Types-Structured.git] / t / bug-is-subtype.t
diff --git a/t/bug-is-subtype.t b/t/bug-is-subtype.t
new file mode 100644 (file)
index 0000000..996cb0c
--- /dev/null
@@ -0,0 +1,85 @@
+use strict;
+use warnings;
+use Test::More;
+
+## Bug report was that if calling ->is_subtype on crap (not a type, etc) you
+## get a not very helpful error message.  Fix was to make crap just return
+## boolean false to make this like the rest of Moose type constraints.  I am
+## not convinced this is good, but at least is consistent.
+#
+# I also changed ->equals and ->is_a_type_of to be consistent
+
+{
+    package moosex::types::structured::bug_is_subtype;
+
+    use Moose;
+    use MooseX::Types -declare => [qw/ ThingType  /];
+    use MooseX::Types::Moose qw/ Int Str /;
+    use MooseX::Types::Structured  qw/ Dict /;
+
+    subtype ThingType, as Dict [ id  => Int, name => Str, ];
+    has thing => ( is => 'ro', isa =>  ThingType, );
+}
+
+ok my $test = moosex::types::structured::bug_is_subtype->new,
+  'created class';
+
+is(
+  moosex::types::structured::bug_is_subtype::ThingType,
+  'moosex::types::structured::bug_is_subtype::ThingType',
+  'correct type',
+);
+
+use MooseX::Types::Moose 'HashRef';
+
+is(
+  HashRef,
+  'HashRef',
+  'correct type',
+);
+
+ok(
+  moosex::types::structured::bug_is_subtype::ThingType->is_subtype_of(HashRef),
+  'is a subtype',
+);
+
+ok(
+  !moosex::types::structured::bug_is_subtype::ThingType
+    ->is_subtype_of(moosex::types::structured::bug_is_subtype::ThingType),
+  'is not a subtype',
+);
+
+ok(
+  !moosex::types::structured::bug_is_subtype::ThingType
+    ->is_subtype_of('SomeCrap'),
+  'is not a subtype',
+);
+
+sub SomeCrap {}
+
+ok(
+  !moosex::types::structured::bug_is_subtype::ThingType
+    ->is_subtype_of(SomeCrap),
+  'is not a subtype',
+);
+
+ok(
+  !moosex::types::structured::bug_is_subtype::ThingType
+    ->is_subtype_of(undef),
+  'is not a subtype',
+);
+
+ok(
+  !moosex::types::structured::bug_is_subtype::ThingType
+    ->equal(undef),
+  'is not a subtype',
+);
+
+ok(
+  !moosex::types::structured::bug_is_subtype::ThingType
+    ->is_a_type_of(undef),
+  'is not a subtype',
+);
+
+
+done_testing;