Correct error message to include 'Maybe' as implemented parametric type.
[gitmo/Mouse.git] / t / 041-enum.t
CommitLineData
d44f0d03 1#!/usr/bin/env perl
2use strict;
3use warnings;
01904723 4use Test::More tests => 16;
d44f0d03 5use Test::Exception;
6
7do {
8 package Shirt;
9 use Mouse;
10 use Mouse::Util::TypeConstraints 'enum';
11
12 enum 'Size' => qw(small medium large);
13
14 has size => (
15 is => 'rw',
16 isa => 'Size',
17 );
01904723 18
19 package Shirt::Anon;
20 use Mouse;
21 use Mouse::Util::TypeConstraints 'enum';
22
23 has size => (
24 is => 'rw',
25 isa => enum ['small', 'medium', 'large'],
26 );
d44f0d03 27};
28
01904723 29for my $class ('Shirt', 'Shirt::Anon') {
30 ok($class->new(size => 'small'));
31 ok($class->new(size => 'medium'));
32 ok($class->new(size => 'large'));
d44f0d03 33
01904723 34 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/;
35 throws_ok { $class->new(size => 'Small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value Small/;
36 throws_ok { $class->new(size => '') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value /;
37 throws_ok { $class->new(size => 'small ') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value small /;
38 throws_ok { $class->new(size => ' small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value small/;
39}
d44f0d03 40