diff options
author | Toby Inkster <mail@tobyinkster.co.uk> | 2013-05-13 16:18:15 +0100 |
---|---|---|
committer | Toby Inkster <mail@tobyinkster.co.uk> | 2013-05-13 16:18:15 +0100 |
commit | f881708e55c75c16966ae3ecec831613b9b5c1b9 (patch) | |
tree | 65e98737e8bf94404fadccd79843441424575c19 /t | |
parent | dcfd5ed609e58c6645fc6a7bfba973c5f342204b (diff) |
shlomif wants these tests
Diffstat (limited to 't')
-rw-r--r-- | t/05haveimissedanytypes.t | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/t/05haveimissedanytypes.t b/t/05haveimissedanytypes.t new file mode 100644 index 0000000..f42430c --- /dev/null +++ b/t/05haveimissedanytypes.t @@ -0,0 +1,67 @@ + +use strict; +use warnings; +use Test::More; + +require Moo; + +my @types_to_check = qw( + Any + Item + Bool + Maybe + Maybe[Int] + Undef + Defined + Value + Str + Num + Int + ClassName + RoleName + Ref + ScalarRef + ScalarRef[Int] + ArrayRef + ArrayRef[Int] + HashRef + HashRef[Int] + CodeRef + RegexpRef + GlobRef + FileHandle + Object +); + +my $count = 0; +sub constraint_for +{ + my $type = shift; + my $class = "Local::Test" . ++$count; + + eval qq{ + package $class; + use Moo; + use MooX::late; + has attr => (is => "ro", isa => "$type"); + 1; + } or die $@; + + "Moo"->_constructor_maker_for($class)->all_attribute_specs->{attr}{isa}; +} + +for my $type (@types_to_check) +{ + my $got = constraint_for($type); + isa_ok($got, "Type::Tiny", "constraint_for('$type')"); + is("$got", "$type", "Type constraint returned for '$type' looks right."); +} + +for my $type ("Local::Test1") +{ + my $got = constraint_for($type); + isa_ok($got, "Type::Tiny::Class", "constraint_for('$type')"); + is($got->class, $type, "Type constraint returned for '$type' looks right."); +} + +done_testing; |