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 | |
1bfb5477 |
16 | |
f4a2945e |
17 | use List::Util qw(reduce min); |
18 | |
60f3865b |
19 | print "1..9\n"; |
f4a2945e |
20 | |
21 | print "not " if defined reduce {}; |
22 | print "ok 1\n"; |
23 | |
24 | print "not " unless 9 == reduce { $a / $b } 756,3,7,4; |
25 | print "ok 2\n"; |
26 | |
27 | print "not " unless 9 == reduce { $a / $b } 9; |
28 | print "ok 3\n"; |
29 | |
30 | @a = map { rand } 0 .. 20; |
31 | print "not " unless min(@a) == reduce { $a < $b ? $a : $b } @a; |
32 | print "ok 4\n"; |
33 | |
34 | @a = map { pack("C", int(rand(256))) } 0 .. 20; |
35 | print "not " unless join("",@a) eq reduce { $a . $b } @a; |
36 | print "ok 5\n"; |
1bfb5477 |
37 | |
38 | sub add { |
39 | my($aa, $bb) = @_; |
40 | return $aa + $bb; |
41 | } |
42 | |
43 | my $sum = reduce { my $t="$a $b\n"; 0+add($a, $b) } 3, 2, 1; |
44 | print "not " unless $sum == 6; |
45 | print "ok 6\n"; |
46 | |
47 | # Check that eval{} inside the block works correctly |
48 | print "not " unless 10 == reduce { eval { die }; $a + $b } 0,1,2,3,4; |
49 | print "ok 7\n"; |
50 | |
51 | print "not " if defined eval { reduce { die if $b > 2; $a + $b } 0,1,2,3,4 }; |
52 | print "ok 8\n"; |
60f3865b |
53 | |
54 | ($x) = foobar(); |
55 | print "${x}ok 9\n"; |
56 | |
57 | sub foobar { reduce { (defined(wantarray) && !wantarray) ? '' : 'not ' } 0,1,2,3 } |
58 | |