The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Proto::HashRef - Test Prototype for Hash References.

SYNOPSIS

        Test::Proto::HashRef->new->ok({a=>undef,b=>2,c=>'three'}); # ok
        Test::Proto::HashRef->new->ok({}); # ok
        Test::Proto::HashRef->new->is_empty->ok({}); # still ok
        Test::Proto::HashRef->new->is_deeply({a=>undef,'c'=>"three", b=>2,})->ok({a=>undef,b=>2,c=>'three'}); # also ok

This is a test prototype which requires that the value it is given is defined and is a hashref. It provides methods for interacting with hashrefs. (To test hashes, make them hashrefs and test them with this module)

METHODS

See Test::Proto::Base for documentation on common methods.

keys

        pHr->keys(['a'])->ok({a=>1}, 'Keys of {a=>1} returns ['a']');

Gets the keys of the hash, and validates them as an arrayref. Note that the keys are not likely to be sorted in nay particular order.

values

        pHr->values([1])->ok({a=>1}, 'Keys of {a=>1} returns [1]');

Gets the values of the hash, and validates them as an arrayref. Note that the values are not likely to be sorted in nay particular order.

key_value

        pHr->key_value('a', pSt->is_eq('b'))->ok({a=>'b',c=>4});

Gets the value of a particular hash key, and validates it, upgrading the expected value as necessary.

key_values

        pHr->key_value({'a' => pSt->is_eq('b'), c=>4})->ok({a=>'b',c=>4, e=>'VI'});

Gets the value of several hash keys, and validates them against the value, upgrading the expected value as necessary. Extra hash keys are ignored.

allow_only

        pHr->key_value({'a' => pSt->is_eq('b'), c=>4, g=>'eight'})->ok({a=>'b',c=>4, e=>'VI'});

Like key_values but all values in the prototype hash are optional, i.e. 'if present, they must be this'.

only_key_values

        pHr->key_value({'a' => pSt->is_eq('b'), c=>4})->ok({a=>'b',c=>4});

Like key_values but no keys are permitted except those specified. This is effectively a deep equality check for the hash, except the key values can be prototypes rather than values.

is_empty

        pHr->is_empty->ok({});

Fails if the hash is not empty, otherwise succeeds.

OTHER INFORMATION

For author, version, bug reports, support, etc, please see Test::Proto.