diff options
author | Brian Ingerson <ingy@ttul.org> | 2001-09-30 14:45:56 -0700 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-10-01 03:58:37 +0000 |
commit | e9105f86fac986145f3f944f90b0191d33cf4185 (patch) | |
tree | b1deadcc621753ecbcc64ad576ff63363ede4b40 /ext/Data/Dumper/t | |
parent | c87b7cc25349df01ad9cb722a7ecfe9006abdfb5 (diff) | |
download | perl-e9105f86fac986145f3f944f90b0191d33cf4185.tar.gz |
Option to sort hashes
Message-ID: <20010930214556.D26392@ttul.org>
(remember also the #12289)
p4raw-id: //depot/perl@12288
Diffstat (limited to 'ext/Data/Dumper/t')
-rwxr-xr-x | ext/Data/Dumper/t/dumper.t | 107 |
1 files changed, 105 insertions, 2 deletions
diff --git a/ext/Data/Dumper/t/dumper.t b/ext/Data/Dumper/t/dumper.t index bf0722977f..2371835647 100755 --- a/ext/Data/Dumper/t/dumper.t +++ b/ext/Data/Dumper/t/dumper.t @@ -61,11 +61,11 @@ sub TEST { if (defined &Data::Dumper::Dumpxs) { print "### XS extension loaded, will run XS tests\n"; - $TMAX = 192; $XS = 1; + $TMAX = 210; $XS = 1; } else { print "### XS extensions not loaded, will NOT run XS tests\n"; - $TMAX = 96; $XS = 0; + $TMAX = 105; $XS = 0; } print "1..$TMAX\n"; @@ -821,3 +821,106 @@ EOT TEST q(Data::Dumper->Dumpxs([$a], ['a'])); } + +{ + $i = 0; + $a = { map { ("$_$_$_", ++$i) } 'I'..'Q' }; + local $Data::Dumper::Sortkeys = 1; + +############# 193 +## + $WANT = <<'EOT'; +#$VAR1 = { +# III => 1, +# JJJ => 2, +# KKK => 3, +# LLL => 4, +# MMM => 5, +# NNN => 6, +# OOO => 7, +# PPP => 8, +# QQQ => 9 +#}; +EOT + +TEST q(Data::Dumper->new([$a])->Dump;); +TEST q(Data::Dumper->new([$a])->Dumpxs;) + if $XS; +} + +{ + $i = 5; + $c = { map { (++$i, "$_$_$_") } 'I'..'Q' }; + local $Data::Dumper::Sortkeys = \&sort199; + sub sort199 { + my $hash = shift; + return [ sort { $b <=> $a } keys %$hash ]; + } + +############# 199 +## + $WANT = <<'EOT'; +#$VAR1 = { +# '14' => 'QQQ', +# '13' => 'PPP', +# '12' => 'OOO', +# '11' => 'NNN', +# '10' => 'MMM', +# '9' => 'LLL', +# '8' => 'KKK', +# '7' => 'JJJ', +# '6' => 'III' +#}; +EOT + +TEST q(Data::Dumper->new([$c])->Dump;); +TEST q(Data::Dumper->new([$c])->Dumpxs;) + if $XS; +} + +{ + $i = 5; + $c = { map { (++$i, "$_$_$_") } 'I'..'Q' }; + $d = { reverse %$c }; + local $Data::Dumper::Sortkeys = \&sort205; + sub sort205 { + my $hash = shift; + return [ + $hash eq $c ? (sort { $a <=> $b } keys %$hash) + : (reverse sort keys %$hash) + ]; + } + +############# 205 +## + $WANT = <<'EOT'; +#$VAR1 = [ +# { +# '6' => 'III', +# '7' => 'JJJ', +# '8' => 'KKK', +# '9' => 'LLL', +# '10' => 'MMM', +# '11' => 'NNN', +# '12' => 'OOO', +# '13' => 'PPP', +# '14' => 'QQQ' +# }, +# { +# QQQ => '14', +# PPP => '13', +# OOO => '12', +# NNN => '11', +# MMM => '10', +# LLL => '9', +# KKK => '8', +# JJJ => '7', +# III => '6' +# } +#]; +EOT + +TEST q(Data::Dumper->new([[$c, $d]])->Dump;); +TEST q(Data::Dumper->new([[$c, $d]])->Dumpxs;) + if $XS; +} |