diff --git a/Cargo.lock b/Cargo.lock index dc87b58..dd43483 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,7 +135,7 @@ checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "semverator" -version = "0.4.3" +version = "0.5.0" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index b2075a5..016751a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "semverator" -version = "0.4.3" +version = "0.5.0" edition = "2021" license = "Apache-2.0" readme = "README.md" diff --git a/src/semver/compare.rs b/src/semver/compare.rs index 012e6b7..5717905 100644 --- a/src/semver/compare.rs +++ b/src/semver/compare.rs @@ -14,21 +14,25 @@ impl Semver { self.compare(other) == Ordering::Less } + // Treat majors >1996 as calver, and less than 0.0.0. + fn handle_calver(&self) -> Vec { + if self.major < 1996 || self.major == usize::MAX { + self.components.clone() + } else { + let mut cmps = vec![0, 0, 0]; + cmps.extend(self.components.iter().cloned()); + cmps + } + } + fn compare(&self, other: &Semver) -> Ordering { - let len = self.components.len().max(other.components.len()); + let acmps = self.handle_calver(); + let bcmps = other.handle_calver(); + + let len = acmps.len().max(bcmps.len()); for x in 0..len { - if x == 0 { - match ( - self.major > 1900 && self.major < usize::MAX, - other.major > 1900 && other.major < usize::MAX, - ) { - (true, false) => return Ordering::Less, - (false, true) => return Ordering::Greater, - _ => (), - } - } - let a = self.components.get(x); - let b = other.components.get(x); + let a = acmps.get(x); + let b = bcmps.get(x); match (a, b) { (None, _) => return Ordering::Less, (_, None) => return Ordering::Greater,