From: Dave Rolsky Date: Fri, 29 Oct 2010 14:42:47 +0000 (-0500) Subject: Test accessor read & write X-Git-Tag: 1.18~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2d779ce6a6a6b0e34a23f964a77d5495ab98895a;p=gitmo%2FMoose.git Test accessor read & write --- diff --git a/t/070_native_traits/050_trait_hash.t b/t/070_native_traits/050_trait_hash.t index 84fd2d3..4ff4671 100644 --- a/t/070_native_traits/050_trait_hash.t +++ b/t/070_native_traits/050_trait_hash.t @@ -47,7 +47,7 @@ use Test::Moose; $class->add_attribute( options => ( traits => \@traits, - is => 'ro', + is => 'rw', isa => 'HashRef[Str]', default => sub { {} }, handles => \%handles, @@ -166,11 +166,23 @@ sub run_tests { is( $obj->quantity, 4, 'reader part of curried accessor works' ); + is( + $obj->option_accessor('quantity'), 4, + 'accessor as reader' + ); + is_deeply( $obj->options, { quantity => 4 }, '... returns what we expect' ); + $obj->option_accessor( size => 42 ); + + is_deeply( + $obj->options, { quantity => 4, size => 42 }, + 'accessor as writer' + ); + is( exception { $class->new( options => { foo => 'BAR' } ); }, undef, '... good constructor params' ); @@ -183,6 +195,8 @@ sub run_tests { $class->new( options => { foo => [] } ); }, undef, '... bad constructor params' ); + $obj->options( {} ); + is_deeply( [ $obj->set_option( oink => "blah", xxy => "flop" ) ], [ 'blah', 'flop' ], @@ -191,13 +205,13 @@ sub run_tests { is_deeply( [ sort $obj->keys ], - [ 'oink', 'quantity', 'xxy' ], + [ 'oink', 'xxy' ], 'keys returns expected keys' ); is_deeply( [ sort $obj->values ], - [ 4, 'blah', 'flop' ], + [ 'blah', 'flop' ], 'values returns expected values' ); @@ -206,7 +220,6 @@ sub run_tests { \@key_value, [ sort { $a->[0] cmp $b->[0] }[ 'xxy', 'flop' ], - [ 'quantity', 4 ], [ 'oink', 'blah' ] ], '... got the right key value pairs' @@ -220,7 +233,6 @@ sub run_tests { is_deeply( \%options_elements, { 'oink' => 'blah', - 'quantity' => 4, 'xxy' => 'flop' }, '... got the right hash elements'