Commit | Line | Data |
bfef1b30 |
1 | BEGIN { |
2 | use strict; |
3 | use warnings; |
7e2f0558 |
4 | use Test::More tests=>10; |
bfef1b30 |
5 | use Test::Exception; |
6 | |
7 | use_ok 'Moose::Util::TypeConstraints'; |
7e2f0558 |
8 | use_ok 'MooseX::Meta::TypeConstraint::Structured::Structurable'; |
9 | use_ok 'MooseX::Meta::TypeConstraint::Structured::Positional'; |
10 | use_ok 'MooseX::Meta::TypeConstraint::Structured::Named'; |
bfef1b30 |
11 | } |
12 | |
7e2f0558 |
13 | my $tuple = MooseX::Meta::TypeConstraint::Structured::Structurable->new( |
bfef1b30 |
14 | name => 'Tuple', |
7e2f0558 |
15 | structured_type => 'MooseX::Meta::TypeConstraint::Structured::Positional', |
bfef1b30 |
16 | package_defined_in => __PACKAGE__, |
7e2f0558 |
17 | parent => find_type_constraint('ArrayRef'), |
bfef1b30 |
18 | ); |
19 | |
011bacc6 |
20 | Moose::Util::TypeConstraints::register_type_constraint($tuple); |
bfef1b30 |
21 | |
011bacc6 |
22 | ## Make sure the new type constraints have been registered |
bfef1b30 |
23 | |
011bacc6 |
24 | ok Moose::Util::TypeConstraints::find_type_constraint('Tuple') |
25 | => 'Found the Tuple Type'; |
bfef1b30 |
26 | |
bfef1b30 |
27 | { |
28 | package Test::MooseX::Types::Structured::Positionable; |
bfef1b30 |
29 | |
011bacc6 |
30 | use Moose; |
31 | use Moose::Util::TypeConstraints; |
bfef1b30 |
32 | |
011bacc6 |
33 | has 'tuple' => (is=>'rw', isa=>'Tuple[Int,Str,Int]'); |
bfef1b30 |
34 | } |
35 | |
011bacc6 |
36 | |
bfef1b30 |
37 | ok my $positioned_obj = Test::MooseX::Types::Structured::Positionable->new, |
38 | => 'Got a good object'; |
39 | |
011bacc6 |
40 | ok $positioned_obj->tuple([1,'hello',3]) |
41 | => "[1,'hello',3] properly suceeds"; |
42 | |
43 | throws_ok sub { |
44 | $positioned_obj->tuple([1,2,'world']); |
45 | }, qr/Validation failed for 'Int' failed with value world/ => "[1,2,'world'] properly fails"; |
bfef1b30 |
46 | |
011bacc6 |
47 | throws_ok sub { |
48 | $positioned_obj->tuple(['hello1',2,3]); |
49 | }, qr/Validation failed for 'Int' failed with value hello1/ => "['hello',2,3] properly fails"; |
50 | |
51 | throws_ok sub { |
52 | $positioned_obj->tuple(['hello2',2,'world']); |
53 | }, qr/Validation failed for 'Int' failed with value hello2/ => "['hello',2,'world'] properly fails"; |
54 | |
55 | |
56 | |
57 | |
58 | #ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint('HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]') |
59 | # => 'detected correctly'; |
60 | |
61 | #is_deeply |
62 | # [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]')], |
63 | # ["HashRef", "key1", "Int", "key2", "Int", "key3", "ArrayRef[Int]"] |
64 | # => 'Correctly parsed HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]'; |