Test-Deep - Re: Defining optional hash keys

Posted on Sat Mar 8 16:42:20 2008 by fergal in response to 7275 (See the whole thread of 4)
Re: Defining optional hash keys

Hmmm, while I think it's definitely a useful feature, if I was actually going to add it to Test::Deep, I think I would do it differently. Something like your original suggestion:

$expect { key => "value", opt_key("key2") => "value2", };

And modify the Test::Deep::Hash to recognise this. I don't really have time right now but if you're interested, I would do something like:

sub opt_key { my $key = shift; return Test::Deep::OptionalKey->new($key); }

and modify the code in descend() in Test::Deep::HashKeysOnly to detect Test::Deep::OptionalKey objects and not add them to @missing then modify Test::Deep::HashElements to handle OptionalKey correctly too.

It's not a terribly big job, I just don't have time to do it and write the tests and the docs.

Write a response