BUILDALL for generated constructor
[gitmo/Moo.git] / t / method-generate-constructor.t
CommitLineData
6f68f022 1use strictures 1;
2use Test::More;
3use Test::Fatal;
4
5use Method::Generate::Constructor;
6
7my $gen = Method::Generate::Constructor->new;
8
9$gen->generate_method('Foo', 'new', {
10 one => { },
11 two => { init_arg => undef },
12 three => { init_arg => 'THREE' }
13});
14
15my $first = Foo->new({
16 one => 1,
17 two => 2,
18 three => -75,
19 THREE => 3,
20 four => 4,
21});
22
23is_deeply(
24 { %$first }, { one => 1, three => 3 },
25 'init_arg handling ok'
26);
27
28$gen->generate_method('Bar', 'new' => {
29 one => { required => 1 },
30 three => { init_arg => 'THREE', required => 1 }
31});
32
33like(
34 exception { Bar->new },
35 qr/Missing required arguments: THREE, one/,
36 'two missing args reported correctly'
37);
38
39like(
40 exception { Bar->new(THREE => 3) },
41 qr/Missing required arguments: one/,
42 'one missing arg reported correctly'
43);
44
45is(
46 exception { Bar->new(one => 1, THREE => 3) },
47 undef,
48 'pass with both required args'
49);
50
51done_testing;