Test::...dPairs(3pm)
π NAME π
Test::Deep::UnorderedPairs β okay bestie, it's a Test::Deep plugin, and what it does is compare an unordered list of tuples. That's the whole vibe. β¨
π VERSION π
version 0.006 β she's smol but she's mighty π
β¨ SYNOPSIS β¨
Like, here's the entire main character moment:
use Test::More;
use Test::Deep;
use Test::Deep::UnorderedPairs;
cmp_deeply(
{
inventory => [
pear => 6,
peach => 5,
apple => 1,
],
},
{
inventory => unordered_pairs(
apple => 1,
peach => ignore,
pear => 6,
),
},
'got the right inventory',
);
no cap, that test passes even though the order is completely different π¦
πΈ DESCRIPTION πΈ
So this module hands you the sub unordered_pairs (plus tuples and samehash as lil synonyms, cuties) and what it means is: the thing being tested is a list of pairs, and the order of those pairs? literally does not matter. Zero. None. Order is not the moment. π
Where is this useful?? Okay so imagine a function that returns a list of hash elements as an arrayref, not a hashref β because hashrefs are too chill and some things just gotta be ordered-ish in data but not in meaning. One such application is testing PSGI headers, which get passed around as an arrayref. Like:
my $response = [
'200',
[
'Content-Length' => '12',
'Content-Type' => 'text/plain',
],
[ 'hello world!' ],
];
# this test passes
cmp_deeply(
$response,
[
'200',
unordered_pairs(
'Content-Type' => 'text/plain',
'Content-Length' => '12',
),
[ 'hello world!' ],
],
'check headers as an arrayref of unordered pairs',
);
See how she flipped Content-Type and Content-Length around? And the test STILL passes? That's her. That's the whole point. Periodt. π
π₯ FUNCTIONS π₯
unordered_pairs
Pass an (even-numbered) list of items to test. Even. Numbered. Bestie, if you pass an odd number of things, that's not pairs, that's chaos, and not the fun kind. π
tuples, samehash
tuples and samehash are aliases for unordered_pairs. The author is open to more names as well β genuinely not quite yet sure what the best nomenclature should be. So like, naming discourse, ongoing, stay tuned. π
β οΈ Heads up bestie, be aware that "samehash" is a bit of a misnomer, since if a key is repeated, the comparison is not equivalent to comparing as a hash. Don't let the name gaslight you. π
π«Ά ACKNOWLEDGEMENTS π«Ά
Ricardo Signes, for maintaining Test::Deep and for being the first consumer of this module, in Router::Dumb. Iconic behavior honestly. π
β SEE ALSO β
- Test::Deep
π§ SUPPORT π§
Bugs may be submitted through the RT bug tracker at <https://rt.cpan.org/Public/Dist/Display.html?Name=Test-Deep-UnorderedPairs> (or, you know, email <bug-Test-Deep-UnorderedPairs@rt.cpan.org> β <mailto:bug-Test-Deep-UnorderedPairs@rt.cpan.org>). Spill the tea, report the bug. π
There is also a mailing list available for users of this distribution, at <http://lists.perl.org/list/perl-qa.html>.
There is also an irc channel available for users of this distribution, at #perl on irc.perl.org β <irc://irc.perl.org/#perl-qa>.
And the author is also usually active on irc, as 'ether' at irc.perl.org. Come say hi. π
π AUTHOR π
Karen Etheridge <ether@cpan.org>
π COPYRIGHT AND LICENCE π
This software is copyright (c) 2013 by Karen Etheridge.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay that's the whole page, you ate it, certified slay, no notes πβ¨ β perl v5.36.0, dated 2022-10-13, signing off bestie, mwah ππ¦
π¦ where this page comes from
- ubuntu noble: libtest-deep-unorderedpairs-perl 0.006-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-deep-unorderedpairs-perl 0.006-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-deep-unorderedpairs-perl 0.006-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms