4 use Test::More tests=>16;
9 package Test::MooseX::Meta::TypeConstraint::Structured::Advanced;
12 use MooseX::Types::Structured qw(Dict Tuple);
13 use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef Maybe);
14 use MooseX::Types -declare => [qw(
15 EqualLength MoreThanFive MoreLengthPlease PersonalInfo MorePersonalInfo
23 ## Tuple contains two equal length Arrays
25 as Tuple[ArrayRef[MoreThanFive],ArrayRef[MoreThanFive]],
26 where { $#{$_->[0]} == $#{$_->[1]} };
28 ## subclass the complex tuple
29 subtype MoreLengthPlease,
31 where { $#{$_->[0]} >= 4};
35 as Dict[name=>Str, stats=>MoreLengthPlease|Object];
37 ## Minimum 5 char string
40 where { length($_) > 5};
42 ## Dict key overloading
43 subtype MorePersonalInfo,
44 # as PersonalInfo[name=>MinFiveChars];
47 has 'EqualLengthAttr' => (is=>'rw', isa=>EqualLength);
48 has 'MoreLengthPleaseAttr' => (is=>'rw', isa=>MoreLengthPlease);
49 has 'PersonalInfoAttr' => (is=>'rw', isa=>PersonalInfo);
50 has 'MorePersonalInfo' => (is=>'rw', isa=>MorePersonalInfo);
53 ## Instantiate a new test object
55 ok my $obj = Test::MooseX::Meta::TypeConstraint::Structured::Advanced->new
56 => 'Instantiated new Record test class.';
58 isa_ok $obj => 'Test::MooseX::Meta::TypeConstraint::Structured::Advanced'
59 => 'Created correct object type.';
61 ## Test EqualLengthAttr
64 $obj->EqualLengthAttr([[6,7,8],[9,10,11]]);
65 } => 'Set EqualLengthAttr attribute without error';
68 $obj->EqualLengthAttr([1,'hello', 'test.xxx.test']);
69 }, qr/Attribute \(EqualLengthAttr\) does not pass the type constraint/
70 => q{EqualLengthAttr correctly fails [1,'hello', 'test.xxx.test']};
73 $obj->EqualLengthAttr([[6,7],[9,10,11]]);
74 }, qr/Attribute \(EqualLengthAttr\) does not pass the type constraint/
75 => q{EqualLengthAttr correctly fails [[6,7],[9,10,11]]};
78 $obj->EqualLengthAttr([[6,7,1],[9,10,11]]);
79 }, qr/Attribute \(EqualLengthAttr\) does not pass the type constraint/
80 => q{EqualLengthAttr correctly fails [[6,7,1],[9,10,11]]};
82 ## Test MoreLengthPleaseAttr
85 $obj->MoreLengthPleaseAttr([[6,7,8,9,10],[11,12,13,14,15]]);
86 } => 'Set MoreLengthPleaseAttr attribute without error';
89 $obj->MoreLengthPleaseAttr([[6,7,8,9],[11,12,13,14]]);
90 }, qr/Attribute \(MoreLengthPleaseAttr\) does not pass the type constraint/
91 => q{MoreLengthPleaseAttr correctly fails [[6,7,8,9],[11,12,13,14]]};
93 ## Test PersonalInfoAttr
96 $obj->PersonalInfoAttr({name=>'John', stats=>[[6,7,8,9,10],[11,12,13,14,15]]});
97 } => 'Set PersonalInfoAttr attribute without error 1';
100 $obj->PersonalInfoAttr({name=>'John', stats=>$obj});
101 } => 'Set PersonalInfoAttr attribute without error 2';
104 $obj->PersonalInfoAttr({name=>'John', stats=>[[6,7,8,9],[11,12,13,14]]});
105 }, qr/Attribute \(PersonalInfoAttr\) does not pass the type constraint/
106 => q{PersonalInfoAttr correctly fails name=>'John', stats=>[[6,7,8,9],[11,12,13,14]]};
109 $obj->PersonalInfoAttr({name=>'John', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]});
110 }, qr/Attribute \(PersonalInfoAttr\) does not pass the type constraint/
111 => q{PersonalInfoAttr correctly fails name=>'John', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]};
113 ## Test MorePersonalInfo
116 $obj->MorePersonalInfo({name=>'Johnnap', stats=>[[6,7,8,9,10],[11,12,13,14,15]]});
117 } => 'Set MorePersonalInfo attribute without error 1';
120 $obj->MorePersonalInfo({name=>'Johnnap', stats=>[[6,7,8,9],[11,12,13,14]]});
121 }, qr/Attribute \(MorePersonalInfo\) does not pass the type constraint/
122 => q{MorePersonalInfo correctly fails name=>'Johnnap', stats=>[[6,7,8,9],[11,12,13,14]]};
125 $obj->MorePersonalInfo({name=>'Johnnap', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]});
126 }, qr/Attribute \(MorePersonalInfo\) does not pass the type constraint/
127 => q{MorePersonalInfo correctly fails name=>'Johnnap', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]};
130 skip 'not yet working', 1;
133 $obj->MorePersonalInfo({name=>'abc', stats=>[[6,7,8,9,10],[11,12,13,14,15]]});
134 }, qr/Attribute \(MorePersonalInfo\) does not pass the type constraint/
135 => q{MorePersonalInfo correctly fails name=>'aaa', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]};