4 use Test::More tests=>8;
7 use_ok 'Moose::Util::TypeConstraints';
8 use_ok 'MooseX::Meta::TypeConstraint::Structured::Positionable';
12 my $tuple = MooseX::Meta::TypeConstraint::Structured::Positionable->new(
14 package_defined_in => __PACKAGE__,
15 parent => find_type_constraint('Ref'),
18 Moose::Util::TypeConstraints::register_type_constraint($tuple);
20 ## Make sure the new type constraints have been registered
22 ok Moose::Util::TypeConstraints::find_type_constraint('Tuple')
23 => 'Found the Tuple Type';
27 package Test::MooseX::Types::Structured::Positionable;
30 use Moose::Util::TypeConstraints;
32 has 'tuple' => (is=>'rw', isa=>'Tuple[Int,Str,Int]');
36 ok my $positioned_obj = Test::MooseX::Types::Structured::Positionable->new,
37 => 'Got a good object';
39 ok $positioned_obj->tuple([1,'hello',3])
40 => "[1,'hello',3] properly suceeds";
43 $positioned_obj->tuple([1,2,'world']);
44 }, qr/Validation failed for 'Int' failed with value world/ => "[1,2,'world'] properly fails";
47 $positioned_obj->tuple(['hello1',2,3]);
48 }, qr/Validation failed for 'Int' failed with value hello1/ => "['hello',2,3] properly fails";
51 $positioned_obj->tuple(['hello2',2,'world']);
52 }, qr/Validation failed for 'Int' failed with value hello2/ => "['hello',2,'world'] properly fails";
57 #ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint('HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]')
58 # => 'detected correctly';
61 # [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]')],
62 # ["HashRef", "key1", "Int", "key2", "Int", "key3", "ArrayRef[Int]"]
63 # => 'Correctly parsed HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]';