File: onlyres.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 (31 lines) | stat: -rw-r--r-- 900 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
BEGIN
{
    $INC{'List/MoreUtils.pm'} or *only_result = __PACKAGE__->can("onlyres");
}

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

my @list = (1 .. 300);
is("Hallelujah", onlyres { 150 == $_ and "Hallelujah" } @list);
is(1,            onlyres { 300 == $_ } @list);
is(undef,        onlyres { 0 == $_ } @list);
is(undef,        onlyres { 1 <= $_ } @list);
is(undef,        onlyres { !(127 & $_) } @list);

# Test aliases
is(1,            only_result { 150 == $_ } @list);
is("Hallelujah", only_result { 300 == $_ and "Hallelujah" } @list);
is(undef,        only_result { 0 == $_ } @list);
is(undef,        only_result { 1 <= $_ } @list);
is(undef,        only_result { !(127 & $_) } @list);

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

done_testing;