"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "cpan/Scalar-List-Utils/t/first.t" between
perl-5.32.0-RC0.tar.xz and perl-5.32.0-RC1.tar.xz

About: Perl (Practical Extraction and Report Language) is a high-level, general-purpose, interpreted, dynamic programming language. Release candidate.

first.t  (perl-5.32.0-RC0.tar.xz):first.t  (perl-5.32.0-RC1.tar.xz)
#!./perl #!./perl
use strict; use strict;
use warnings; use warnings;
use List::Util qw(first); use List::Util qw(first);
use Test::More; use Test::More;
plan tests => 22 + ($::PERL_ONLY ? 0 : 2); plan tests => 24;
my $v; my $v;
ok(defined &first, 'defined'); ok(defined &first, 'defined');
$v = first { 8 == ($_ - 1) } 9,4,5,6; $v = first { 8 == ($_ - 1) } 9,4,5,6;
is($v, 9, 'one more than 8'); is($v, 9, 'one more than 8');
$v = first { 0 } 1,2,3,4; $v = first { 0 } 1,2,3,4;
is($v, undef, 'none match'); is($v, undef, 'none match');
$v = first { 0 }; $v = first { 0 };
is($v, undef, 'no args'); is($v, undef, 'no args');
$v = first { $_->[1] le "e" and "e" le $_->[2] } $v = first { $_->[1] le "e" and "e" le $_->[2] }
[qw(a b c)], [qw(d e f)], [qw(g h i)]; [qw(a b c)], [qw(d e f)], [qw(g h i)];
is_deeply($v, [qw(d e f)], 'reference args'); is_deeply($v, [qw(d e f)], 'reference args');
# Check that eval{} inside the block works correctly # Check that eval{} inside the block works correctly
my $i = 0; my $i = 0;
$v = first { eval { die }; ($i == 5, $i = $_)[0] } 0,1,2,3,4,5,5; $v = first { eval { die }; ($i == 5, $i = $_)[0] } 0,1,2,3,4,5,5;
is($v, 5, 'use of eval'); is($v, 5, 'use of eval');
$v = eval { first { die if $_ } 0,0,1 }; $v = eval { first { die if $_ } 0,0,1 };
is($v, undef, 'use of die'); is($v, undef, 'use of die');
skipping to change at line 92 skipping to change at line 92
# Calling a sub from first should leave its refcount unchanged. # Calling a sub from first should leave its refcount unchanged.
SKIP: { SKIP: {
skip("No Internals::SvREFCNT", 1) if !defined &Internals::SvREFCNT; skip("No Internals::SvREFCNT", 1) if !defined &Internals::SvREFCNT;
sub huge {$_>1E6} sub huge {$_>1E6}
my $refcnt = &Internals::SvREFCNT(\&huge); my $refcnt = &Internals::SvREFCNT(\&huge);
$v = first \&huge, 1..6; $v = first \&huge, 1..6;
is(&Internals::SvREFCNT(\&huge), $refcnt, "Refcount unchanged"); is(&Internals::SvREFCNT(\&huge), $refcnt, "Refcount unchanged");
} }
# The remainder of the tests are only relevant for the XS # These tests are only relevant for the real multicall implementation. The
# implementation. The Perl-only implementation behaves differently # psuedo-multicall implementation behaves differently.
# (and more flexibly) in a way that we can't emulate from XS. SKIP: {
if (!$::PERL_ONLY) { SKIP: {
$List::Util::REAL_MULTICALL ||= 0; # Avoid use only once $List::Util::REAL_MULTICALL ||= 0; # Avoid use only once
skip("Poor man's MULTICALL can't cope", 2) skip("Poor man's MULTICALL can't cope", 2)
if !$List::Util::REAL_MULTICALL; if !$List::Util::REAL_MULTICALL;
# Can we goto a label from the 'first' sub? # Can we goto a label from the 'first' sub?
eval {()=first{goto foo} 1,2; foo: 1}; eval {()=first{goto foo} 1,2; foo: 1};
like($@, qr/^Can't "goto" out of a pseudo block/, "goto label"); like($@, qr/^Can't "goto" out of a pseudo block/, "goto label");
# Can we goto a subroutine? # Can we goto a subroutine?
eval {()=first{goto sub{}} 1,2;}; eval {()=first{goto sub{}} 1,2;};
like($@, qr/^Can't goto subroutine from a sort sub/, "goto sub"); like($@, qr/^Can't goto subroutine from a sort sub/, "goto sub");
}
} }
use constant XSUBC_TRUE => 1; use constant XSUBC_TRUE => 1;
use constant XSUBC_FALSE => 0; use constant XSUBC_FALSE => 0;
is first(\&XSUBC_TRUE, 42, 1, 2, 3), 42, 'XSUB callbacks'; is first(\&XSUBC_TRUE, 42, 1, 2, 3), 42, 'XSUB callbacks';
is first(\&XSUBC_FALSE, 42, 1, 2, 3), undef, 'XSUB callbacks'; is first(\&XSUBC_FALSE, 42, 1, 2, 3), undef, 'XSUB callbacks';
eval { &first(1) }; eval { &first(1) };
ok($@ =~ /^Not a subroutine reference/, 'check for code reference'); ok($@ =~ /^Not a subroutine reference/, 'check for code reference');
eval { &first(1,2) }; eval { &first(1,2) };
 End of changes. 5 change blocks. 
10 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)