X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F02-constraints.t;h=86c4e6ce682b699762f67fabb086ce27815e8821;hb=78f559467710da345f5d08c2fea40da4d75ed8ee;hp=5bceb08d18c00a8575b00475f9ce6243e2d523cb;hpb=67be6b65eafdcc510a27f502aaad8070dc0674b3;p=gitmo%2FMooseX-Types-Structured.git diff --git a/t/02-constraints.t b/t/02-constraints.t index 5bceb08..86c4e6c 100644 --- a/t/02-constraints.t +++ b/t/02-constraints.t @@ -10,21 +10,23 @@ BEGIN { use Moose; use MooseX::Types::Structured qw(Tuple Dict Optional); + use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef Maybe); + use MooseX::Types -declare => [qw(MyString)]; use Moose::Util::TypeConstraints; - subtype 'MyString', + subtype MyString, as 'Str', where { $_=~m/abc/}; - has 'tuple' => (is=>'rw', isa=>Tuple['Int', 'Str', 'MyString']); - has 'dict' => (is=>'rw', isa=>Dict[name=>'Str', age=>'Int']); - has 'dict_with_maybe' => (is=>'rw', isa=>Dict[name=>'Str', age=>'Maybe[Int]']); - has 'tuple_with_param' => (is=>'rw', isa=>Tuple['Int', 'Str', 'ArrayRef[Int]']); - has 'tuple_with_maybe' => (is=>'rw', isa=>Tuple['Int', 'Str', 'Maybe[Int]']); - has 'dict_with_tuple' => (is=>'rw', isa=>Dict[key1=>'Str', key2=>Tuple['Int','Str']]); - has 'optional_tuple' => (is=>'rw', isa=>Tuple['Int', 'Int', Optional['Int']] ); - has 'optional_dict' => (is=>'rw', isa=>Dict[key1=>'Int', Optional[key2=>'Int']] ); - has 'dict_with_tuple_with_union' => (is=>'rw', isa=>Dict[key1=>'Str|Object', key2=>Tuple['Int','Str|Object']] ); + has 'tuple' => (is=>'rw', isa=>Tuple[Int, Str, MyString]); + has 'dict' => (is=>'rw', isa=>Dict[name=>Str, age=>Int]); + has 'dict_with_maybe' => (is=>'rw', isa=>Dict[name=>Str, age=>Maybe[Int]]); + has 'tuple_with_param' => (is=>'rw', isa=>Tuple[Int, Str, ArrayRef[Int]]); + has 'tuple_with_maybe' => (is=>'rw', isa=>Tuple[Int, Str, Maybe[Int]]); + has 'dict_with_tuple' => (is=>'rw', isa=>Dict[key1=>Str, key2=>Tuple[Int,Str]]); + has 'optional_tuple' => (is=>'rw', isa=>Tuple[Int, Int, Optional[Int]] ); + has 'optional_dict' => (is=>'rw', isa=>Dict[key1=>Int, Optional[key2=>Int]] ); + has 'dict_with_tuple_with_union' => (is=>'rw', isa=>Dict[key1=>Str|Object, key2=>Tuple[Int,Str|Object]] ); has 'crazy' => ( is=>'rw', @@ -32,15 +34,15 @@ BEGIN { ## First ArrayRef Arg is the required type constraints for the top ## level Tuple. [ - 'Int', - 'MyString', + Int, + MyString, ## The third required element is a Dict type constraint, which ## itself has two required keys and a third optional key. - Dict[name=>'Str',age=>'Int', Optional[visits=>'Int']], + Dict[name=>Str,age=>Int, Optional[visits=>Int]], Optional[ - 'Int', + Int, ## This Tuple has one required type constraint and two optional. - Tuple['Int', Optional['Int','HashRef']], + Tuple[Int, Optional[Int,HashRef]], ], ], );