1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 05:27:45 +00:00

Fix SemVer non version lines/empty line sorting with a test

This commit is contained in:
electricboogie 2021-04-10 15:27:16 -05:00
parent 7133273725
commit c6021e10c2
4 changed files with 44 additions and 2 deletions

View file

@ -1262,10 +1262,21 @@ fn month_compare(a: &str, b: &str) -> Ordering {
}
}
fn version_parse(a: &str) -> Version {
let result = Version::parse(a);
match result {
Ok(vers_a) => vers_a,
// Non-version lines parse to 0.0.0
Err(_e) => Version::parse("0.0.0").unwrap(),
}
}
fn version_compare(a: &str, b: &str) -> Ordering {
#![allow(clippy::comparison_chain)]
let ver_a = Version::parse(a);
let ver_b = Version::parse(b);
let ver_a = version_parse(a);
let ver_b = version_parse(b);
// Version::cmp is not implemented; implement comparison directly
if ver_a > ver_b {
Ordering::Greater

View file

@ -13,6 +13,15 @@ fn test_months_whitespace() {
test_helper("months-whitespace", "-M");
}
#[test]
fn test_version_empty_lines() {
new_ucmd!()
.arg("-V")
.arg("version-empty-lines.txt")
.succeeds()
.stdout_is("\n\n\n\n\n\n\n1.2.3-alpha\n1.2.3-alpha2\n\t\t\t1.12.4\n11.2.3\n");
}
#[test]
fn test_human_numeric_whitespace() {
test_helper("human-numeric-whitespace", "-h");

View file

@ -0,0 +1,11 @@
1.2.3-alpha
1.2.3-alpha2
11.2.3
1.12.4

View file

@ -0,0 +1,11 @@
11.2.3
1.2.3-alpha2
1.2.3-alpha
1.12.4