More type constraint fixes for edge cases in is_a_type_of and is_a_subtype_of when...
[gitmo/Moose.git] / t / 040_type_constraints / 016_subtyping_parameterized_types.t
index 2462c14..444b18a 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 18;
+use Test::More tests => 32;
 use Test::Exception;
 
 BEGIN {
@@ -28,6 +28,13 @@ lives_ok {
 
     ok($t->check({ one => 1, two => 2 }), '... validated it correctly');
     ok(!$t->check({ one => "ONE", two => "TWO" }), '... validated it correctly');
+
+    ok( $t->equals($t), "equals to self" );
+    ok( !$t->equals( $t->parent ), "not equal to parent" );
+    ok( $t->parent->equals( $t->parent ), "parent equals to self" );
+
+    ok( !$t->is_a_type_of("ThisTypeDoesNotExist"), "not a non existant type" );
+    ok( !$t->is_subtype_of("ThisTypeDoesNotExist"), "not a subtype of a non existant type" );
 }
 
 lives_ok {
@@ -56,3 +63,28 @@ lives_ok {
     ok(!$t->check({ one => "ONE", two => "TWO" }), '... validated it correctly');
 }
 
+lives_ok {
+    subtype 'MyNonSpecialHash'
+        => as "HashRef"
+        => where { keys %$_ == 3 };
+};
+
+{
+    my $t = find_type_constraint('MyNonSpecialHash');
+
+    isa_ok($t, 'Moose::Meta::TypeConstraint');
+    isa_ok($t, 'Moose::Meta::TypeConstraint::Parameterizable');
+
+    ok( $t->check({ one => 1, two => "foo", three => [] }), "validated" );
+    ok( !$t->check({ one => 1 }), "failed" );
+}
+
+{
+    my $t = Moose::Util::TypeConstraints::find_or_parse_type_constraint('MyNonSpecialHash[Int]');
+
+    isa_ok($t, 'Moose::Meta::TypeConstraint');
+
+    ok( $t->check({ one => 1, two => 2, three => 3 }), "validated" );
+    ok( !$t->check({ one => 1, two => "foo", three => [] }), "failed" );
+    ok( !$t->check({ one => 1 }), "failed" );
+}