1use Test::More; 2use strict; use warnings FATAL => 'all'; 3 4use List::Objects::WithUtils 'array'; 5 6my $arr = array(qw/ a b c d/); 7 8my $meshed = $arr->mesh( array(1, 2, 3, 4) ); 9is_deeply 10 [ $meshed->all ], 11 [ a => 1, b => 2, c => 3, d => 4 ], 12 'mesh on even lists ok'; 13 14$meshed = $arr->mesh([1,2]); 15is_deeply 16 [ $meshed->all ], 17 [ 'a', 1, 'b', 2, 'c', undef, 'd', undef ], 18 'mesh on uneven lists ok'; 19 20my @holey; $#holey = 9; 21$meshed = array( 1 .. 10 )->mesh( array(@holey) ); 22is_deeply 23 [ $meshed->all ], 24 [ 25 1, undef, 2, undef, 3, undef, 4, undef, 5, undef, 26 6, undef, 7, undef, 8, undef, 9, undef, 10, undef 27 ], 28 'mesh with undef-filled list ok'; 29 30my @first = ( 1, 2 ); 31my @second = qw/ foo bar baz/; 32$meshed = array( 'x' )->mesh( array(@first), \@second ); 33is_deeply 34 [ $meshed->all ], 35 [ 'x', 1, 'foo', undef, 2, 'bar', undef, undef, 'baz' ], 36 'mesh on mixed object/ref arrays ok'; 37 38eval {; array('foo')->mesh('bar') }; 39ok $@ =~ /ARRAY/, 'mesh with bad args dies' 40 or diag explain $@; 41 42ok array->mesh([], [])->is_empty, 43 'meshing empty arrays ok'; 44 45ok array->zip([], [])->is_empty, 'zip alias for mesh ok'; 46 47done_testing; 48