Test::Proto::Role::HashRef - Role containing test case methods for hash refs.
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.
key_exists
pHash->key_exists('a')->ok({a=>1, b=>2});
Returns true if the key exists (even if the value is undefined).
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.
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.
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!
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'].
ok
$tests_keys
['a','b']
['b','a']
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].
$tests_values
[1,2]
[2,1]
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']].
$tests_key_value_pairs
[['a','1'],['b','2']]
[['b','2'],['a','1']]
For author, version, bug reports, support, etc, please see Test::Proto.
To install Test::Proto, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Proto
CPAN shell
perl -MCPAN -e shell install Test::Proto
For more information on module installation, please visit the detailed CPAN module installation guide.