init_arg can be undef
[gitmo/Moose.git] / t / 300_immutable / 004_inlined_constructors_n_types.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 4;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Moose');
11 }
12
13 =pod
14
15 This tests to make sure that the inlined constructor
16 has all the type constraints in order, even in the 
17 cases when there is no type constraint available, such 
18 as with a Class::MOP::Attribute object.
19
20 =cut
21
22 {
23     package Foo;
24     use Moose;
25
26     has 'foo' => (is => 'rw', isa => 'Int');    
27     has 'baz' => (is => 'rw', isa => 'Int');
28     has 'zot' => (is => 'rw', isa => 'Int', init_arg => undef);
29     
30     Foo->meta->add_attribute(
31         Class::MOP::Attribute->new(
32             'bar' => (
33                 accessor => 'bar',
34             )
35         )
36     );
37     
38     Foo->meta->make_immutable(debug => 0);
39 }
40
41 lives_ok {
42     Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => 4);
43 } '... this passes the constuctor correctly';
44
45 lives_ok {
46     Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => "not an int");
47 } "... the constructor doesn't care about 'zot'";
48
49 dies_ok {
50     Foo->new(foo => "Hello World", bar => 100, baz => "Hello World");
51 } '... this fails the constuctor correctly';
52
53
54
55