1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 21:47:46 +00:00

sort: compatibility of human-numeric sort

Closes #1985.
This makes human-numeric sort follow the same algorithm as GNU's/FreeBSD's sort.
As documented by GNU in https://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html,
we first compare by sign, then by si unit and finally by the numeric value.
This commit is contained in:
Michael Debertol 2021-06-25 18:19:00 +02:00
parent fef8761ac1
commit 548a895cd6
6 changed files with 77 additions and 25 deletions

View file

@ -456,10 +456,20 @@ fn test_human_block_sizes2() {
.arg(human_numeric_sort_param)
.pipe_in(input)
.succeeds()
.stdout_only("-8T\n0.8M\n8981K\n21G\n909991M\n");
.stdout_only("-8T\n8981K\n0.8M\n909991M\n21G\n");
}
}
#[test]
fn test_human_numeric_zero_stable() {
let input = "0M\n0K\n-0K\n-P\n-0M\n";
new_ucmd!()
.arg("-hs")
.pipe_in(input)
.succeeds()
.stdout_only(input);
}
#[test]
fn test_month_default2() {
for month_sort_param in &["-M", "--month-sort", "--sort=month"] {

View file

@ -1,3 +1,4 @@
0K
K
844K
981K

View file

@ -1,3 +1,6 @@
0K
__
__
K
^ no match for key
_

View file

@ -9,4 +9,5 @@
844K
981K
13M
K
K
0K