BEGIN {
use strict;
use warnings;
- use Test::More tests=>36;
+ use Test::More tests=>37;
use Test::Exception;
use_ok 'Moose::Util::TypeConstraints';
has 'tuple_with_optional' => (is=>'rw', isa=>'Tuple[Int,Str,Int,Optional[Int,Int]]');
has 'tuple_with_union' => (is=>'rw', isa=>'Tuple[Int,Str,Int|Object,Optional[Int|Object,Int]]');
- has 'dict' => (is=>'rw', isa=>'Dict[name=>Str, Age=>Int]');
- has 'dict_with_parameterized' => (is=>'rw', isa=>'Dict[name=>Str, Age=>Int, telephone=>ArrayRef[Int]]');
- has 'dict_with_optional' => (is=>'rw', isa=>'Dict[name=>Str, Age=>Int, Optional[opt1=>Str,Opt2=>Object]]');
+ has 'dict' => (is=>'rw', isa=>'Dict[name=>Str,age=>Int]');
+ has 'dict_with_parameterized' => (is=>'rw', isa=>'Dict[name=>Str, age=>Int, telephone=>ArrayRef[Int]]');
+ has 'dict_with_optional' => (is=>'rw', isa=>'Dict[name=>Str, age=>Int, Optional[opt1=>Str,opt2=>Object]]');
}
-#use Data::Dump qw/dump/;
-#warn dump Moose::Util::TypeConstraints::list_all_type_constraints;
-ok my $positioned_obj = Test::MooseX::Types::Structured::BasicAttributes->new,
+ok my $obj = Test::MooseX::Types::Structured::BasicAttributes->new,
=> 'Got a good object';
ok Moose::Util::TypeConstraints::find_type_constraint('Tuple[Int,Str,Int]')
ok Moose::Util::TypeConstraints::find_type_constraint('Tuple[Int,Str,Int,Optional[Int,Int]]')
=> 'Found expected type constraint';
+## dict Dict[name=>Str, Age=>Int]
+
+ok $obj->dict({name=>'John', age=>39})
+ => 'Dict[name=>Str, Age=>Int] properly succeeds';
+
+
+
+
+
+
## Test tuple (Tuple[Int,Str,Int])
-ok $positioned_obj->tuple([1,'hello',3])
+ok $obj->tuple([1,'hello',3])
=> "[1,'hello',3] properly suceeds";
throws_ok sub {
- $positioned_obj->tuple([1,2,'world']);
+ $obj->tuple([1,2,'world']);
}, qr/Validation failed for 'Int' failed with value world/ => "[1,2,'world'] properly fails";
throws_ok sub {
- $positioned_obj->tuple(['hello1',2,3]);
+ $obj->tuple(['hello1',2,3]);
}, qr/Validation failed for 'Int' failed with value hello1/ => "['hello',2,3] properly fails";
throws_ok sub {
- $positioned_obj->tuple(['hello2',2,'world']);
+ $obj->tuple(['hello2',2,'world']);
}, qr/Validation failed for 'Int' failed with value hello2/ => "['hello',2,'world'] properly fails";
## Test tuple_with_parameterized (Tuple[Int,Str,Int,ArrayRef[Int]])
-ok $positioned_obj->tuple_with_parameterized([1,'hello',3,[1,2,3]])
+ok $obj->tuple_with_parameterized([1,'hello',3,[1,2,3]])
=> "[1,'hello',3,[1,2,3]] properly suceeds";
throws_ok sub {
- $positioned_obj->tuple_with_parameterized([1,2,'world']);
+ $obj->tuple_with_parameterized([1,2,'world']);
}, qr/Validation failed for 'Int' failed with value world/ => "[1,2,'world'] properly fails";
throws_ok sub {
- $positioned_obj->tuple_with_parameterized(['hello1',2,3]);
+ $obj->tuple_with_parameterized(['hello1',2,3]);
}, qr/Validation failed for 'Int' failed with value hello1/ => "['hello',2,3] properly fails";
throws_ok sub {
- $positioned_obj->tuple_with_parameterized(['hello2',2,'world']);
+ $obj->tuple_with_parameterized(['hello2',2,'world']);
}, qr/Validation failed for 'Int' failed with value hello2/ => "['hello',2,'world'] properly fails";
throws_ok sub {
- $positioned_obj->tuple_with_parameterized([1,'hello',3,[1,2,'world']]);
+ $obj->tuple_with_parameterized([1,'hello',3,[1,2,'world']]);
}, qr/Validation failed for 'ArrayRef\[Int\]'/ => "[1,'hello',3,[1,2,'world']] properly fails";
## Test tuple_with_optional (Tuple[Int,Str,Int,Optional[Int,Int]])
-ok $positioned_obj->tuple_with_optional([1,'hello',3])
+ok $obj->tuple_with_optional([1,'hello',3])
=> "[1,'hello',3] properly suceeds";
-ok $positioned_obj->tuple_with_optional([1,'hello',3,1])
+ok $obj->tuple_with_optional([1,'hello',3,1])
=> "[1,'hello',3,1] properly suceeds";
-ok $positioned_obj->tuple_with_optional([1,'hello',3,4])
+ok $obj->tuple_with_optional([1,'hello',3,4])
=> "[1,'hello',3,4] properly suceeds";
-ok $positioned_obj->tuple_with_optional([1,'hello',3,4,5])
+ok $obj->tuple_with_optional([1,'hello',3,4,5])
=> "[1,'hello',3,4,5] properly suceeds";
throws_ok sub {
- $positioned_obj->tuple_with_optional([1,'hello',3,4,5,6]);
+ $obj->tuple_with_optional([1,'hello',3,4,5,6]);
}, qr/Too Many arguments for the available type constraints/ => "[1,'hello',3,4,5,6] properly fails";
throws_ok sub {
- $positioned_obj->tuple_with_optional([1,2,'world']);
+ $obj->tuple_with_optional([1,2,'world']);
}, qr/Validation failed for 'Int' failed with value world/ => "[1,2,'world'] properly fails";
throws_ok sub {
- $positioned_obj->tuple_with_optional(['hello1',2,3]);
+ $obj->tuple_with_optional(['hello1',2,3]);
}, qr/Validation failed for 'Int' failed with value hello1/ => "['hello',2,3] properly fails";
throws_ok sub {
- $positioned_obj->tuple_with_optional(['hello2',2,'world']);
+ $obj->tuple_with_optional(['hello2',2,'world']);
}, qr/Validation failed for 'Int' failed with value hello2/ => "['hello',2,'world'] properly fails";
## tuple_with_union Tuple[Int,Str,Int|Object,Optional[Int|Object,Int]]
skip "Unions not supported for string parsed type constraints" => 8;
- ok $positioned_obj->tuple_with_union([1,'hello',3])
+ ok $obj->tuple_with_union([1,'hello',3])
=> "[1,'hello',3] properly suceeds";
- ok $positioned_obj->tuple_with_union([1,'hello',3,1])
+ ok $obj->tuple_with_union([1,'hello',3,1])
=> "[1,'hello',3,1] properly suceeds";
- ok $positioned_obj->tuple_with_union([1,'hello',3,4])
+ ok $obj->tuple_with_union([1,'hello',3,4])
=> "[1,'hello',3,4] properly suceeds";
- ok $positioned_obj->tuple_with_union([1,'hello',3,4,5])
+ ok $obj->tuple_with_union([1,'hello',3,4,5])
=> "[1,'hello',3,4,5] properly suceeds";
throws_ok sub {
- $positioned_obj->tuple_with_union([1,'hello',3,4,5,6]);
+ $obj->tuple_with_union([1,'hello',3,4,5,6]);
}, qr/Too Many arguments for the available type constraints/ => "[1,'hello',3,4,5,6] properly fails";
throws_ok sub {
- $positioned_obj->tuple_with_union([1,2,'world']);
+ $obj->tuple_with_union([1,2,'world']);
}, qr/Validation failed for 'Int' failed with value world/ => "[1,2,'world'] properly fails";
throws_ok sub {
- $positioned_obj->tuple_with_union(['hello1',2,3]);
+ $obj->tuple_with_union(['hello1',2,3]);
}, qr/Validation failed for 'Int' failed with value hello1/ => "['hello',2,3] properly fails";
throws_ok sub {
- $positioned_obj->tuple_with_union(['hello2',2,'world']);
+ $obj->tuple_with_union(['hello2',2,'world']);
}, qr/Validation failed for 'Int' failed with value hello2/ => "['hello',2,'world'] properly fails";
}