Cosmetic changes (mostly from perltidy).
[gitmo/Moose.git] / t / 040_type_constraints / 021_maybe_type_constraint.t
index e59f501..06528d3 100644 (file)
@@ -3,18 +3,23 @@
 use strict;
 use warnings;
 
-use Test::More tests => 12;
+use Test::More tests => 17;
 use Test::Exception;
 
-BEGIN {
-    use_ok('Moose');
-    use_ok('Moose::Util::TypeConstraints');
-}
+use Moose::Util::TypeConstraints;
 
-my $type = Moose::Util::TypeConstraints::find_or_create_type_constraint('Maybe[Int]');
+my $type = Moose::Util::TypeConstraints::find_or_parse_type_constraint('Maybe[Int]');
 isa_ok($type, 'Moose::Meta::TypeConstraint');
 isa_ok($type, 'Moose::Meta::TypeConstraint::Parameterized');
 
+ok( $type->equals($type), "equals self" );
+ok( !$type->equals($type->parent), "not equal to parent" );
+ok( !$type->equals(find_type_constraint("Maybe")), "not equal to Maybe" );
+ok( $type->parent->equals(find_type_constraint("Maybe")), "parent is Maybe" );
+ok( $type->equals( Moose::Meta::TypeConstraint::Parameterized->new( name => "__ANON__", parent => find_type_constraint("Maybe"), type_parameter => find_type_constraint("Int") ) ), "equal to clone" );
+ok( !$type->equals( Moose::Meta::TypeConstraint::Parameterized->new( name => "__ANON__", parent => find_type_constraint("Maybe"), type_parameter => find_type_constraint("Str") ) ), "not equal to clone with diff param" );
+ok( !$type->equals( Moose::Util::TypeConstraints::find_or_parse_type_constraint('Maybe[Str]') ), "not equal to declarative version of diff param" );
+
 ok($type->check(10), '... checked type correctly (pass)');
 ok($type->check(undef), '... checked type correctly (pass)');
 ok(!$type->check('Hello World'), '... checked type correctly (fail)');