X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F06-api.t;h=37e09afa36ceb9465bb083b4ea044fd7dadf7cad;hb=5ac93dbb32df5bdf286efab5cca11423083b8a57;hp=cbfb6873e36b90137934ac7e194787599a8eea53;hpb=179af711f82dd08536a45a6d915978e6bd59d433;p=gitmo%2FMooseX-Types-Structured.git diff --git a/t/06-api.t b/t/06-api.t index cbfb687..37e09af 100644 --- a/t/06-api.t +++ b/t/06-api.t @@ -1,50 +1,60 @@ BEGIN { - use strict; - use warnings; - use Test::More tests=>83; + use strict; + use warnings; + use Test::More tests=>88; } -use Moose::Util::TypeConstraints; -use MooseX::Types::Structured qw(Dict Tuple); -use MooseX::Types::Moose qw(Int Str Item Object ArrayRef HashRef); -use MooseX::Types -declare => [qw( - MyDict1 MyDict2 MyDict3 MyDict4 subMyDict3 subMyDict1 - MyTuple1 MyTuple2 MyTuple3 subMyTuple3 -)]; +{ + package TypeLib; + use MooseX::Types::Structured qw(Dict Tuple); + use MooseX::Types::Moose qw(Int Str Item Object ArrayRef HashRef); + use MooseX::Types -declare => [qw( + MyDict1 MyDict2 MyDict3 MyDict4 subMyDict3 subMyDict1 + MyTuple1 MyTuple2 MyTuple3 subMyTuple3 + )]; + + ## Create some sample Dicts + + subtype MyDict1, + as Dict[name=>Str, age=>Int]; + + subtype subMyDict1, + as MyDict1; + + subtype MyDict2, + as Dict[name=>Str, age=>Int]; + + subtype MyDict3, + as Dict[key=>Int, anotherkey=>Str]; -## Create some sample Dicts + subtype subMyDict3, + as MyDict3; -subtype MyDict1, - as Dict[name=>Str, age=>Int]; + subtype MyDict4, + as Dict[name=>Str, age=>Item]; -subtype subMyDict1, - as MyDict1; + ## Create some sample Tuples -subtype MyDict2, - as Dict[name=>Str, age=>Int]; - -subtype MyDict3, - as Dict[key=>Int, anotherkey=>Str]; - -subtype subMyDict3, - as MyDict3; + subtype MyTuple1, + as Tuple[Int,Int,Str]; -subtype MyDict4, - as Dict[name=>Str, age=>Item]; + subtype MyTuple2, + as Tuple[Int,Int,Str]; -## Create some sample Tuples + subtype MyTuple3, + as Tuple[Object, HashRef]; -subtype MyTuple1, - as Tuple[Int,Int,Str]; + subtype subMyTuple3, + as MyTuple3; +} -subtype MyTuple2, - as Tuple[Int,Int,Str]; - -subtype MyTuple3, - as Tuple[Object, HashRef]; +use Moose::Util::TypeConstraints; +use MooseX::Types::Structured qw(Dict Tuple); +use MooseX::Types::Moose qw(Int Str Item Object ArrayRef HashRef); -subtype subMyTuple3, - as MyTuple3; +BEGIN { + TypeLib->import(':all'); +} ## Test equals @@ -112,6 +122,12 @@ ok (!MyTuple2->is_a_type_of(MyTuple3), 'MyTuple2 NOT is_a_type_of MyTuple3'); ## is_subtype_of +ok ( not((Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->equals( Tuple[Tuple[ Item, Item ], Dict[]] )), "tuple of tuple" ); +ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->equals( Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]] ), "tuple of tuple" ); +ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->is_a_type_of( Tuple[Tuple[ Item, Item ], Dict[]] ), "tuple of tuple" ); +ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->is_a_type_of( Tuple[Tuple[ Item, Item ], Dict[]] ), "tuple of tuple" ); +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(HashRef), 'MyDict1 is_subtype_of HashRef'); ok ( MyDict1->is_subtype_of(Dict), 'MyDict1 is_subtype_of Dict'); ok ( MyDict1->is_subtype_of(MyDict4), 'MyDict1 is_subtype_of MyDict4'); @@ -137,19 +153,19 @@ ok (!MyTuple2->is_subtype_of(MyTuple3), 'MyTuple2 NOT is_subtype_of MyTuple3'); PARAMETERIZE: { ok (my $int = Moose::Util::TypeConstraints::find_or_parse_type_constraint('Int'), 'Got Int'); - ok (my $str = Moose::Util::TypeConstraints::find_or_parse_type_constraint('Str'), 'Got Str'); - ok (my $hashref = Moose::Util::TypeConstraints::find_or_parse_type_constraint('HashRef[Int]'), 'Got HashRef'); + ok (my $str = Moose::Util::TypeConstraints::find_or_parse_type_constraint('Str'), 'Got Str'); + ok (my $hashref = Moose::Util::TypeConstraints::find_or_parse_type_constraint('HashRef[Int]'), 'Got HashRef'); ## Test Dict->parameterize ok (my $test_dict = Dict(), 'Created Test Dict'); ok (my $person = $test_dict->parameterize(name=>$str, age=>$int), 'Parameterized It'); ok ($person->check({name=>'John', age=>21}), 'Passed'); ok ($person->check({age=>25, name=>'User'}), 'Passed'); - + ## Test Tuple->parameterize ok (my $test_tuple = Tuple(), 'Created Test Tuple'); ok (my $int_and_hashref = $test_tuple->parameterize($int, $hashref), 'Parameterized It'); ok ($int_and_hashref->check([1, {key=>2, key2=>3}]), "Passed"); - ok (!$int_and_hashref->check(['a', {key=>2, key2=>3}]), "Not Passed"); + ok (!$int_and_hashref->check(['a', {key=>2, key2=>3}]), "Not Passed"); ok (!$int_and_hashref->check([1, {key=>'a', key2=>3}]), "Not Passed"); }