Test::...dPairs(3pm)

πŸ“¦
version 0.006 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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>


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