Update to Scalar-List-Utils 1.08
[p5sagit/p5-mst-13.2.git] / ext / List / Util / t / first.t
1 #!./perl
2
3 BEGIN {
4     unless (-d 'blib') {
5         chdir 't' if -d 't';
6         @INC = '../lib';
7         require Config; import Config;
8         keys %Config; # Silence warning
9         if ($Config{extensions} !~ /\bList\/Util\b/) {
10             print "1..0 # Skip: List::Util was not built\n";
11             exit 0;
12         }
13     }
14 }
15
16 use List::Util qw(first);
17
18 print "1..8\n";
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";
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";
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