Test::Data::Hash(3pm)

πŸ“¦
version 1.248 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– Test::Data::Hash πŸ’–

okay bestie, so this is Test::Data::Hash, a lil corner of the User Contributed Perl Documentation universe, and it's literally just a whole collection of test functions for hash variables. yes. hashes. the curly-brace ones. she's giving very specific, very useful, and honestly? obsessed.


✨ SYNOPSIS ✨

use Test::Data qw(Hash);

that's it. that's the whole vibe check. πŸ’…


🌸 DESCRIPTION 🌸

so this module is a collection of test utilities for hash variables β€” like, every lil check you'd wanna run on a hash, but as a proper test function instead of you squinting at exists and defined at 2am wondering which one does what.

🚨 important, bestie: you load this module through Test::Data. not by itself. that's the doorway. don't try to climb in through the window.

πŸŽ€ Functions πŸŽ€

every single one of these takes KEY, HASH [, NAME] β€” the NAME part is optional, she's flexible like that β€” and every single one has the same iconic rule: the function does not create KEY in HASH. it's a reader, not a maker. no side effects, no surprise keys materialising out of nowhere. periodt.


  • exists_ok( KEY, HASH [, NAME] ) β€” slays if the value for KEY in HASH exists. and again, for the people in the back: the function does not create KEY in HASH. it just peeks. 🫣
  • not_exists_ok( KEY, HASH [, NAME] ) β€” the flip side, the mirror, the opposite-energy queen. ok if the value for KEY in HASH does not exist. and nope, still doesn't create KEY in HASH. πŸ’€
  • hash_value_defined_ok( KEY, HASH [, NAME] ) β€” ok if the value for KEY in HASH is defined. undef can't sit with us. and β€” you guessed it β€” the function does not create KEY in HASH. ✨
  • hash_value_undef_ok( KEY, HASH [, NAME] ) β€” ok if the value for KEY in HASH is undefined. sometimes undef is the moment. and the function does not create KEY in HASH, so no accidental glow-up of your data. πŸŒ™
  • hash_value_true_ok( KEY, HASH [, NAME] ) β€” ok if the value for KEY in HASH is true. truthy. thriving. and the function does not create KEY in HASH. no cap. πŸ‘‘
  • hash_value_false_ok( KEY, HASH [, NAME] ) β€” ok if the value for KEY in HASH is false. falsy and fully at peace with it. and the function does not create KEY in HASH. iconic behaviour honestly. 🌈

πŸ‘€ SEE ALSO πŸ‘€

the whole friend group, go say hi:

  • Test::Data
  • Test::Data::Array
  • Test::Data::Function
  • Test::Data::Scalar
  • Test::Builder

πŸ¦‹ SOURCE AVAILABILITY πŸ¦‹

the source lives on Github, bestie, go star it:

https://github.com/briandfoy/test-data

πŸ’œ AUTHOR πŸ’œ

brian d foy, "<briandfoy@pobox.com>" β€” the author, the icon, the legend.


Copyright Β© 2002-2025, brian d foy <briandfoy@pobox.com>. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.


okay that's the whole page, no notes. this was documented with perl v5.40.1 on 2025-04-17, and honestly? she ate. stay hydrated, go write some tests, mwah πŸ©·πŸŽ€πŸ§š

πŸ“¦ where this page comes from