@INC = '../lib';
}
use warnings;
-print "1..125\n";
+print "1..129\n";
# these shouldn't hang
{
my $upperfirst = 'A' lt 'a';
# Beware: in future this may become hairier because of possible
-# collation complications: qw(A a B c) can be sorted at least as
+# collation complications: qw(A a B b) can be sorted at least as
# any of the following
#
# A a B b
@input = sort {$b <=> $a} @input;
ok "@input", "G H I D E F A B C", 'stable $b <=> $a in place sort';
+# test that optimized {$b cmp $a} and {$b <=> $a} remain stable
+# (new in 5.9) without overloading
+{ no warnings;
+@b = sort { $b <=> $a } @input = qw/5first 6first 5second 6second/;
+ok "@b" , "6first 6second 5first 5second", "optimized {$b <=> $a} without overloading" ;
+@input = sort {$b <=> $a} @input;
+ok "@input" , "6first 6second 5first 5second","inline optimized {$b <=> $a} without overloading" ;
+};
+
# These two are actually doing string cmp on 0 1 and 2
@input = &generate1;
@output = reverse sort @input;
ok "@output", "I H G F E D C B A",
'reversed stable $a <=> $b sort return list context';
$output = sortnumr &generate1;
-ok $output, "IHGFEDCBA",
- 'reversed stable $a <=> $b sort return scalar context';
+ok $output, "IHGFEDCBA", 'reversed stable $a <=> $b sort return scalar context';
sub sortnumrba {
reverse sort {$b <=> $a} @_;
ok "@output", "C B A F E D I H G",
'reversed stable $b <=> $a sort return list context';
$output = sortnumrba &generate1;
-ok $output, "CBAFEDIHG",
-'reversed stable $b <=> $a sort return scalar context';
+ok $output, "CBAFEDIHG", 'reversed stable $b <=> $a sort return scalar context';
sub sortnumrq {
reverse sort {stuff || $a <=> $b} @_;
ok "@output", "I H G F E D C B A",
'reversed stable complex sort return list context';
$output = sortnumrq &generate1;
-ok $output, "IHGFEDCBA",
- 'reversed stable complex sort return scalar context';
+ok $output, "IHGFEDCBA", 'reversed stable complex sort return scalar context';
+
+@output = reverse (sort(qw(C A B)), 0);
+ok "@output", "0 C B A", 'reversed sort with trailing argument';
+
+@output = reverse (0, sort(qw(C A B)));
+ok "@output", "C B A 0", 'reversed sort with leading argument';