Don't rely on hash order in tests (RT#81564)
[gitmo/MooseX-AttributeHelpers.git] / t / 003_basic_hash.t
index 79ca4cd..a10b506 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 45;
+use Test::More tests => 50;
 use Test::Exception;
 
 BEGIN {
@@ -30,6 +30,8 @@ BEGIN {
             'exists'   => 'has_option',
             'defined'  => 'is_defined',
             'accessor' => 'option_accessor',
+            'kv'       => 'key_value',
+            'elements' => 'options_elements',
         },
         curries   => {
             'accessor' => {
@@ -131,6 +133,21 @@ dies_ok {
     Stuff->new(options => { foo => [] });
 } '... bad constructor params';
 
+dies_ok {
+    my $stuff = Stuff->new;
+    $stuff->option_accessor();
+} '... accessor dies on 0 args';
+
+dies_ok {
+    my $stuff = Stuff->new;
+    $stuff->option_accessor(1 => 2, 3);
+} '... accessor dies on 3 args';
+
+dies_ok {
+    my $stuff = Stuff->new;
+    $stuff->option_accessor(1 => 2, 3 => 4);
+} '... accessor dies on 4 args';
+
 ## test the meta
 
 my $options = $stuff->meta->get_attribute('options');
@@ -146,6 +163,27 @@ is_deeply($options->provides, {
     'defined'  => 'is_defined',
     'exists'   => 'has_option',
     'accessor' => 'option_accessor',
+    'kv'       => 'key_value',
+    'elements' => 'options_elements',
 }, '... got the right provides mapping');
 
 is($options->type_constraint->type_parameter, 'Str', '... got the right container type');
+
+$stuff->set_option( oink => "blah", xxy => "flop" );
+my @key_value = sort { $a->[0] cmp $b->[0] } $stuff->key_value;
+is_deeply(
+    \@key_value,
+    [ [ 'oink', 'blah' ], [ 'quantity', 4 ], [ 'xxy', 'flop' ] ],
+    '... got the right key value pairs'
+);
+
+my %options_elements = $stuff->options_elements;
+is_deeply(
+    \%options_elements,
+    {
+        'oink'     => 'blah',
+        'quantity' => 4,
+        'xxy'      => 'flop'
+    },
+    '... got the right hash elements'
+);