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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#!perl
use strict ("subs", "vars", "refs");
use warnings ("all");
BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; }
END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS
use lib ("t/lib");
use List::MoreUtils (":all");
use Test::More;
use Test::LMU;
use Tie::Array ();
SCOPE:
{
my @a = qw(one two three four five six seven eight nine ten eleven twelve thirteen);
my @b = qw(two three five seven eleven thirteen seventeen);
my @c = qw(one one two three five eight thirteen twentyone);
my %expected = (
one => [0, 2],
two => [0, 1, 2],
three => [0, 1, 2],
four => [0],
five => [0, 1, 2],
six => [0],
seven => [0, 1],
eight => [0, 2],
nine => [0],
ten => [0],
eleven => [0, 1],
twelve => [0],
thirteen => [0, 1, 2],
seventeen => [1],
twentyone => [2],
);
my %cmped = listcmp @a, @b, @c;
is_deeply(\%cmped, \%expected, "Sequence vs. Prime vs. Fibonacci sorted out correctly");
}
SCOPE:
{
my @a = ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen");
my @b = (undef, "two", "three", undef, "five", undef, "seven", undef, undef, undef, "eleven", undef, "thirteen");
my %expected = (
one => [0],
two => [0, 1],
three => [0, 1],
four => [0],
five => [0, 1],
six => [0],
seven => [0, 1],
eight => [0],
nine => [0],
ten => [0],
eleven => [0, 1],
twelve => [0],
thirteen => [0, 1],
);
my %cmped = listcmp @a, @b;
is_deeply(\%cmped, \%expected, "Sequence vs. Prime filled with undef sorted out correctly");
}
leak_free_ok(
listcmp => sub {
my @a = ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen");
my @b = (undef, "two", "three", undef, "five", undef, "seven", undef, undef, undef, "eleven", undef, "thirteen");
my %expected = (
one => [0],
two => [0, 1],
three => [0, 1],
four => [0],
five => [0, 1],
six => [0],
seven => [0, 1],
eight => [0],
nine => [0],
ten => [0],
eleven => [0, 1],
twelve => [0],
thirteen => [0, 1],
);
my %cmped = listcmp @a, @b;
}
);
# This test (and the associated fix) are from Kevin Ryde; see RT#49796
leak_free_ok(
'listcmp with exception in overloading stringify at begin' => sub {
eval {
my @a = ("one", "two", "three");
my @b = (DieOnStringify->new, "two", "three");
my %expected = (
one => [0],
two => [0, 1],
three => [0, 1],
);
my %cmped = listcmp @a, @b;
};
},
'listcmp with exception in overloading stringify at end' => sub {
eval {
my @a = ("one", "two", "three");
my @b = ("two", "three", DieOnStringify->new);
my %expected = (
one => [0],
two => [0, 1],
three => [0, 1],
);
my %cmped = listcmp @a, @b;
};
}
);
done_testing;
|