xref: /openbsd-src/gnu/usr.bin/perl/cpan/Scalar-List-Utils/t/mesh.t (revision 256a93a44f36679bee503f12e49566c2183f6181)
1*256a93a4Safresh1#!./perl
2*256a93a4Safresh1
3*256a93a4Safresh1use strict;
4*256a93a4Safresh1use warnings;
5*256a93a4Safresh1
6*256a93a4Safresh1use Test::More tests => 7;
7*256a93a4Safresh1use List::Util qw(mesh mesh_longest mesh_shortest);
8*256a93a4Safresh1
9*256a93a4Safresh1is_deeply( [mesh ()], [],
10*256a93a4Safresh1  'mesh empty returns empty');
11*256a93a4Safresh1
12*256a93a4Safresh1is_deeply( [mesh ['a'..'c']], [ 'a', 'b', 'c' ],
13*256a93a4Safresh1  'mesh of one list returns the list' );
14*256a93a4Safresh1
15*256a93a4Safresh1is_deeply( [mesh ['one', 'two'], [1, 2]], [ one => 1, two => 2 ],
16*256a93a4Safresh1  'mesh of two lists returns a list of two pairs' );
17*256a93a4Safresh1
18*256a93a4Safresh1# Unequal length arrays
19*256a93a4Safresh1
20*256a93a4Safresh1is_deeply( [mesh_longest ['x', 'y', 'z'], ['X', 'Y']], [ 'x', 'X', 'y', 'Y', 'z', undef ],
21*256a93a4Safresh1  'mesh_longest extends short lists with undef' );
22*256a93a4Safresh1
23*256a93a4Safresh1is_deeply( [mesh_shortest ['x', 'y', 'z'], ['X', 'Y']], [ 'x', 'X', 'y', 'Y' ],
24*256a93a4Safresh1  'mesh_shortest stops after shortest list' );
25*256a93a4Safresh1
26*256a93a4Safresh1# Non arrayref arguments throw exception
27*256a93a4Safresh1ok( !defined eval { mesh 1, 2, 3 },
28*256a93a4Safresh1  'non-reference argument throws exception' );
29*256a93a4Safresh1
30*256a93a4Safresh1ok( !defined eval { mesh +{ one => 1 } },
31*256a93a4Safresh1  'reference to non array throws exception' );
32