first release
[gitmo/MooseX-AlwaysCoerce.git] / t / 01-basic.t
diff --git a/t/01-basic.t b/t/01-basic.t
new file mode 100644 (file)
index 0000000..f056dd9
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+{
+    package MyClass;
+    use Moose;
+    use MooseX::ClassAttribute;
+    use MooseX::AlwaysCoerce;
+    use Moose::Util::TypeConstraints;
+
+    subtype 'MyType', as 'Int';
+    coerce 'MyType', from 'Str', via { length $_ };
+
+    has foo => (is => 'rw', isa => 'MyType');
+
+    class_has bar => (is => 'rw', isa => 'MyType');
+}
+
+ok( (my $instance = MyClass->new), 'instance' );
+
+eval { $instance->foo('bar') };
+ok( (!$@), 'attribute coercion ran' );
+
+eval { $instance->bar('baz') };
+ok( (!$@), 'class attribute coercion ran' );