From: Hans Dieter Pearcey Date: Fri, 24 Apr 2009 20:28:10 +0000 (-0400) Subject: tests for selective coercion X-Git-Tag: 0.76~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=88071df79c9e902b76e7793c8ca1caa04ee9e20a;p=gitmo%2FMoose.git tests for selective coercion --- diff --git a/t/040_type_constraints/005_util_type_coercion.t b/t/040_type_constraints/005_util_type_coercion.t index e4a0492..a6feaa4 100644 --- a/t/040_type_constraints/005_util_type_coercion.t +++ b/t/040_type_constraints/005_util_type_coercion.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 24; +use Test::More tests => 26; use Test::Exception; BEGIN { @@ -88,3 +88,23 @@ foreach my $coercion ( is($coerced, "Foo", '... got back what we put in'); } } + +subtype 'MyHashRef' + => as 'HashRef' + => where { $_->{is_awesome} }; + +coerce 'MyHashRef' + => from 'HashRef' + => via { $_->{my_hash_ref} }; + +my $tc = find_type_constraint('MyHashRef'); +is_deeply( + $tc->coerce({ my_hash_ref => { is_awesome => 1 } }), + { is_awesome => 1 }, + "coercion runs on HashRef (not MyHashRef)", +); +is_deeply( + $tc->coerce({ is_awesome => 1 }), + { is_awesome => 1 }, + "did not coerce MyHashRef", +);