X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F002_basic_array.t;h=a3362764dbf5ecc492dbee41e45a9e93be5ddc7e;hb=e0d340ca0cd12125cabbd39e9799e4fc77c2a703;hp=c7887eedd147798141a1d48d168b77d1860817cf;hpb=71703b283612e6feaa6f61835a2f99e2bc4ff1ca;p=gitmo%2FMooseX-AttributeHelpers.git diff --git a/t/002_basic_array.t b/t/002_basic_array.t index c7887ee..a336276 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 => 69; use Test::Exception; BEGIN { @@ -29,7 +29,9 @@ BEGIN { 'count' => 'num_options', 'empty' => 'has_options', 'clear' => 'clear_options', + 'splice' => 'splice_options', 'sort_in_place' => 'sort_options_in_place', + 'accessor' => 'option_accessor', }, curries => { 'push' => { @@ -58,6 +60,7 @@ can_ok($stuff, $_) for qw[ clear_options has_options sort_options_in_place + option_accessor ]; is_deeply($stuff->options, [10, 12], '... got options'); @@ -152,12 +155,28 @@ 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' +); + +is($stuff->option_accessor(1 => 'foo++'), 'foo++'); +is($stuff->option_accessor(1), 'foo++'); + ## check some errors #dies_ok { @@ -192,6 +211,16 @@ dies_ok { $stuff->sort_in_place_options( undef ); } '... sort rejects arg of invalid type'; +dies_ok { + my $stuff = Stuff->new(); + $stuff->option_accessor(); +} '... accessor rejects 0 args'; + +dies_ok { + my $stuff = Stuff->new(); + $stuff->option_accessor(1, 2, 3); +} '... accessor rejects 3 args'; + ## test the meta my $options = $stuff->meta->get_attribute('options'); @@ -207,7 +236,9 @@ is_deeply($options->provides, { 'count' => 'num_options', 'empty' => 'has_options', 'clear' => 'clear_options', + 'splice' => 'splice_options', 'sort_in_place' => 'sort_options_in_place', + 'accessor' => 'option_accessor', }, '... got the right provides mapping'); is($options->type_constraint->type_parameter, 'Str', '... got the right container type');