Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**/target
coverage/
.idea
.envrc
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "semverator"
version = "0.10.0"
version = "0.10.1"
edition = "2021"
license = "Apache-2.0"
readme = "../README.md"
Expand All @@ -13,7 +13,7 @@ categories = ["command-line-utilities"]
[dependencies]
anyhow = "1.0.98"
clap = { version = '4.5.40', features = ['cargo'] }
libsemverator = { path = "../lib", version = "0.10.0" }
libsemverator = { path = "../lib", version = "0.10.1" }

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(tarpaulin_include)'] }
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libsemverator"
version = "0.10.0"
version = "0.10.1"
edition = "2021"
license = "Apache-2.0"
readme = "../README.md"
Expand Down
11 changes: 9 additions & 2 deletions lib/src/range/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ lazy_static! {
static ref CONSTRAINT_REGEX_RANGE: Regex =
Regex::new(r"^>=((\d+\.)*\d+)\s*(<((\d+\.)*\d+))?$").unwrap();
static ref CONSTRAINT_REGEX_SIMPLE: Regex = Regex::new(r"^([~=<^@])(.+)$").unwrap();
static ref INFINITIES_REGEX: Regex = Regex::new(r"<Infinity(\.Infinity)+").unwrap();
}

impl Range {
pub fn parse(range: &str) -> Result<Self> {
// Ignore `<Infinity.Infinity.Infinity`. Fixes https://github.com/pkgxdev/pkgx/issues/1190
let range = if INFINITIES_REGEX.is_match(range) {
&INFINITIES_REGEX.replace(range, "").to_string()
} else {
range
};
let raw = range.to_string();
let mut set = Vec::new();

Expand Down Expand Up @@ -148,9 +155,9 @@ impl Constraint {
"=" => Ok(Constraint::Single(Semver::parse(
cap.get(2).context("invalid description")?.as_str(),
)?)),
_ => unreachable!("invalid range description"),
_ => unreachable!("invalid range description: {}", constraint),
};
}
bail!("invalid range description")
bail!("invalid range description: {}", constraint)
}
}
16 changes: 16 additions & 0 deletions lib/src/tests/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ fn test_intersect() -> Result<()> {
assert!(il.is_ok());
assert_eq!(il?.raw, rg.raw);

// This is the test for https://github.com/pkgxdev/pkgx/issues/1190
let rn = Range::any();
let ro = Range::parse(">=5.0.0<Infinity.Infinity.Infinity")?;

let im = rn.intersect(&ro);
assert!(im.is_ok());
assert_eq!(im?.raw, ro.raw);

let r#in = ro.intersect(&rn);
assert!(r#in.is_ok());
assert_eq!(r#in?.raw, ro.raw);

Ok(())
}

Expand Down Expand Up @@ -278,6 +290,10 @@ fn test_display() -> Result<()> {
assert_eq!(ri.to_string(), ">=0.1.1");
assert_eq!(rj.to_string(), ">=0.1.1<3");

// This is the test for https://github.com/pkgxdev/pkgx/issues/1190
let rk = Range::parse(">=5.0.0<Infinity.Infinity.Infinity")?;
assert_eq!(rk.to_string(), ">=5");

Ok(())
}

Expand Down