X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=t%2F041-enum.t;h=5546f4f1f32dcbaaf3e3c3ef0f72c197d58427fe;hp=731dcc1beee70df16242c0c60ef67a8ba8b00f7c;hb=019047233180625898edb43732965d0dbda7e4b0;hpb=2276cb146244298515808ff1a82b6b252e5448a7 diff --git a/t/041-enum.t b/t/041-enum.t index 731dcc1..5546f4f 100644 --- a/t/041-enum.t +++ b/t/041-enum.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 8; +use Test::More tests => 16; use Test::Exception; do { @@ -15,15 +15,26 @@ do { is => 'rw', isa => 'Size', ); + + package Shirt::Anon; + use Mouse; + use Mouse::Util::TypeConstraints 'enum'; + + has size => ( + is => 'rw', + isa => enum ['small', 'medium', 'large'], + ); }; -ok(Shirt->new(size => 'small')); -ok(Shirt->new(size => 'medium')); -ok(Shirt->new(size => 'large')); +for my $class ('Shirt', 'Shirt::Anon') { + ok($class->new(size => 'small')); + ok($class->new(size => 'medium')); + ok($class->new(size => 'large')); -throws_ok { Shirt->new(size => 'extra small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for 'Size' failed with value extra small/; -throws_ok { Shirt->new(size => 'Small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for 'Size' failed with value Small/; -throws_ok { Shirt->new(size => '') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for 'Size' failed with value /; -throws_ok { Shirt->new(size => 'small ') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for 'Size' failed with value small /; -throws_ok { Shirt->new(size => ' small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for 'Size' failed with value small/; + throws_ok { $class->new(size => 'extra small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value extra small/; + throws_ok { $class->new(size => 'Small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value Small/; + throws_ok { $class->new(size => '') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value /; + throws_ok { $class->new(size => 'small ') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value small /; + throws_ok { $class->new(size => ' small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value small/; +}