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

NAME

Test::Proto::Role::HashRef - Role containing test case methods for hash refs.

SYNOPSIS

        package MyProtoClass;
        use Moo;
        with 'Test::Proto::Role::HashRef';

This Moo Role provides methods to Test::Proto::HashRef for test case methods that apply to hashrefs such as key_exists. It can also be used for objects which use overload or otherwise respond to hashref syntax.

METHODS

key_exists

        pHash->key_exists('a')->ok({a=>1, b=>2});

Returns true if the key exists (even if the value is undefined).

key_has_value

        pHash->key_has_value('a',1)->ok({a=>1, b=>2});
        pHash->key_has_value('b',p->num_gt(0))->ok({a=>1, b=>2});

Returns the value of corresponding to the key provided within the subject, and tests it against the prototype provided in the argument.

superhash_of

        pHash->superhash_of({'a'=>1})->ok({a=>1, b=>2});
        pHash->superhash_of({'b'=>p->num_gt(0)})->ok({a=>1, b=>2});

Tests whether each of the key-value pairs in the second argument are present and validate the test subject's equivalent pair.

count_keys

        pHash->count_keys(2)->ok({a=>1, b=>2});
        pHash->count_keys(p->num_gt(0))->ok({a=>1, b=>2});

Counts the keys of the hashref and compares them to the prototype provided. There is no equivalent count_values - the number should be identical!

keys

        pHash->keys($tests_keys)->ok({a=>1, b=>2});

Returns the hash keys of the subject as an array reference (in an undetermined order), and tests them against the prototype provided in the argument.

In the above example, the ok passes if the prototype $tests_keys returns a pass for ['a','b'] or ['b','a'].

values

        pHash->values($tests_values)->ok({a=>1, b=>2});

Produces the hash values of the subject as an array reference (in an undetermined order), and tests them against the prototype provided in the argument.

In the above example, the ok passes if the prototype $tests_values returns a pass for [1,2] or [2,1].

enumerated

        pHash->enumerated($tests_key_value_pairs)->ok({a=>1, b=>2});

Produces the hash keys and values of the subject as an array reference (in an undetermined order), and tests them against the prototype provided in the argument.

In the above example, the prototype $tests_key_value_pairs should return a pass for [['a','1'],['b','2']] or [['b','2'],['a','1']].

OTHER INFORMATION

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