From: Shawn M Moore Date: Fri, 13 Jun 2008 01:43:48 +0000 (+0000) Subject: More tests for attributes and new X-Git-Tag: 0.04~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=069668c4fbc88fc3a347c4dbab98f031835edb75;p=gitmo%2FMouse.git More tests for attributes and new --- diff --git a/t/028-subclass-attr.t b/t/028-subclass-attr.t index 2ec4e6e..eaeb283 100644 --- a/t/028-subclass-attr.t +++ b/t/028-subclass-attr.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 3; +use Test::More tests => 11; do { package Class; @@ -31,3 +31,41 @@ is_deeply([Child->meta->compute_all_applicable_attributes], [ Class->meta->get_attribute('class'), ], "correct compute_all_applicable_attributes"); +do { + package Foo; + use Mouse; + + has attr => ( + is => 'ro', + default => 'Foo', + ); + + package Bar; + use Mouse; + extends 'Foo'; + + has attr => ( + is => 'rw', + ); +}; + +my $foo = Foo->new; +is($foo->attr, 'Foo', 'subclass does not affect parent attr'); + +my $bar = Bar->new; +is($bar->attr, undef, 'new attribute does not have the new default'); + +is(Foo->meta->get_attribute('attr')->default, 'Foo'); +is(Foo->meta->get_attribute('attr')->_is_metadata, 'ro'); + +is(Bar->meta->get_attribute('attr')->default, undef); +is(Bar->meta->get_attribute('attr')->_is_metadata, 'rw'); + +is_deeply([Foo->meta->compute_all_applicable_attributes], [ + Foo->meta->get_attribute('attr'), +], "correct compute_all_applicable_attributes"); + +is_deeply([Bar->meta->compute_all_applicable_attributes], [ + Bar->meta->get_attribute('attr'), +], "correct compute_all_applicable_attributes"); + diff --git a/t/029-new.t b/t/029-new.t index 9ad1721..d387bdf 100644 --- a/t/029-new.t +++ b/t/029-new.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Exception; do { @@ -28,3 +28,7 @@ throws_ok { Class->new('non-hashref scalar'); } qr/Single parameters to new\(\) must be a HASH ref/; +lives_ok { + Class->new(undef); +} "Class->new(undef) specifically doesn't throw an error. weird" +