From: Dave Rolsky Date: Fri, 24 Oct 2008 02:44:48 +0000 (+0000) Subject: Add tests for creating subtype of a Class type constraint. X-Git-Tag: 0.60~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=81e727db79c8beb634285833f4a0aeb70b7ee4c9;p=gitmo%2FMoose.git Add tests for creating subtype of a Class type constraint. --- diff --git a/t/040_type_constraints/030-class_subtypes.t b/t/040_type_constraints/030-class_subtypes.t index 275a033..4eb88b5 100644 --- a/t/040_type_constraints/030-class_subtypes.t +++ b/t/040_type_constraints/030-class_subtypes.t @@ -3,13 +3,12 @@ use strict; use warnings; -use Test::More tests => 16; +use Test::More tests => 18; use Test::Exception; -BEGIN { - use_ok('Moose::Util::TypeConstraints'); - use_ok('Moose::Meta::TypeConstraint'); -} +use Moose::Util::TypeConstraints; +use Moose::Meta::TypeConstraint; + ## Create a subclass with a custom method @@ -23,7 +22,7 @@ BEGIN { } } -my $Int = Moose::Util::TypeConstraints::find_type_constraint('Int'); +my $Int = find_type_constraint('Int'); ok $Int, 'Got a good type contstraint'; my $parent = Test::Moose::Meta::TypeConstraint::AnySubType->new({ @@ -36,8 +35,7 @@ ok $parent->check(1), 'Correctly passed'; ok ! $parent->check('a'), 'correctly failed'; ok $parent->my_custom_method, 'found the custom method'; -my $subtype1 = Moose::Util::TypeConstraints::subtype 'another_subtype', - as $parent; +my $subtype1 = subtype 'another_subtype' => as $parent; ok $subtype1, 'Created type constraint'; ok $subtype1->check(1), 'Correctly passed'; @@ -45,13 +43,40 @@ ok ! $subtype1->check('a'), 'correctly failed'; ok $subtype1->my_custom_method, 'found the custom method'; -my $subtype2 = Moose::Util::TypeConstraints::subtype 'another_subtype', - as $subtype1, - where { $_ < 10 }; +my $subtype2 = subtype 'another_subtype' => as $subtype1 => where { $_ < 10 }; ok $subtype2, 'Created type constraint'; ok $subtype2->check(1), 'Correctly passed'; ok ! $subtype2->check('a'), 'correctly failed'; ok ! $subtype2->check(100), 'correctly failed'; -ok $subtype2->my_custom_method, 'found the custom method'; \ No newline at end of file +ok $subtype2->my_custom_method, 'found the custom method'; + + +{ + package Foo; + + use Moose; +} + +{ + package Bar; + + use Moose; + + extends 'Foo'; +} + +{ + package Baz; + + use Moose; +} + +my $foo = class_type 'Foo'; +my $isa_foo = subtype 'IsaFoo' => as $foo; + +ok $isa_foo, 'Created subtype of Foo type'; +ok $isa_foo->check( Foo->new ), 'Foo passes check'; +ok $isa_foo->check( Bar->new ), 'Bar passes check'; +ok ! $isa_foo->check( Baz->new ), 'Baz does not pass check';