just restored some bits so that tests all pass, incase anyone wants to play with...
[gitmo/MooseX-Types-Structured.git] / t / 01-basic.t
CommitLineData
bfef1b30 1BEGIN {
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';
dbd75632 8 use_ok 'MooseX::Meta::TypeConstraint::Structured::Generator';
7e2f0558 9 use_ok 'MooseX::Meta::TypeConstraint::Structured::Positional';
10 use_ok 'MooseX::Meta::TypeConstraint::Structured::Named';
bfef1b30 11}
12
dbd75632 13my $tuple = MooseX::Meta::TypeConstraint::Structured::Generator->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 20Moose::Util::TypeConstraints::register_type_constraint($tuple);
bfef1b30 21
011bacc6 22## Make sure the new type constraints have been registered
bfef1b30 23
011bacc6 24ok Moose::Util::TypeConstraints::find_type_constraint('Tuple')
25 => 'Found the Tuple Type';
bfef1b30 26
bfef1b30 27{
dbd75632 28 package Test::MooseX::Types::Structured::BasicAttributes;
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
dbd75632 37ok my $positioned_obj = Test::MooseX::Types::Structured::BasicAttributes->new,
bfef1b30 38 => 'Got a good object';
39
011bacc6 40ok $positioned_obj->tuple([1,'hello',3])
41 => "[1,'hello',3] properly suceeds";
42
43throws_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 47throws_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
51throws_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]]';