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

fix: revert VersionReq being equal on inner RangeSet #16

Closed
Closed
Changes from all commits
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
28 changes: 11 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,12 @@ impl RangeSetOrTag {
}

/// A version constraint.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct VersionReq {
raw_text: String,
inner: RangeSetOrTag,
}

impl PartialEq for VersionReq {
fn eq(&self, other: &Self) -> bool {
self.inner == other.inner
}
}

impl Eq for VersionReq {}

impl Hash for VersionReq {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.inner.hash(state);
}
}

impl VersionReq {
/// Creates a version requirement without examining the raw text.
pub fn from_raw_text_and_inner(
Expand All @@ -242,11 +228,17 @@ impl VersionReq {
npm::parse_npm_version_req(text)
}

/// The underlying `RangeSetOrTag`.
/// The underlying `RangeSetOrTag` which doesn't include the raw text.
pub fn inner(&self) -> &RangeSetOrTag {
&self.inner
}

/// Converts the `VersionReq` into the underlying `RangeSetOrTag`
/// which doesn't include the raw text.
pub fn into_inner(self) -> RangeSetOrTag {
self.inner
}

/// Gets if this version requirement overlaps another one.
pub fn intersects(&self, other: &VersionReq) -> bool {
self.inner.intersects(&other.inner)
Expand Down Expand Up @@ -353,6 +345,8 @@ mod test {
fn version_req_eq() {
let p1 = VersionReq::parse_from_specifier("1").unwrap();
let p2 = VersionReq::parse_from_specifier("1.x").unwrap();
assert_eq!(p1, p2);
// the inner RangeSetOrTag is equal, but not the underlying raw text
assert_ne!(p1, p2);
assert_eq!(p1.inner(), p2.inner());
}
}