File: first_index.t

package info (click to toggle)
liblist-objects-withutils-perl 2.028003-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,292 kB
  • sloc: perl: 1,957; makefile: 17; sh: 1
file content (21 lines) | stat: -rw-r--r-- 505 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
use Test::More;
use strict; use warnings FATAL => 'all';

use List::Objects::WithUtils 'array';

my $arr = array(qw/ a ba bb c /);
my $firstidx = $arr->firstidx(sub { /^b/ });
ok $firstidx == 1, 'firstidx ok';
ok $arr->first_index(sub { /^b/ }) == $firstidx,
  'first_index alias ok';

ok $arr->first_index(sub { /c/ }) == 3,
  'firstidx ok';

ok $arr->first_index(sub { /d/ }) == -1,
  'negative first_index ok';

ok array->first_index(sub { 1 }) == -1,
  'first_index on empty array ok';

done_testing;