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