all new tests in place that must work with the (pending) update to Moose and MX:Types
John Napiorkowski [Fri, 28 May 2010 19:50:43 +0000 (15:50 -0400)]
lib/MooseX/Meta/TypeConstraint/Structured.pm
t/regressions/01-is_type_of.t

index a9aa0e5..44691e4 100644 (file)
@@ -232,9 +232,7 @@ sub is_a_type_of {
 
 sub is_subtype_of {
     my ( $self, $type_or_name ) = @_;
-
     my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
-
     if ( $other->isa(__PACKAGE__) ) {
         if ( $other->type_constraints and $self->type_constraints ) {
             if ( $self->parent->is_a_type_of($other->parent) ) {
@@ -294,7 +292,8 @@ sub _type_constraints_op_all {
         $_ = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($_)
           for $self_type_constraint, $other_type_constraint;
 
-        $self_type_constraint->$op($other_type_constraint) or return;
+        my $result = $self_type_constraint->$op($other_type_constraint);
+        return unless $result;
     }
     
     return 1; ##If we get this far, everything is good.
index ec6edec..d8ca76d 100644 (file)
@@ -1,7 +1,7 @@
 BEGIN {
        use strict;
        use warnings;
-       use Test::More tests=>5;
+       use Test::More tests=>11;
 }
 
 {
@@ -23,17 +23,21 @@ BEGIN {
 
 }
 
-use Moose::Util::TypeConstraints;
-use MooseX::Types::Structured qw(Dict Tuple);
-use MooseX::Types::Moose qw(Int Str Item Object ArrayRef HashRef);
-
 BEGIN {
     TypeLib->import(':all');
 }
 
+use Moose::Util::TypeConstraints;
+use MooseX::Types::Structured qw(Dict Tuple);
+use MooseX::Types::Moose qw(Item Any);
+
+
 ok ( MyDict2->is_a_type_of(MyDict4),
   'MyDict2 is_a_type_of MyDict4');
 
+ok ( MyDict1->is_subtype_of(MyDict4),
+  'MyDict1 is_subtype_of MyDict4');
+
 ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->is_a_type_of( Tuple[Tuple[ Item, Item ], Dict[]] ),
   "tuple of tuple" );
 
@@ -43,6 +47,29 @@ ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->is_a_ty
 ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->is_subtype_of( Tuple[Tuple[ Item, Item ], Dict[]] ),
   "tuple of tuple" );
 
-ok ( MyDict1->is_subtype_of(MyDict4),
-  'MyDict1 is_subtype_of MyDict4');
+my $item = subtype as 'Item';
+
+ok ( $item->is_subtype_of('Any'),
+  q[$item is subtype of 'Any']);
+
+ok ( Item->is_subtype_of('Any'),
+  q[Item is subtype of 'Any']);
+
+ok ( $item->is_subtype_of(Any),
+  q[Item is subtype of Any]);
+
+ok ( Item->is_subtype_of(Any),
+  q[Item is subtype of Any]);
+
+my $any = subtype as 'Any';
+
+ok ( ! $item->is_subtype_of($any),
+  q[$item is NOT a subtype of $any]);
+
+ok ( ! Item->is_subtype_of($any),
+  q[Item is NOT a subtype of $any]);
+
+__END__
+
 
+