X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F007-attributes.t;h=4edd2d0f156c5e7631f26a6338a1f23e672617de;hb=bf8e5b90e442d6ec7dbb837a051f547d685ee2e9;hp=cf2b5a7365102b45a98529093f59e8889a4e40ca;hpb=c3398f5bd45f2851b7cd40ca9823bcf7d2378469;p=gitmo%2FMouse.git diff --git a/t/007-attributes.t b/t/007-attributes.t index cf2b5a7..4edd2d0 100644 --- a/t/007-attributes.t +++ b/t/007-attributes.t @@ -1,13 +1,16 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 10; +use Test::More tests => 15; +use Test::Exception; do { package Class; use Mouse; - has 'x'; + has 'x' => ( + is => 'bare', + ); has 'y' => ( is => 'ro', @@ -16,6 +19,12 @@ do { has 'z' => ( is => 'rw', ); + + has 'attr' => ( + accessor => 'rw_attr', + reader => 'read_attr', + writer => 'write_attr', + ); }; ok(!Class->can('x'), "No accessor is injected if 'is' has no value"); @@ -27,10 +36,22 @@ ok(!$object->can('x'), "No accessor is injected if 'is' has no value"); can_ok($object, 'y', 'z'); is($object->y, undef); -is($object->y(10), undef); + +throws_ok { + $object->y(10); +} qr/Cannot assign a value to a read-only accessor/; + is($object->y, undef); is($object->z, undef); is($object->z(10), 10); is($object->z, 10); +can_ok($object, qw(rw_attr read_attr write_attr)); +$object->write_attr(42); +is $object->rw_attr, 42; +is $object->read_attr, 42; +$object->rw_attr(100); +is $object->rw_attr, 100; +is $object->read_attr, 100; +