File: onlyidx.pm

package info (click to toggle)
liblist-moreutils-perl 0.430-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,228 kB
  • sloc: perl: 13,167; makefile: 17
file content (33 lines) | stat: -rw-r--r-- 845 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
33
BEGIN
{
    $INC{'List/MoreUtils.pm'} or *only_index = __PACKAGE__->can("onlyidx");
}

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

my @list = (1 .. 300);
is(0,   onlyidx { 1 == $_ } @list);
is(149, onlyidx { 150 == $_ } @list);
is(299, onlyidx { 300 == $_ } @list);
is(-1,  onlyidx { 0 == $_ } @list);
is(-1,  onlyidx { 1 <= $_ } @list);
is(-1,  onlyidx { !(127 & $_) } @list);

# Test aliases
is(0,   only_index { 1 == $_ } @list);
is(149, only_index { 150 == $_ } @list);
is(299, only_index { 300 == $_ } @list);
is(-1,  only_index { 0 == $_ } @list);
is(-1,  only_index { 1 <= $_ } @list);
is(-1,  only_index { !(127 & $_) } @list);

leak_free_ok(
    onlyidx => sub {
        my $ok  = onlyidx { 150 <= $_ } @list;
        my $ok2 = onlyidx { 150 <= $_ } 1 .. 300;
    }
);
is_dying('onlyidx without sub' => sub { &onlyidx(42, 4711); });

done_testing;