From: Shawn M Moore Date: Sat, 26 Jan 2008 16:54:47 +0000 (+0000) Subject: Failing tests for custom type error messages. Now let's see about making them pass.. X-Git-Tag: 0_37~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f5f2d4828548e91cd7f8165614206d8ba3b96024;p=gitmo%2FMoose.git Failing tests for custom type error messages. Now let's see about making them pass.. --- diff --git a/t/040_type_constraints/022_custom_type_errors.t b/t/040_type_constraints/022_custom_type_errors.t new file mode 100644 index 0000000..7063e20 --- /dev/null +++ b/t/040_type_constraints/022_custom_type_errors.t @@ -0,0 +1,55 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 8; +use Test::Exception; + +{ + package Animal; + use Moose; + BEGIN { + ::use_ok("Moose::Util::TypeConstraints"); + } + + subtype 'Natural' + => as 'Int' + => where { $_ > 0 } + => message { "This number ($_) is not a positive integer!" }; + + subtype 'NaturalLessThanTen' + => as 'Natural' + => where { $_ < 10 } + => message { "This number ($_) is not less than ten!" }; + + has leg_count => ( + is => 'rw', + isa => 'NaturalLessThanTen', + ); +} + +lives_ok { my $goat = Animal->new(leg_count => 4) }; +lives_ok { my $spider = Animal->new(leg_count => 8) }; + +throws_ok { my $fern = Animal->new(leg_count => 0) } + qr/^This number \(0\) is not a positive integer!/, + "gave custom supertype error message on new"; + +throws_ok { my $centipede = Animal->new(leg_count => 30) } + qr/^This number \(30\) is not less than ten!/, + "gave custom subtype error message on new"; + +my $chimera; +lives_ok { $chimera = Animal->new(leg_count => 4) }; + +# first we remove the lion's legs.. +throws_ok { $chimera->leg_count(0) } + qr/^This number \(0\) is not a positive integer!/, + "gave custom supertype error message on set_value"; + +# mix in a few octopodes +throws_ok { $chimera->leg_count(16) } + qr/^This number \(16\) is not less than ten!/, + "gave custom subtype error message on set_value"; +