do nothing at construction time for attributes with undef init_arg - fixes undefined...
[gitmo/MooseX-UndefTolerant.git] / t / undef_init_arg.t
diff --git a/t/undef_init_arg.t b/t/undef_init_arg.t
new file mode 100644 (file)
index 0000000..7b3c579
--- /dev/null
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+use Test::More tests => 7;
+use Test::Fatal;
+use Test::Moose;
+use Test::NoWarnings 0.94 ':early';
+
+{
+package Foo;
+use Moose;
+use MooseX::UndefTolerant;
+
+has 'bar' => (
+    is => 'ro',
+    isa => 'Num',
+    init_arg => undef,
+);
+}
+
+package main;
+
+with_immutable
+{
+    is(exception { my $foo = Foo->new }, undef, 'constructed with no args');
+
+    is(exception { my $foo = Foo->new(bar => undef) }, undef, 'constructed with undef value');
+
+    is(exception { my $foo = Foo->new(bar => 1234) }, undef, 'constructed with defined value');
+} 'Foo';
+