rename postionalable to a more generic name
[gitmo/MooseX-Types-Structured.git] / t / 01-basic.t
CommitLineData
bfef1b30 1BEGIN {
2 use strict;
3 use warnings;
011bacc6 4 use Test::More tests=>8;
bfef1b30 5 use Test::Exception;
6
7 use_ok 'Moose::Util::TypeConstraints';
8 use_ok 'MooseX::Meta::TypeConstraint::Structured::Positionable';
9}
10
bfef1b30 11
12my $tuple = MooseX::Meta::TypeConstraint::Structured::Positionable->new(
13 name => 'Tuple',
14 package_defined_in => __PACKAGE__,
15 parent => find_type_constraint('Ref'),
16 );
17
011bacc6 18Moose::Util::TypeConstraints::register_type_constraint($tuple);
bfef1b30 19
011bacc6 20## Make sure the new type constraints have been registered
bfef1b30 21
011bacc6 22ok Moose::Util::TypeConstraints::find_type_constraint('Tuple')
23 => 'Found the Tuple Type';
bfef1b30 24
25
26{
27 package Test::MooseX::Types::Structured::Positionable;
bfef1b30 28
011bacc6 29 use Moose;
30 use Moose::Util::TypeConstraints;
bfef1b30 31
011bacc6 32 has 'tuple' => (is=>'rw', isa=>'Tuple[Int,Str,Int]');
bfef1b30 33}
34
011bacc6 35
bfef1b30 36ok my $positioned_obj = Test::MooseX::Types::Structured::Positionable->new,
37 => 'Got a good object';
38
011bacc6 39ok $positioned_obj->tuple([1,'hello',3])
40 => "[1,'hello',3] properly suceeds";
41
42throws_ok sub {
43 $positioned_obj->tuple([1,2,'world']);
44}, qr/Validation failed for 'Int' failed with value world/ => "[1,2,'world'] properly fails";
bfef1b30 45
011bacc6 46throws_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
50throws_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]]';