test array delegation edge cases
[gitmo/Moose.git] / t / 070_native_traits / 203_trait_hash.t
index fe2e649..1b621b5 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 46;
+use Test::More;
 use Test::Exception;
 use Test::Moose 'does_ok';
 
@@ -19,7 +19,7 @@ use Test::Moose 'does_ok';
         handles => {
             'set_option'       => 'set',
             'get_option'       => 'get',
-            'has_no_options'   => 'empty',
+            'has_no_options'   => 'is_empty',
             'num_options'      => 'count',
             'clear_options'    => 'clear',
             'delete_option'    => 'delete',
@@ -81,6 +81,9 @@ is( $stuff->get_option('foo'), 'bar', '... got the right option' );
 is_deeply( [ $stuff->get_option(qw(foo bar)) ], [qw(bar baz)],
     "get multiple options at once" );
 
+is( scalar($stuff->get_option(qw( foo bar) )), "baz",
+       '... got last option in scalar context');
+
 lives_ok {
     $stuff->set_option( oink => "blah", xxy => "flop" );
 }
@@ -96,14 +99,9 @@ lives_ok {
 '... deleted the option okay';
 
 lives_ok {
-    $stuff->delete_option('oink');
-}
-'... deleted the option okay';
-
-lives_ok {
-    $stuff->delete_option('xxy');
+    $stuff->delete_option('oink','xxy');
 }
-'... deleted the option okay';
+'... deleted multiple option okay';
 
 is( $stuff->num_options, 1, '... we have 1 option(s)' );
 is_deeply( $stuff->options, { foo => 'bar' }, '... got more options now' );
@@ -148,7 +146,7 @@ is_deeply(
     {
         'set_option'       => 'set',
         'get_option'       => 'get',
-        'has_no_options'   => 'empty',
+        'has_no_options'   => 'is_empty',
         'num_options'      => 'count',
         'clear_options'    => 'clear',
         'delete_option'    => 'delete',
@@ -166,12 +164,12 @@ is( $options->type_constraint->type_parameter, 'Str',
     '... got the right container type' );
 
 $stuff->set_option( oink => "blah", xxy => "flop" );
-my @key_value = $stuff->key_value;
+my @key_value = sort{ $a->[0] cmp $b->[0] } $stuff->key_value;
 is_deeply(
     \@key_value,
-    [ [ 'xxy', 'flop' ], [ 'quantity', 4 ], [ 'oink', 'blah' ] ],
+    [ sort{ $a->[0] cmp $b->[0] } [ 'xxy', 'flop' ], [ 'quantity', 4 ], [ 'oink', 'blah' ] ],
     '... got the right key value pairs'
-);
+) or do{ require Data::Dumper; diag(Data::Dumper::Dumper(\@key_value)) };
 
 my %options_elements = $stuff->options_elements;
 is_deeply(
@@ -183,3 +181,5 @@ is_deeply(
     },
     '... got the right hash elements'
 );
+
+done_testing;