File: mesh.t

package info (click to toggle)
liblist-moreutils-perl 0.430-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,228 kB
  • sloc: perl: 13,167; makefile: 17
file content (79 lines) | stat: -rw-r--r-- 1,740 bytes parent folder | download
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
#!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");

BEGIN
{
    $INC{'List/MoreUtils.pm'} or *zip = __PACKAGE__->can("mesh");
}

use Test::More;
use Test::LMU;

SCOPE:
{
    my @x = qw/a b c d/;
    my @y = qw/1 2 3 4/;
    my @z = mesh @x, @y;
    is_deeply(\@z, ['a', 1, 'b', 2, 'c', 3, 'd', 4], "mesh two list with same count of elements");
}

SCOPE:
{
    # alias check
    my @x = qw/a b c d/;
    my @y = qw/1 2 3 4/;
    my @z = zip @x, @y;
    is_deeply(\@z, ['a', 1, 'b', 2, 'c', 3, 'd', 4], "zip two list with same count of elements");
}

SCOPE:
{
    my @a = ('x');
    my @b = ('1', '2');
    my @c = qw/zip zap zot/;
    my @z = mesh @a, @b, @c;
    is_deeply(\@z, ['x', 1, 'zip', undef, 2, 'zap', undef, undef, 'zot'], "mesh three list with increasing count of elements");
}

SCOPE:
{
    # alias check
    my @a = ('x');
    my @b = ('1', '2');
    my @c = qw/zip zap zot/;
    my @z = zip @a, @b, @c;
    is_deeply(\@z, ['x', 1, 'zip', undef, 2, 'zap', undef, undef, 'zot'], "zip three list with increasing count of elements");
}

# Make array with holes
SCOPE:
{
    my @a = (1 .. 10);
    my @d;
    $#d = 9;
    my @z = mesh @a, @d;
    is_deeply(
        \@z,
        [1, undef, 2, undef, 3, undef, 4, undef, 5, undef, 6, undef, 7, undef, 8, undef, 9, undef, 10, undef,],
        "mesh one list with 9 elements with an empty list"
    );
}

leak_free_ok(
    mesh => sub {
        my @x = qw/a b c d e/;
        my @y = qw/1 2 3 4/;
        my @z = mesh @x, @y;
    }
);
is_dying('mesh with a list, not at least two arrays' => sub { &mesh(1, 2); });

done_testing;