"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "cpan/Scalar-List-Utils/t/uniq.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.

uniq.t  (perl-5.32.0-RC0.tar.xz):uniq.t  (perl-5.32.0-RC1.tar.xz)
#!./perl #!./perl
use strict; use strict;
use warnings; use warnings;
use Config; # to determine ivsize
use Test::More tests => 33; use Test::More tests => 31;
use List::Util qw( uniqnum uniqstr uniq ); use List::Util qw( uniqstr uniqint uniq );
use Tie::Array; use Tie::Array;
is_deeply( [ uniqstr ], is_deeply( [ uniqstr ],
[], [],
'uniqstr of empty list' ); 'uniqstr of empty list' );
is_deeply( [ uniqstr qw( abc ) ], is_deeply( [ uniqstr qw( abc ) ],
[qw( abc )], [qw( abc )],
'uniqstr of singleton list' ); 'uniqstr of singleton list' );
skipping to change at line 70 skipping to change at line 70
utf8::encode( my $cafebytes = $cafe ); utf8::encode( my $cafebytes = $cafe );
is_deeply( [ uniqstr $cafe, $cafebytes ], is_deeply( [ uniqstr $cafe, $cafebytes ],
[ $cafe, $cafebytes ], [ $cafe, $cafebytes ],
'uniqstr does not squash bytewise-equal but differently-encoded strings' ); 'uniqstr does not squash bytewise-equal but differently-encoded strings' );
} }
is( $warnings, "", 'No warnings are printed when handling Unicode strings' ) ; is( $warnings, "", 'No warnings are printed when handling Unicode strings' ) ;
} }
is_deeply( [ uniqnum qw( 1 1.0 1E0 2 3 ) ], is_deeply( [ uniqint ],
[ 1, 2, 3 ], [],
'uniqnum compares numbers' ); 'uniqint of empty list' );
is_deeply( [ uniqnum qw( 1 1.1 1.2 1.3 ) ],
[ 1, 1.1, 1.2, 1.3 ],
'uniqnum distinguishes floats' );
{
my @nums = map $_+0.1, 1e7..1e7+5;
is_deeply( [ uniqnum @nums ],
[ @nums ],
'uniqnum distinguishes large floats' );
my @strings = map "$_", @nums;
is_deeply( [ uniqnum @strings ],
[ @strings ],
'uniqnum distinguishes large floats (stringified)' );
}
# Hard to know for sure what an Inf is going to be. Lets make one
my $Inf = 0 + 1E1000;
my $NaN;
$Inf **= 1000 while ( $NaN = $Inf - $Inf ) == $NaN;
is_deeply( [ uniqnum 0, 1, 12345, $Inf, -$Inf, $NaN, 0, $Inf, $NaN ],
[ 0, 1, 12345, $Inf, -$Inf, $NaN ],
'uniqnum preserves the special values of +-Inf and Nan' );
SKIP: {
my $maxuint = ~0;
my $maxint = ~0 >> 1;
my $minint = -(~0 >> 1) - 1;
my @nums = ($maxuint, $maxuint-1, -1, $Inf, $NaN, $maxint, $minint, 1 );
is_deeply( [ uniqnum @nums, 1.0 ],
[ @nums ],
'uniqnum preserves uniqness of full integer range' );
my @strs = map "$_", @nums; is_deeply( [ uniqint 5, 5 ],
[ 5 ],
'uniqint of repeated-element list' );
skip( "Perl $] doesn't stringify UV_MAX right ($maxuint)", 1 ) is_deeply( [ uniqint 1, 2, 1, 3 ],
if $maxuint !~ /\A[0-9]+\z/; [ 1, 2, 3 ],
'uniqint removes subsequent duplicates' );
is_deeply( [ uniqnum @strs, "1.0" ], is_deeply( [ uniqint 6.1, 6.2, 6.3 ],
[ @strs ], [ 6 ],
'uniqnum preserves uniqness of full integer range (stringified)' 'uniqint compares as and returns integers' );
);
}
{ {
my $warnings = ""; my $warnings = "";
local $SIG{__WARN__} = sub { $warnings .= join "", @_ }; local $SIG{__WARN__} = sub { $warnings .= join "", @_ };
is_deeply( [ uniqnum 0, undef ], is_deeply( [ uniqint 0, undef ],
[ 0 ], [ 0 ],
'uniqnum considers undef and zero equivalent' ); 'uniqint considers undef and zero equivalent' );
ok( length $warnings, 'uniqnum on undef yields a warning' ); ok( length $warnings, 'uniqint on undef yields a warning' );
is_deeply( [ uniqnum undef ], is_deeply( [ uniqint undef ],
[ 0 ], [ 0 ],
'uniqnum on undef coerces to zero' ); 'uniqint on undef coerces to zero' );
}
SKIP: {
skip('UVs are not reliable on this perl version', 2) unless $] ge "5.008000"
;
my $maxbits = $Config{ivsize} * 8 - 1;
# An integer guaranteed to be a UV
my $uv = 1 << $maxbits;
is_deeply( [ uniqint $uv, $uv + 1 ],
[ $uv, $uv + 1 ],
'uniqint copes with UVs' );
my $nvuv = 2 ** $maxbits;
is_deeply( [ uniqint $nvuv, 0 ],
[ int($nvuv), 0 ],
'uniqint copes with NVUV dualvars' );
} }
is_deeply( [ uniq () ], is_deeply( [ uniq () ],
[], [],
'uniq of empty list' ); 'uniq of empty list' );
{ {
my $warnings = ""; my $warnings = "";
local $SIG{__WARN__} = sub { $warnings .= join "", @_ }; local $SIG{__WARN__} = sub { $warnings .= join "", @_ };
skipping to change at line 172 skipping to change at line 155
package main; package main;
my @strs = map { Stringify->new( $_ ) } qw( foo foo bar ); my @strs = map { Stringify->new( $_ ) } qw( foo foo bar );
is_deeply( [ map "$_", uniqstr @strs ], is_deeply( [ map "$_", uniqstr @strs ],
[ map "$_", $strs[0], $strs[2] ], [ map "$_", $strs[0], $strs[2] ],
'uniqstr respects stringify overload' ); 'uniqstr respects stringify overload' );
} }
{ SKIP: {
package Numify; skip('int overload requires perl version 5.8.0', 1) unless $] ge "5.008000";
use overload '0+' => sub { return $_[0]->{num} }; package Googol;
sub new { bless { num => $_[1] }, $_[0] } use overload '""' => sub { "1" . ( "0"x100 ) },
'int' => sub { $_[0] };
package main; sub new { bless {}, $_[0] }
use Scalar::Util qw( refaddr );
my @nums = map { Numify->new( $_ ) } qw( 2 2 5 ); package main;
# is_deeply wants to use eq overloading is_deeply( [ uniqint( Googol->new, Googol->new ) ],
my @ret = uniqnum @nums; [ "1" . ( "0"x100 ) ],
ok( scalar @ret == 2 && 'uniqint respects int overload' );
refaddr $ret[0] == refaddr $nums[0] &&
refaddr $ret[1] == refaddr $nums[2],
'uniqnum respects numify overload' );
} }
{ {
package DestroyNotifier; package DestroyNotifier;
use overload '""' => sub { "SAME" }; use overload '""' => sub { "SAME" };
sub new { bless { var => $_[1] }, $_[0] } sub new { bless { var => $_[1] }, $_[0] }
sub DESTROY { ${ $_[0]->{var} }++ } sub DESTROY { ${ $_[0]->{var} }++ }
skipping to change at line 222 skipping to change at line 202
undef @uniqstr; undef @uniqstr;
is_deeply( \@destroyed, [ 1, 1, 1 ], is_deeply( \@destroyed, [ 1, 1, 1 ],
'all values destroyed' ); 'all values destroyed' );
} }
{ {
"a a b" =~ m/(.) (.) (.)/; "a a b" =~ m/(.) (.) (.)/;
is_deeply( [ uniqstr $1, $2, $3 ], is_deeply( [ uniqstr $1, $2, $3 ],
[qw( a b )], [qw( a b )],
'uniqstr handles magic' ); 'uniqstr handles magic' );
"1 1 2" =~ m/(.) (.) (.)/;
is_deeply( [ uniqnum $1, $2, $3 ],
[ 1, 2 ],
'uniqnum handles magic' );
} }
{ {
my @array; my @array;
tie @array, 'Tie::StdArray'; tie @array, 'Tie::StdArray';
@array = ( @array = (
( map { ( 1 .. 10 ) } 0 .. 1 ), ( map { ( 1 .. 10 ) } 0 .. 1 ),
( map { ( 'a' .. 'z' ) } 0 .. 1 ) ( map { ( 'a' .. 'z' ) } 0 .. 1 )
); );
 End of changes. 17 change blocks. 
73 lines changed or deleted 48 lines changed or added

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