1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 11:36:16 +00:00

Merge pull request #5013 from shinhs0506/core-version-cmp

uucore: leading zeros are ignored in version compare
This commit is contained in:
Sylvestre Ledru 2023-07-09 09:21:18 +02:00 committed by GitHub
commit 78fd0efab9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 64 deletions

View file

@ -2312,56 +2312,15 @@ fn test_ls_version_sort() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
for filename in [
"a2",
"b1",
"b20",
"a1.4",
"a1.40",
"b3",
"b11",
"b20b",
"b20a",
"a100",
"a1.13",
"aa",
"a1",
"aaa",
"a1.00000040",
"abab",
"ab",
"a01.40",
"a001.001",
"a01.0000001",
"a01.001",
"a001.01",
"a2", "b1", "b20", "a1.4", "b3", "b11", "b20b", "b20a", "a100", "a1.13", "aa", "a1", "aaa",
"abab", "ab", "a01.40", "a001.001",
] {
at.touch(filename);
}
let mut expected = vec![
"a1",
"a001.001",
"a001.01",
"a01.0000001",
"a01.001",
"a1.4",
"a1.13",
"a01.40",
"a1.00000040",
"a1.40",
"a2",
"a100",
"aa",
"aaa",
"ab",
"abab",
"b1",
"b3",
"b11",
"b20",
"b20a",
"b20b",
"", // because of '\n' at the end of the output
"a1", "a001.001", "a1.4", "a1.13", "a01.40", "a2", "a100", "aa", "aaa", "ab", "abab", "b1",
"b3", "b11", "b20", "b20a", "b20b", "", // because of '\n' at the end of the output
];
let result = scene.ucmd().arg("-1v").succeeds();

View file

@ -134,6 +134,25 @@ fn test_version_empty_lines() {
test_helper("version-empty-lines", &["-V", "--version-sort"]);
}
#[test]
fn test_version_sort_unstable() {
new_ucmd!()
.arg("--sort=version")
.pipe_in("0.1\n0.02\n0.2\n0.002\n0.3\n")
.succeeds()
.stdout_is("0.1\n0.002\n0.02\n0.2\n0.3\n");
}
#[test]
fn test_version_sort_stable() {
new_ucmd!()
.arg("--stable")
.arg("--sort=version")
.pipe_in("0.1\n0.02\n0.2\n0.002\n0.3\n")
.succeeds()
.stdout_is("0.1\n0.02\n0.2\n0.002\n0.3\n");
}
#[test]
fn test_human_numeric_whitespace() {
test_helper(