TODO-ify failing tests
[gitmo/MooseX-AlwaysCoerce.git] / t / 01-basic.t
CommitLineData
ad1917d7 1#!/usr/bin/env perl
2use strict;
3use warnings;
4
0d42c8e8 5use Test::More tests => 8;
df491f72 6use Test::Exception;
0d42c8e8 7use Test::NoWarnings;
ad1917d7 8
9{
10 package MyClass;
11 use Moose;
ad1917d7 12 use MooseX::AlwaysCoerce;
13 use Moose::Util::TypeConstraints;
14
15 subtype 'MyType', as 'Int';
16 coerce 'MyType', from 'Str', via { length $_ };
17
6b46d35c 18 subtype 'Uncoerced', as 'Int';
19
ad1917d7 20 has foo => (is => 'rw', isa => 'MyType');
21
22 class_has bar => (is => 'rw', isa => 'MyType');
44b44091 23
24 class_has baz => (is => 'rw', isa => 'MyType', coerce => 0);
f327aa7a 25
26 has quux => (is => 'rw', isa => 'MyType', coerce => 0);
6b46d35c 27
28 has uncoerced_attr => (is => 'rw', isa => 'Uncoerced');
29
30 class_has uncoerced_class_attr => (is => 'rw', isa => 'Uncoerced');
ad1917d7 31}
32
33ok( (my $instance = MyClass->new), 'instance' );
34
df491f72 35lives_ok { $instance->foo('bar') } 'attribute coercion ran';
ad1917d7 36
df491f72 37lives_ok { $instance->bar('baz') } 'class attribute coercion ran';
44b44091 38
df491f72 39dies_ok { $instance->baz('quux') }
40 'class attribute coercion did not run with coerce => 0';
f327aa7a 41
df491f72 42dies_ok { $instance->quux('mtfnpy') }
43 'attribute coercion did not run with coerce => 0';
f327aa7a 44
df491f72 45lives_ok { $instance->uncoerced_attr(10) }
46 'set attribute having type with no coercion and no coerce=0';
6b46d35c 47
df491f72 48lives_ok { $instance->uncoerced_class_attr(10) }
49 'set class attribute having type with no coercion and no coerce=0';