Skip to content

Commit

Permalink
Merge pull request #8 from jhheider/fix-caret-0
Browse files Browse the repository at this point in the history
fix range ^0
  • Loading branch information
jhheider authored Jan 1, 2025
2 parents 6c254ee + f6b7951 commit 292a081
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
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.6.0"
version = "0.7.0"
edition = "2021"
license = "Apache-2.0"
readme = "../README.md"
Expand All @@ -13,7 +13,7 @@ categories = ["command-line-utilities"]
[dependencies]
anyhow = "1.0.75"
clap = { version = '4.4.2', features = ['cargo'] }
libsemverator = { path = "../lib", version = "0.6.0" }
libsemverator = { path = "../lib", version = "0.7.0" }

[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.6.0"
version = "0.7.0"
edition = "2021"
license = "Apache-2.0"
readme = "../README.md"
Expand Down
10 changes: 10 additions & 0 deletions lib/src/range/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ impl Constraint {
return Ok(Constraint::Contiguous(v1, v2));
}

// ^0 is a special case, in that it doesn't work like
// ^0.x or ^0.x.y, but rather like any other ^x
if constraint == "^0" {
return Ok(Constraint::Contiguous(
Semver::parse("0.0.0")?,
Semver::parse("1.0.0")?,
));
}

let re = Regex::new(r"^([~=<^])(.+)$")?;

if let Some(cap) = re.captures(constraint) {
return match cap.get(1).context("invalid character")?.as_str() {
"^" => {
Expand Down
10 changes: 10 additions & 0 deletions lib/src/tests/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ fn test_satisfies() -> Result<()> {
assert!(rg.satisfies(&sg));
assert!(!rg.satisfies(&sh));

let ri = Range::parse("^0")?;

let si = Semver::parse("0.0.5")?;
let sj = Semver::parse("0.21.1")?;
let sk = Semver::parse("1.0.0")?;

assert!(ri.satisfies(&si));
assert!(ri.satisfies(&sj));
assert!(!ri.satisfies(&sk));

Ok(())
}

Expand Down

0 comments on commit 292a081

Please sign in to comment.