Debian Codegraph @

cpan/Scalar-List-Utils/t/head-tail.t

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