From: Dave Rolsky Date: Thu, 26 Feb 2009 16:06:08 +0000 (+0000) Subject: splice was totally broken, add tests and fix it X-Git-Tag: 0.16~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=af1ade485f435bd067838c710548f949b6f77835;p=gitmo%2FMooseX-AttributeHelpers.git splice was totally broken, add tests and fix it --- diff --git a/lib/MooseX/AttributeHelpers/MethodProvider/Array.pm b/lib/MooseX/AttributeHelpers/MethodProvider/Array.pm index 4589a69..a45a963 100644 --- a/lib/MooseX/AttributeHelpers/MethodProvider/Array.pm +++ b/lib/MooseX/AttributeHelpers/MethodProvider/Array.pm @@ -125,13 +125,13 @@ sub splice : method { my ( $self, $i, $j, @elems ) = @_; ($container_type_constraint->check($_)) || confess "Value " . (defined($_) ? $_ : 'undef') . " did not pass container type constraint" for @elems; - CORE::splice @{$self->$reader()}, $i, $j, @elems; + CORE::splice @{$reader->($self)}, $i, $j, @elems; }; } else { return sub { my ( $self, $i, $j, @elems ) = @_; - CORE::splice @{$self->$reader()}, $i, $j, @elems; + CORE::splice @{$reader->($self)}, $i, $j, @elems; }; } } diff --git a/t/002_basic_array.t b/t/002_basic_array.t index c7887ee..9ac81f2 100644 --- a/t/002_basic_array.t +++ b/t/002_basic_array.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 62; +use Test::More tests => 64; use Test::Exception; BEGIN { @@ -29,6 +29,7 @@ BEGIN { 'count' => 'num_options', 'empty' => 'has_options', 'clear' => 'clear_options', + 'splice' => 'splice_options', 'sort_in_place' => 'sort_options_in_place', }, curries => { @@ -152,12 +153,26 @@ lives_ok { $stuff->add_options_with_speed('compatible', 'safe'); } '... add options with speed okay'; -is_deeply($stuff->options, [qw/tree funrolls funbuns compatible safe/]); +is_deeply($stuff->options, [qw/tree funrolls funbuns compatible safe/], + 'check options after add_options_with_speed'); lives_ok { $stuff->prepend_prerequisites_along_with(); } '... add prerequisite options okay'; +$stuff->clear_options; +$stuff->add_options( 1, 2 ); + +lives_ok { + $stuff->splice_options( 1, 0, 'foo' ); +} '... splice_options works'; + +is_deeply( + $stuff->options, [ 1, 'foo', 2 ], + 'splice added expected option' +); + + ## check some errors #dies_ok { @@ -207,6 +222,7 @@ is_deeply($options->provides, { 'count' => 'num_options', 'empty' => 'has_options', 'clear' => 'clear_options', + 'splice' => 'splice_options', 'sort_in_place' => 'sort_options_in_place', }, '... got the right provides mapping');