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, stats=>MoreLengthPlease|Object];
46 has 'EqualLengthAttr' => (is=>'rw', isa=>EqualLength);
47 has 'MoreLengthPleaseAttr' => (is=>'rw', isa=>MoreLengthPlease);
48 has 'PersonalInfoAttr' => (is=>'rw', isa=>PersonalInfo);
49 has 'MorePersonalInfo' => (is=>'rw', isa=>MorePersonalInfo);
52 ## Instantiate a new test object
54 ok my $obj = Test::MooseX::Meta::TypeConstraint::Structured::Advanced->new
55 => 'Instantiated new Record test class.';
57 isa_ok $obj => 'Test::MooseX::Meta::TypeConstraint::Structured::Advanced'
58 => 'Created correct object type.';
60 ## Test EqualLengthAttr
63 $obj->EqualLengthAttr([[6,7,8],[9,10,11]]);
64 } => 'Set EqualLengthAttr attribute without error';
67 $obj->EqualLengthAttr([1,'hello', 'test.xxx.test']);
68 }, qr/Attribute \(EqualLengthAttr\) does not pass the type constraint/
69 => q{EqualLengthAttr correctly fails [1,'hello', 'test.xxx.test']};
72 $obj->EqualLengthAttr([[6,7],[9,10,11]]);
73 }, qr/Attribute \(EqualLengthAttr\) does not pass the type constraint/
74 => q{EqualLengthAttr correctly fails [[6,7],[9,10,11]]};
77 $obj->EqualLengthAttr([[6,7,1],[9,10,11]]);
78 }, qr/Attribute \(EqualLengthAttr\) does not pass the type constraint/
79 => q{EqualLengthAttr correctly fails [[6,7,1],[9,10,11]]};
81 ## Test MoreLengthPleaseAttr
84 $obj->MoreLengthPleaseAttr([[6,7,8,9,10],[11,12,13,14,15]]);
85 } => 'Set MoreLengthPleaseAttr attribute without error';
88 $obj->MoreLengthPleaseAttr([[6,7,8,9],[11,12,13,14]]);
89 }, qr/Attribute \(MoreLengthPleaseAttr\) does not pass the type constraint/
90 => q{MoreLengthPleaseAttr correctly fails [[6,7,8,9],[11,12,13,14]]};
92 ## Test PersonalInfoAttr
95 $obj->PersonalInfoAttr({name=>'John', stats=>[[6,7,8,9,10],[11,12,13,14,15]]});
96 } => 'Set PersonalInfoAttr attribute without error 1';
99 $obj->PersonalInfoAttr({name=>'John', stats=>$obj});
100 } => 'Set PersonalInfoAttr attribute without error 2';
103 $obj->PersonalInfoAttr({name=>'John', stats=>[[6,7,8,9],[11,12,13,14]]});
104 }, qr/Attribute \(PersonalInfoAttr\) does not pass the type constraint/
105 => q{PersonalInfoAttr correctly fails name=>'John', stats=>[[6,7,8,9],[11,12,13,14]]};
108 $obj->PersonalInfoAttr({name=>'John', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]});
109 }, qr/Attribute \(PersonalInfoAttr\) does not pass the type constraint/
110 => q{PersonalInfoAttr correctly fails name=>'John', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]};
112 ## Test MorePersonalInfo
115 $obj->MorePersonalInfo({name=>'Johnnap', stats=>[[6,7,8,9,10],[11,12,13,14,15]]});
116 } => 'Set MorePersonalInfo attribute without error 1';
119 $obj->MorePersonalInfo({name=>'Johnnap', stats=>[[6,7,8,9],[11,12,13,14]]});
120 }, qr/Attribute \(MorePersonalInfo\) does not pass the type constraint/
121 => q{MorePersonalInfo correctly fails name=>'Johnnap', stats=>[[6,7,8,9],[11,12,13,14]]};
124 $obj->MorePersonalInfo({name=>'Johnnap', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]});
125 }, qr/Attribute \(MorePersonalInfo\) does not pass the type constraint/
126 => q{MorePersonalInfo correctly fails name=>'Johnnap', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]};
129 $obj->MorePersonalInfo({name=>'.bc', stats=>[[6,7,8,9,10],[11,12,13,14,15]]});
130 }, qr/Attribute \(MorePersonalInfo\) does not pass the type constraint/
131 => q{MorePersonalInfo correctly fails name=>'.bc', stats=>[[6,7,8,9,10],[11,12,13,14,15]]};