The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Deep::UnorderedPairs - A Test::Deep plugin for comparing an unordered list of tuples

VERSION

version 0.005

SYNOPSIS

    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',
    );

DESCRIPTION

This module provides the sub unordered_pairs (and tuples, samehash, as synonyms) to indicate the data being tested is a list of pairs that should be tested where the order of the pairs is insignificant.

This is useful when testing a function that returns a list of hash elements as an arrayref, not a hashref. One such application might be testing PSGI headers, which are passed around as an arrayref:

    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',
    );

FUNCTIONS

unordered_pairs

Pass an (even-numbered) list of items to test

tuples, samehash

tuples and samehash are aliases for unordered_pairs. I'm open to more names as well; I'm not quite yet sure what the best nomenclature should be.

(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.)

SUPPORT

Bugs may be submitted through the RT bug tracker (or bug-Test-Deep-UnorderedPairs@rt.cpan.org). I am also usually active on irc, as 'ether' at irc.perl.org.

ACKNOWLEDGEMENTS

Ricardo Signes, for maintaining Test::Deep and for being the first consumer of this module, in Router::Dumb.

SEE ALSO

AUTHOR

Karen Etheridge <ether@cpan.org>

COPYRIGHT AND LICENSE

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.