| 1 |
#!./perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test::More tests => 7; |
| 7 |
use List::Util qw(zip zip_longest zip_shortest); |
| 8 |
|
| 9 |
is_deeply( [zip ()], [], |
| 10 |
'zip empty returns empty'); |
| 11 |
|
| 12 |
is_deeply( [zip ['a'..'c']], [ ['a'], ['b'], ['c'] ], |
| 13 |
'zip of one list returns a list of singleton lists' ); |
| 14 |
|
| 15 |
is_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 |
|
| 20 |
is_deeply( [zip_longest ['x', 'y', 'z'], ['X', 'Y']], [ ['x', 'X'], ['y', 'Y'], ['z', undef] ], |
| 21 |
'zip_longest extends short lists with undef' ); |
| 22 |
|
| 23 |
is_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 |
| 27 |
ok( !defined eval { zip 1, 2, 3 }, |
| 28 |
'non-reference argument throws exception' ); |
| 29 |
|
| 30 |
ok( !defined eval { zip +{ one => 1 } }, |
| 31 |
'reference to non array throws exception' ); |