1#!./perl 2 3use strict; 4use warnings; 5 6use List::Util qw(head tail); 7use Test::More; 8plan tests => 42; 9 10my @ary; 11 12ok(defined &head, 'defined'); 13ok(defined &tail, 'defined'); 14 15@ary = head 1, ( 4, 5, 6 ); 16is( scalar @ary, 1 ); 17is( $ary[0], 4 ); 18 19@ary = head 2, ( 4, 5, 6 ); 20is( scalar @ary, 2 ); 21is( $ary[0], 4 ); 22is( $ary[1], 5 ); 23 24@ary = head -1, ( 4, 5, 6 ); 25is( scalar @ary, 2 ); 26is( $ary[0], 4 ); 27is( $ary[1], 5 ); 28 29@ary = head -2, ( 4, 5, 6 ); 30is( scalar @ary, 1 ); 31is( $ary[0], 4 ); 32 33@ary = head 999, ( 4, 5, 6 ); 34is( scalar @ary, 3 ); 35is( $ary[0], 4 ); 36is( $ary[1], 5 ); 37is( $ary[2], 6 ); 38 39@ary = head 0, ( 4, 5, 6 ); 40is( scalar @ary, 0 ); 41 42@ary = head 0; 43is( scalar @ary, 0 ); 44 45@ary = head 5; 46is( scalar @ary, 0 ); 47 48@ary = head -3, ( 4, 5, 6 ); 49is( scalar @ary, 0 ); 50 51@ary = head -999, ( 4, 5, 6 ); 52is( scalar @ary, 0 ); 53 54eval '@ary = head'; 55like( $@, qr{^Not enough arguments for List::Util::head} ); 56 57@ary = head 4, ( 4, 5, 6 ); 58is( scalar @ary, 3 ); 59is( $ary[0], 4 ); 60is( $ary[1], 5 ); 61is( $ary[2], 6 ); 62 63@ary = tail 1, ( 4, 5, 6 ); 64is( scalar @ary, 1 ); 65is( $ary[0], 6 ); 66 67@ary = tail 2, ( 4, 5, 6 ); 68is( scalar @ary, 2 ); 69is( $ary[0], 5 ); 70is( $ary[1], 6 ); 71 72@ary = tail -1, ( 4, 5, 6 ); 73is( scalar @ary, 2 ); 74is( $ary[0], 5 ); 75is( $ary[1], 6 ); 76 77@ary = tail -2, ( 4, 5, 6 ); 78is( scalar @ary, 1 ); 79is( $ary[0], 6 ); 80 81@ary = tail 0, ( 4, 5, 6 ); 82is( scalar @ary, 0 ); 83 84@ary = tail 0; 85is( scalar @ary, 0 ); 86 87@ary = tail 5; 88is( scalar @ary, 0 ); 89 90@ary = tail -3; 91is( scalar @ary, 0 ); 92 93@ary = tail -999; 94is( scalar @ary, 0 ); 95 96eval '@ary = tail'; 97like( $@, qr{^Not enough arguments for List::Util::tail} ); 98