c2ddfafdadea2c8ed29a432bda22f56e3f5b3182
[gitmo/Moose.git] / t / 071_misc_attribute_tests.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 10;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Moose');           
11 }
12
13 {
14     {
15         package Test::TheDefaultFor::ArrayRef::and::HashRef;
16         use Moose;
17     
18         has 'array_ref' => (is => 'rw', isa => 'ArrayRef');
19         has 'hash_ref'  => (is => 'rw', isa => 'HashRef');    
20
21     }
22
23     my $test = Test::TheDefaultFor::ArrayRef::and::HashRef->new;
24     isa_ok($test, 'Test::TheDefaultFor::ArrayRef::and::HashRef');
25
26     is_deeply($test->array_ref, [], '.... got the right default value');
27     is_deeply($test->hash_ref,  {}, '.... got the right default value');
28
29     my $test2 = Test::TheDefaultFor::ArrayRef::and::HashRef->new(
30         array_ref => [ 1, 2, [] ],
31         hash_ref  => { one => 1, two => 2, three => {} },
32     );
33     isa_ok($test2, 'Test::TheDefaultFor::ArrayRef::and::HashRef');
34
35     is_deeply($test2->array_ref, [ 1, 2, [] ], '.... got the right default value');
36     is_deeply($test2->hash_ref,  { one => 1, two => 2, three => {} }, '.... got the right default value');
37 }
38
39 {
40     {
41         package Test::For::Lazy::TypeConstraint;
42         use Moose;
43         use Moose::Util::TypeConstraints;
44
45         has 'bad_lazy_attr' => (
46             is => 'rw',
47             isa => 'ArrayRef',
48             lazy => 1, 
49             default => sub { "test" },
50         );
51         
52         has 'good_lazy_attr' => (
53             is => 'rw',
54             isa => 'ArrayRef',
55             lazy => 1, 
56             default => sub { [] },
57         );        
58
59     }
60
61     my $test = Test::For::Lazy::TypeConstraint->new;
62     isa_ok($test, 'Test::For::Lazy::TypeConstraint');
63     
64     dies_ok {
65         $test->bad_lazy_attr;
66     } '... this does not work';
67     
68     lives_ok {
69         $test->good_lazy_attr;
70     } '... this does not work';    
71 }