constructor generation, add option to quote_sub to name without installing
[gitmo/Moo.git] / t / method-generate-constructor.t
diff --git a/t/method-generate-constructor.t b/t/method-generate-constructor.t
new file mode 100644 (file)
index 0000000..96d604c
--- /dev/null
@@ -0,0 +1,51 @@
+use strictures 1;
+use Test::More;
+use Test::Fatal;
+
+use Method::Generate::Constructor;
+
+my $gen = Method::Generate::Constructor->new;
+
+$gen->generate_method('Foo', 'new', {
+  one => { },
+  two => { init_arg => undef },
+  three => { init_arg => 'THREE' }
+});
+
+my $first = Foo->new({
+  one => 1,
+  two => 2,
+  three => -75,
+  THREE => 3,
+  four => 4,
+});
+
+is_deeply(
+  { %$first }, { one => 1, three => 3 },
+  'init_arg handling ok'
+);
+
+$gen->generate_method('Bar', 'new' => {
+  one => { required => 1 },
+  three => { init_arg => 'THREE', required => 1 }
+});
+
+like(
+  exception { Bar->new },
+  qr/Missing required arguments: THREE, one/,
+  'two missing args reported correctly'
+);
+
+like(
+  exception { Bar->new(THREE => 3) },
+  qr/Missing required arguments: one/,
+  'one missing arg reported correctly'
+);
+
+is(
+  exception { Bar->new(one => 1, THREE => 3) },
+  undef,
+  'pass with both required args'
+);
+
+done_testing;