Skip to content

Commit

Permalink
add Version.compare
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Feb 20, 2025
1 parent 4f019da commit 5433ad3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 29 deletions.
10 changes: 1 addition & 9 deletions js-rattler/crate/version.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::JsResult;
use rattler_conda_types::{Version, VersionBumpType};
use std::{cmp::Ordering, str::FromStr};
use std::str::FromStr;
use wasm_bindgen::prelude::wasm_bindgen;

#[wasm_bindgen]
Expand Down Expand Up @@ -130,12 +130,4 @@ impl JsVersion {
pub fn equals(&self, other: &Self) -> bool {
self.as_ref() == other.as_ref()
}

pub fn compare(&self, other: &Self) -> i8 {
match self.as_ref().cmp(other.as_ref()) {
Ordering::Less => -1,
Ordering::Equal => 0,
Ordering::Greater => 1,
}
}
}
5 changes: 2 additions & 3 deletions js-rattler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions js-rattler/src/Version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,4 @@ describe("Version", () => {
expect(new Version("1.2.3a").withAlpha().toString()).toBe("1.2.3a");
});
});

describe("compare", () => {
it("should compare version with expected order", () => {
expect(new Version("1.2.3").compare(new Version("1.2.3"))).toBe(0);
expect(new Version("1.2.0").compare(new Version("1.2.3"))).toBe(-1);
expect(new Version("1.2.4").compare(new Version("1.2.3"))).toBe(1);
});
});
});
9 changes: 0 additions & 9 deletions js-rattler/src/Version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,4 @@ export class Version {
public withAlpha(): Version {
return Version.fromNative(this.native.with_alpha());
}

/**
* Compare 2 versions.
*
* Returns `-1` if self<other, `0` if self == other, `1` if self > other
*/
public compare(other: Version): number {
return this.native.compare(other.native);
}
}

0 comments on commit 5433ad3

Please sign in to comment.