diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2025-07-11 15:30:50 +0200 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2025-07-11 15:30:50 +0200 |
| commit | 838659ca0d6169dd143db97c53da42da60c89f9d (patch) | |
| tree | 6c5686a2054d69651905bacb8b8b127e0a944b49 | |
| parent | 4ee5c4cca8b30118d22cd747cb478d4c54c33680 (diff) | |
| parent | 7eada7830a77c6c58b00a850337d5efd8d36a1d0 (diff) | |
| download | mullvadvpn-838659ca0d6169dd143db97c53da42da60c89f9d.tar.xz mullvadvpn-838659ca0d6169dd143db97c53da42da60c89f9d.zip | |
Merge branch 'fix-version-partial-ord'
| -rw-r--r-- | .github/workflows/git-commit-message-style.yml | 2 | ||||
| -rw-r--r-- | mullvad-version/src/lib.rs | 34 |
2 files changed, 24 insertions, 12 deletions
diff --git a/.github/workflows/git-commit-message-style.yml b/.github/workflows/git-commit-message-style.yml index 04816d30c8..b32229754a 100644 --- a/.github/workflows/git-commit-message-style.yml +++ b/.github/workflows/git-commit-message-style.yml @@ -34,4 +34,4 @@ jobs: # This action defaults to 50 char subjects, but 72 is fine. max-subject-line-length: '72' # The action's wordlist is a bit short. Add more accepted verbs - additional-verbs: 'tidy, wrap, obfuscate, bias, prohibit, forbid, revert, slim' + additional-verbs: 'tidy, wrap, obfuscate, bias, prohibit, forbid, revert, slim, impl' diff --git a/mullvad-version/src/lib.rs b/mullvad-version/src/lib.rs index f52df40188..fc5a23ac94 100644 --- a/mullvad-version/src/lib.rs +++ b/mullvad-version/src/lib.rs @@ -60,17 +60,20 @@ impl PartialOrd for Version { } }; - // The dev vs non-dev ordering. For a version of a given type, if all else is equal - // a dev version is greater than a non-dev version. - let dev_ordering = match (self.is_dev(), other.is_dev()) { - (true, false) => Some(Ordering::Greater), - (false, true) => Some(Ordering::Less), - (_, _) => None, + // The dev vs non-dev ordering. + let dev_ordering = match (&self.dev, &other.dev) { + // All else being equal, a dev version is greater than a non-dev version + (Some(_), None) => Some(Ordering::Greater), + (None, Some(_)) => Some(Ordering::Less), + + // Dev-suffixes are not ordered, but they can be equal. + (Some(a), Some(b)) if a != b => None, + (Some(_), Some(_)) => Some(Ordering::Equal), + + (None, None) => Some(Ordering::Equal), }; - let release_ordering = self - .year - .cmp(&other.year) + let release_ordering = (self.year.cmp(&other.year)) .then(self.incremental.cmp(&other.incremental)) .then(type_ordering); @@ -237,13 +240,22 @@ mod tests { } #[test] + fn test_version_ordering_and_equality() { + let v = parse("2021.3"); + + // A version is equal to itself + assert_eq!(v, v); + assert_eq!(v.partial_cmp(&v), Some(Ordering::Equal)); + } + + #[test] fn test_version_ordering_and_equality_dev() { let v1 = parse("2021.3-dev-abc"); let v2 = parse("2021.3-dev-def"); - // Exactly the same version are equal, but has no ordering + // A dev version is equal to itself assert_eq!(v1, v1); - assert!(v1.partial_cmp(&v1).is_none()); + assert_eq!(v1.partial_cmp(&v1), Some(Ordering::Equal)); // Equal down to the dev suffix are not equal, and has no ordering assert_ne!(v1, v2); |
