X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F040_type_constraints%2F021_maybe_type_constraint.t;h=06528d30975afbe7ad0351e0009dc8e1db49b8d1;hb=d4d3bd093a5653b9a5fe106768e527d2fd910950;hp=e59f501eb806194d231ed795c0d9a0dbfc4b6da3;hpb=7e4e1ad46fd4c72845b18df57a80cdc03b47c4c4;p=gitmo%2FMoose.git diff --git a/t/040_type_constraints/021_maybe_type_constraint.t b/t/040_type_constraints/021_maybe_type_constraint.t index e59f501..06528d3 100644 --- a/t/040_type_constraints/021_maybe_type_constraint.t +++ b/t/040_type_constraints/021_maybe_type_constraint.t @@ -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)');