Subject: | Preliminary thoughts re new new feature: comparison function for comparing an arrayref with ordering as if it were a hashref |
I'm opening this ticket so I don't forget this thought.. need to discuss
with rjbs later, and I don't have the time currently to code this up in
a pull request.
new comparison function for testing the contents of an arrayref, as if
it were a hashref (that is, the ordering of *pairs* of elements is
insignificant). This would be useful for testing the 2nd element of a
PSGI response (which contains header information, as an arrayref).
This works as-is, but can made nicer by folding into its own testing
function within Test::Deep:
use Test::Deep 'cmp_details';
sub _hash_as_arrayref(@)
{
my %expected_hash = @_;
return (
all(
supersetof(), # first check we have an arrayref.
code(sub { # now compare contents as a hash
my $got = shift;
return cmp_details({@$got}, \%expected_hash);
},
),
),
);
}
my @result = (
404,
[
'Cache-Control' => 'no-cache',
'Content-Type' => 'text/plain',
],
[ 'foo' ],
);
cmp_deeply(
\@result,
[
404,
_hash_as_arrayref(
'Cache-Control' => 'no-cache',
'Content-Type' => 'text/plain',
),
[ 'foo' ],
],
);