Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore trailing .0 in version comparison #196

Merged
merged 5 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion crates/rattler_conda_types/src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,26 @@ impl Version {

impl PartialEq<Self> for Version {
fn eq(&self, other: &Self) -> bool {
baszalmstra marked this conversation as resolved.
Show resolved Hide resolved
self.version == other.version && self.local == other.local
for ranges in self
.version
.components
.iter()
.zip_longest(other.version.components.iter())
{
match ranges {
EitherOrBoth::Both(left, right) => {
if left != right {
return false;
}
}
EitherOrBoth::Left(el) | EitherOrBoth::Right(el) => {
if el != &NumeralOrOther::Numeral(0) {
return false;
}
}
}
}
self.local.components == other.local.components
}
}

Expand Down
15 changes: 15 additions & 0 deletions crates/rattler_conda_types/src/version_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ mod tests {
))
);
}

#[test]
fn test_group() {
assert_eq!(
Expand Down Expand Up @@ -300,4 +301,18 @@ mod tests {
))
);
}

#[test]
fn test_matches() {
let v1 = Version::from_str("1.2.0").unwrap();
let vs1 = VersionSpec::from_str(">=1.2.3,<2.0.0").unwrap();
assert!(!vs1.matches(&v1));

let vs2 = VersionSpec::from_str("1.2").unwrap();
assert!(vs2.matches(&v1));

let v2 = Version::from_str("1.2.3").unwrap();
assert!(vs1.matches(&v2));
assert!(!vs2.matches(&v2));
}
}