diff options
author | Zefram <zefram@fysh.org> | 2009-09-27 14:42:11 +0200 |
---|---|---|
committer | Rafael Garcia-Suarez <rgs@consttype.org> | 2009-09-27 14:42:11 +0200 |
commit | 93e19c0f634ff075d96380394c4e3449389368d8 (patch) | |
tree | 7a430f687af4320300fe628219042a91e1cb8570 /t/op/sort.t | |
parent | 338584c0b1c948a967b5e2ecbb69c512410589e4 (diff) | |
download | perl-93e19c0f634ff075d96380394c4e3449389368d8.tar.gz |
[perl #69384] numericness failure in sorting
This patch removes the error "Sort subroutine didn't return a numeric
value" and adds a regression test.
Diffstat (limited to 't/op/sort.t')
-rw-r--r-- | t/op/sort.t | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/t/op/sort.t b/t/op/sort.t index 616761a05d..8484827b6d 100644 --- a/t/op/sort.t +++ b/t/op/sort.t @@ -6,7 +6,7 @@ BEGIN { require 'test.pl'; } use warnings; -plan( tests => 144 ); +plan( tests => 146 ); # these shouldn't hang { @@ -801,3 +801,10 @@ is("@b", "10 9 8 7 6 5 4 3 2 1", "return with SVs on stack"); sub ret_with_stacked { $_ = ($a<=>$b) + do {return $b <=> $a} } @b = sort ret_with_stacked 1..10; is("@b", "10 9 8 7 6 5 4 3 2 1", "return with SVs on stack"); + +# Comparison code should be able to give result in non-integer representation. +sub cmp_as_string($$) { $_[0] < $_[1] ? "-1" : $_[0] == $_[1] ? "0" : "+1" } +@b = sort { cmp_as_string($a, $b) } (1,5,4,7,3,2,3); +is("@b", "1 2 3 3 4 5 7", "comparison result as string"); +@b = sort cmp_as_string (1,5,4,7,3,2,3); +is("@b", "1 2 3 3 4 5 7", "comparison result as string"); |