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:
parent
7133273725
commit
c6021e10c2
4 changed files with 44 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
11
tests/fixtures/sort/version-empty-lines.expected
vendored
Normal file
11
tests/fixtures/sort/version-empty-lines.expected
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1.2.3-alpha
|
||||
1.2.3-alpha2
|
||||
11.2.3
|
||||
1.12.4
|
11
tests/fixtures/sort/version-empty-lines.txt
vendored
Normal file
11
tests/fixtures/sort/version-empty-lines.txt
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
11.2.3
|
||||
|
||||
|
||||
|
||||
1.2.3-alpha2
|
||||
|
||||
|
||||
1.2.3-alpha
|
||||
|
||||
|
||||
1.12.4
|
Loading…
Add table
Add a link
Reference in a new issue