1use Test::More; 2use strict; use warnings FATAL => 'all'; 3 4use List::Objects::WithUtils 'array'; 5 6my $arr = array; 7 8my $insert = $arr->insert(0 => 1); 9ok $insert == $arr, 'insert returned self ok'; 10is_deeply 11 [ $arr->all ], 12 [ 1 ], 13 'insert first position on empty list ok'; 14 15$arr->insert(4 => 2); 16is_deeply 17 [ $arr->all ], 18 [ 1, undef, undef, undef, 2 ], 19 'insert pre-filled nonexistant elems ok'; 20 21$arr->insert(3 => 3); 22is_deeply 23 [ $arr->all ], 24 [ 1, undef, undef, 3, undef, 2 ], 25 'insert to middle ok'; 26 27$arr->insert(5 => 5); 28is_deeply 29 [ $arr->all ], 30 [ 1, undef, undef, 3, undef, 5, 2 ], 31 'insert next-to-last ok'; 32 33$arr->insert( 7 => 7 ); 34is_deeply 35 [ $arr->all ], 36 [ 1, undef, undef, 3, undef, 5, 2, 7 ], 37 'insert last ok'; 38 39$arr->insert( 9 => 9 ); 40is_deeply 41 [ $arr->all ], 42 [ 1, undef, undef, 3, undef, 5, 2, 7, undef, 9 ], 43 'insert one-off last ok'; 44 45$arr->insert( 0 => 0 ); 46is_deeply 47 [ $arr->all ], 48 [ 0, 1, undef, undef, 3, undef, 5, 2, 7, undef, 9 ], 49 'insert first ok'; 50 51$arr->insert( 2 => 0, 1, 2 ); 52is_deeply 53 [ $arr->all ], 54 [ 0, 1, 0, 1, 2, undef, undef, 3, undef, 5, 2, 7, undef, 9 ], 55 'insert multiple ok'; 56 57done_testing; 58