fmt
This commit is contained in:
+13
-8
@@ -102,7 +102,8 @@ impl DebianVersion {
|
||||
/// - digit chunks compare numerically (leading zeroes are irrelevant; an
|
||||
/// empty digit chunk counts as `0`, so a missing revision equals `0`).
|
||||
pub fn compare(a: &DebianVersion, b: &DebianVersion) -> std::cmp::Ordering {
|
||||
a.epoch.unwrap_or(0)
|
||||
a.epoch
|
||||
.unwrap_or(0)
|
||||
.cmp(&b.epoch.unwrap_or(0))
|
||||
.then_with(|| verrevcmp(a.upstream.as_bytes(), b.upstream.as_bytes()))
|
||||
.then_with(|| {
|
||||
@@ -137,8 +138,7 @@ fn verrevcmp(mut a: &[u8], mut b: &[u8]) -> std::cmp::Ordering {
|
||||
// Non-digit chunks: compare by character weight. A chunk boundary
|
||||
// (end of string or start of a digit run) weighs 0, which sorts
|
||||
// after `~` (-1) and before every real character.
|
||||
while (!a.is_empty() && !a[0].is_ascii_digit())
|
||||
|| (!b.is_empty() && !b[0].is_ascii_digit())
|
||||
while (!a.is_empty() && !a[0].is_ascii_digit()) || (!b.is_empty() && !b[0].is_ascii_digit())
|
||||
{
|
||||
let ac = if !a.is_empty() && !a[0].is_ascii_digit() {
|
||||
char_order(a[0])
|
||||
@@ -276,7 +276,14 @@ pub(crate) mod test_vectors {
|
||||
],
|
||||
),
|
||||
(
|
||||
&["4", "5.0abc", "0.0alpha0", "10.100.1", "0~999.999zeta", "1.0"],
|
||||
&[
|
||||
"4",
|
||||
"5.0abc",
|
||||
"0.0alpha0",
|
||||
"10.100.1",
|
||||
"0~999.999zeta",
|
||||
"1.0",
|
||||
],
|
||||
&[
|
||||
"0~999.999zeta",
|
||||
"0.0alpha0",
|
||||
@@ -334,10 +341,8 @@ mod tests {
|
||||
#[test]
|
||||
fn comparison_dpkg_vectors() {
|
||||
for (a, b, expected) in test_vectors::COMPARE {
|
||||
let va =
|
||||
DebianVersion::parse(a).unwrap_or_else(|e| panic!("parse {a}: {e}"));
|
||||
let vb =
|
||||
DebianVersion::parse(b).unwrap_or_else(|e| panic!("parse {b}: {e}"));
|
||||
let va = DebianVersion::parse(a).unwrap_or_else(|e| panic!("parse {a}: {e}"));
|
||||
let vb = DebianVersion::parse(b).unwrap_or_else(|e| panic!("parse {b}: {e}"));
|
||||
assert_eq!(
|
||||
cmp_sign(&va, &vb),
|
||||
*expected,
|
||||
|
||||
Reference in New Issue
Block a user