1#!./perl 2 3use strict; 4use warnings; 5 6use Test::More tests => 7; 7use List::Util qw(zip zip_longest zip_shortest); 8 9is_deeply( [zip ()], [], 10 'zip empty returns empty'); 11 12is_deeply( [zip ['a'..'c']], [ ['a'], ['b'], ['c'] ], 13 'zip of one list returns a list of singleton lists' ); 14 15is_deeply( [zip ['one', 'two'], [1, 2]], [ [one => 1], [two => 2] ], 16 'zip of two lists returns a list of pair lists' ); 17 18# Unequal length arrays 19 20is_deeply( [zip_longest ['x', 'y', 'z'], ['X', 'Y']], [ ['x', 'X'], ['y', 'Y'], ['z', undef] ], 21 'zip_longest extends short lists with undef' ); 22 23is_deeply( [zip_shortest ['x', 'y', 'z'], ['X', 'Y']], [ ['x', 'X'], ['y', 'Y'] ], 24 'zip_shortest stops after shortest list' ); 25 26# Non arrayref arguments throw exception 27ok( !defined eval { zip 1, 2, 3 }, 28 'non-reference argument throws exception' ); 29 30ok( !defined eval { zip +{ one => 1 } }, 31 'reference to non array throws exception' ); 32