File: 02-repeated-keys.t

package info (click to toggle)
libtest-deep-unorderedpairs-perl 0.006-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 288 kB
  • sloc: perl: 351; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,301 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use strict;
use warnings;

use Test::More 0.88;
use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
use Test::Deep::UnorderedPairs;

use lib 't/lib';
use Util;

my @tests = (
    'repeated key, missing a key' => {
        got => [ foo => 1, foo => 2 ],
        exp => tuples(foo => 2, bar => 1),
        ok => 0,
        diag => "Comparing keys of \$data\nMissing: 'bar'\nExtra: 'foo'\n",
    },
    'repeated key, extra key' => {
        got => [ foo => 1, bar => 2 ],
        exp => tuples(bar => 2, bar => 1),
        ok => 0,
        diag => "Comparing keys of \$data\nMissing: 'bar'\nExtra: 'foo'\n",
    },

    'repeated key, keys ok, value wrong' => {
        got => [ foo => 1, foo => 3, bar => 3 ],
        exp => tuples(bar => 3, foo => 1, foo => 2),
        ok => 0,
        diag => qr/^Compared \$data->\[3\]\n\s+got : '3'\nexpect : '2'\n$/,
    },
    'repeated key ok' => {
        got => [ foo => 1, foo => 2, bar => 3 ],
        exp => tuples(bar => 3, foo => 1, foo => 2),
        ok => 1,
    },
);

while (my ($test_name, $test) = (shift(@tests), shift(@tests)))
{
    last if not $test_name;

    subtest $test_name => test_plugin(@{$test}{qw(got exp ok diag)});

    # for author testing only
    BAIL_OUT('oops') if -e '.git' and not Test::Builder->new->is_passing;
}

done_testing;