1use Test::More; 2use strict; use warnings FATAL => 'all'; 3 4use List::Objects::WithUtils 'array'; 5 6my $arr = array( 1, 2, 1, 1, 3, 4, 1 ); 7 8my $deleted = $arr->delete_when(sub { $_ == 1 }); 9 10is_deeply [ $deleted->all ], [ (1) x 4 ], 11 'delete_when returned correct values'; 12 13is_deeply [ $arr->all ], [ 2, 3, 4 ], 14 'delete_when deleted correct values'; 15 16$arr->delete_when(sub { $_[0] == 2 }); 17is_deeply [ $arr->all ], [ 3, 4 ], 18 'delete_when using @_ ok'; 19 20$deleted = $arr->delete_when(sub { $_ == 10 }); 21is_deeply [ $arr->all ], [ 3, 4 ], 22 'delete_when deleted nothing ok'; 23 24is_deeply [ $deleted->all ], [], 25 'delete_when deleted nothing ok'; 26 27$arr = array; 28$deleted = $arr->delete_when(sub { $_ == 2 }); 29ok $deleted->is_empty, 'delete_when on empty list ok'; 30ok $arr->is_empty, 'delete_when on empty list left list alone'; 31 32done_testing; 33