File: firstidx.pm

package info (click to toggle)
liblist-moreutils-xs-perl 0.430-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,116 kB
  • sloc: perl: 9,038; ansic: 159; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 821 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
BEGIN
{
    $INC{'List/MoreUtils.pm'} or *first_index = __PACKAGE__->can("firstidx");
}

use Test::More;
use Test::LMU;

my @list = (1 .. 10000);
is(4999, (firstidx { $_ >= 5000 } @list),  "firstidx");
is(-1,   (firstidx { not defined } @list), "invalid firstidx");
is(0,    (firstidx { defined } @list),     "real firstidx");
is(-1,   (firstidx {}),                    "empty firstidx");

SKIP:
{
    # Test the alias
    is(4999, first_index { $_ >= 5000 } @list);
    is(-1,   first_index { not defined } @list);
    is(0,    first_index { defined } @list);
    is(-1,   first_index {});
}

leak_free_ok(
    firstidx => sub {
        my $i  = firstidx { $_ >= 5000 } @list;
        my $i2 = firstidx { $_ >= 5000 } 1 .. 10000;
    }
);
is_dying('firstidx without sub' => sub { &firstidx(42, 4711); });

done_testing;