Karen Etheridge > Test-Deep-UnorderedPairs-0.003 > Test::Deep::UnorderedPairs

Download:
Test-Deep-UnorderedPairs-0.003.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.003   Source  

NAME ^

Test::Deep::UnorderedPairs - A Test::Deep plugin for comparing lists as if they were hashes

VERSION ^

version 0.003

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/METHODS ^

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 ^

Test::Deep

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.

syntax highlighting: