Commit | Line | Data |
1bfb5477 |
1 | #!./perl |
2 | |
f4a2945e |
3 | BEGIN { |
1bfb5477 |
4 | unless (-d 'blib') { |
f4a2945e |
5 | chdir 't' if -d 't'; |
6 | @INC = '../lib'; |
6b05f64e |
7 | require Config; import Config; |
1bfb5477 |
8 | keys %Config; # Silence warning |
6b05f64e |
9 | if ($Config{extensions} !~ /\bList\/Util\b/) { |
10 | print "1..0 # Skip: List::Util was not built\n"; |
11 | exit 0; |
12 | } |
1bfb5477 |
13 | } |
f4a2945e |
14 | } |
15 | |
16 | use List::Util qw(first); |
17 | |
60f3865b |
18 | print "1..8\n"; |
f4a2945e |
19 | |
20 | print "not " unless defined &first; |
21 | print "ok 1\n"; |
22 | |
23 | print "not " unless 9 == first { 8 == ($_ - 1) } 9,4,5,6; |
24 | print "ok 2\n"; |
25 | |
26 | print "not " if defined(first { 0 } 1,2,3,4); |
27 | print "ok 3\n"; |
28 | |
29 | print "not " if defined(first { 0 }); |
30 | print "ok 4\n"; |
1bfb5477 |
31 | |
32 | my $foo = first { $_->[1] le "e" and "e" le $_->[2] } |
33 | [qw(a b c)], [qw(d e f)], [qw(g h i)]; |
34 | print "not " unless $foo->[0] eq 'd'; |
35 | print "ok 5\n"; |
36 | |
37 | # Check that eval{} inside the block works correctly |
38 | my $i = 0; |
39 | print "not " unless 5 == first { eval { die }; ($i == 5, $i = $_)[0] } 0,1,2,3,4,5,5; |
40 | print "ok 6\n"; |
41 | |
42 | print "not " if defined eval { first { die if $_ } 0,0,1 }; |
43 | print "ok 7\n"; |
60f3865b |
44 | |
45 | ($x) = foobar(); |
46 | $x = '' unless defined $x; |
47 | print "${x}ok 8\n"; |
48 | |
49 | sub foobar { first { !defined(wantarray) || wantarray } "not ","not ","not " } |
50 | |