From 4818abfd036da577da7b79129425e2a2a6944f03 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 14 Mar 2024 22:39:07 -0400 Subject: [PATCH] Simplify some tests --- crates/pep440-rs/src/version.rs | 65 +++++---------------------------- 1 file changed, 10 insertions(+), 55 deletions(-) diff --git a/crates/pep440-rs/src/version.rs b/crates/pep440-rs/src/version.rs index 9823bd37ed670..644fae160baca 100644 --- a/crates/pep440-rs/src/version.rs +++ b/crates/pep440-rs/src/version.rs @@ -2414,30 +2414,15 @@ pub(crate) fn compare_release(this: &[u64], other: &[u64]) -> Ordering { fn sortable_tuple(version: &Version) -> (u64, u64, Option, u64, &[LocalSegment]) { // If the version is a "max" version, use a post version larger than any possible post version. let post = if version.is_max() { - // But don't convert a `dev` version to a `post` version. `1.0.dev0` should _not_ be greater - // than `1.0.post0.dev0`, since the latter means "a dev release of a post release of 1.0", - // not "a post release of a dev release of 1.0". - if version.is_dev() && !version.is_post() { - None - } else { - Some(u64::MAX) - } + Some(u64::MAX) } else { version.post() }; - - // If the version is a "max" version, use a local version larger than any possible local version. - let local = if version.is_max() { - &[LocalSegment::Number(u64::MAX)] - } else { - version.local() - }; - match (version.pre(), post, version.dev(), version.min()) { // min release - (_pre, post, _dev, Some(n)) => (0, 0, post, n, local), + (_pre, post, _dev, Some(n)) => (0, 0, post, n, version.local()), // dev release - (None, None, Some(n), None) => (1, 0, None, n, local), + (None, None, Some(n), None) => (1, 0, None, n, version.local()), // alpha release ( Some(PreRelease { @@ -2447,7 +2432,7 @@ fn sortable_tuple(version: &Version) -> (u64, u64, Option, u64, &[LocalSegm post, dev, None, - ) => (2, n, post, dev.unwrap_or(u64::MAX), local), + ) => (2, n, post, dev.unwrap_or(u64::MAX), version.local()), // beta release ( Some(PreRelease { @@ -2457,7 +2442,7 @@ fn sortable_tuple(version: &Version) -> (u64, u64, Option, u64, &[LocalSegm post, dev, None, - ) => (3, n, post, dev.unwrap_or(u64::MAX), local), + ) => (3, n, post, dev.unwrap_or(u64::MAX), version.local()), // alpha release ( Some(PreRelease { @@ -2467,11 +2452,13 @@ fn sortable_tuple(version: &Version) -> (u64, u64, Option, u64, &[LocalSegm post, dev, None, - ) => (4, n, post, dev.unwrap_or(u64::MAX), local), + ) => (4, n, post, dev.unwrap_or(u64::MAX), version.local()), // final release - (None, None, None, None) => (5, 0, None, 0, local), + (None, None, None, None) => (5, 0, None, 0, version.local()), // post release - (None, Some(post), dev, None) => (6, 0, Some(post), dev.unwrap_or(u64::MAX), local), + (None, Some(post), dev, None) => { + (6, 0, Some(post), dev.unwrap_or(u64::MAX), version.local()) + } } } @@ -3775,38 +3762,6 @@ mod tests { ); } - // Ensure that the `.max` suffix plays nicely with dev versions. - let greater = Version::new([1, 0]).with_dev(Some(5)).with_max(Some(0)); - - let versions = &["1.dev5", "1.dev5+local"]; - - for less in versions.iter() { - let less = less.parse::().unwrap(); - assert_eq!( - less.cmp(&greater), - Ordering::Less, - "less: {:?}\ngreater: {:?}", - less.as_bloated_debug(), - greater.as_bloated_debug() - ); - } - - // Ensure that the `.max` suffix plays nicely with dev versions. - let less = Version::new([1, 0]).with_dev(Some(5)).with_max(Some(0)); - - let versions = &["1.post1.dev5", "1.0"]; - - for greater in versions.iter() { - let greater = greater.parse::().unwrap(); - assert_eq!( - less.cmp(&greater), - Ordering::Less, - "less: {:?}\ngreater: {:?}", - less.as_bloated_debug(), - greater.as_bloated_debug() - ); - } - // Ensure that the `.max` suffix plays nicely with pre-release versions. let greater = Version::new([1, 0]) .with_pre(Some(PreRelease {