X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=t%2F040_type_constraints%2Ffailing%2F010_misc_type_tests.t;fp=t%2F040_type_constraints%2Ffailing%2F010_misc_type_tests.t;h=43fcebc76cf11cc9c06b5e2f827191c4a7a9cc24;hp=0000000000000000000000000000000000000000;hb=b2b106d765ef1bcbb5ea3b215668baea1a9504b6;hpb=61fcd0dad2a4b4bc1f616b95b9c162597098503a diff --git a/t/040_type_constraints/failing/010_misc_type_tests.t b/t/040_type_constraints/failing/010_misc_type_tests.t new file mode 100644 index 0000000..43fcebc --- /dev/null +++ b/t/040_type_constraints/failing/010_misc_type_tests.t @@ -0,0 +1,67 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 11; +use Test::Exception; + +BEGIN { + use_ok('Mouse::Util::TypeConstraints'); +} + +# subtype 'aliasing' ... + +lives_ok { + subtype 'Numb3rs' => as 'Num'; +} '... create bare subtype fine'; + +my $numb3rs = find_type_constraint('Numb3rs'); +isa_ok($numb3rs, 'Mouse::Meta::TypeConstraint'); + +# subtype with unions + +{ + package Test::Mouse::Meta::TypeConstraint::Union; + + use overload '""' => sub {'Broken|Test'}, fallback => 1; + use Mouse; + + extends 'Mouse::Meta::TypeConstraint'; +} + +my $dummy_instance = Test::Mouse::Meta::TypeConstraint::Union->new; + +ok $dummy_instance => "Created Instance"; + +isa_ok $dummy_instance, + 'Test::Mouse::Meta::TypeConstraint::Union' => 'isa correct type'; + +is "$dummy_instance", "Broken|Test" => + 'Got expected stringification result'; + +my $subtype1 = subtype 'New1' => as $dummy_instance; + +ok $subtype1 => 'made a subtype from our type object'; + +my $subtype2 = subtype 'New2' => as $subtype1; + +ok $subtype2 => 'made a subtype of our subtype'; + +# assert_valid + +{ + my $type = find_type_constraint('Num'); + + my $ok_1 = eval { $type->assert_valid(1); }; + ok($ok_1, "we can assert_valid that 1 is of type $type"); + + my $ok_2 = eval { $type->assert_valid('foo'); }; + my $error = $@; + ok(! $ok_2, "'foo' is not of type $type"); + like( + $error, + qr{validation failed for .\Q$type\E.}i, + "correct error thrown" + ); +}