Skip to content

Commit

Permalink
fix ^0.x and ^0.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jhheider committed Apr 8, 2023
1 parent 57b7228 commit 7d8ae45
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "semverator"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
Expand Down
11 changes: 9 additions & 2 deletions src/range/parse.rs
Expand Up @@ -52,8 +52,15 @@ impl<'a> Constraint<'a> {
return match cap.get(1).context("invalid character")?.as_str() {
"^" => {
let v1 = Semver::parse(cap.get(2).context("invalid description")?.as_str())?;
let v2 = Semver::parse(&format!("{}", v1.major + 1))?;
Ok(Constraint::Contiguous(v1, v2))
if v1.major > 0 {
let v2 = Semver::parse(&format!("{}", v1.major + 1))?;
return Ok(Constraint::Contiguous(v1, v2));
} else if v1.minor > 0 {
let v2 = Semver::parse(&format!("{}.{}", v1.major, v1.minor + 1))?;
return Ok(Constraint::Contiguous(v1, v2));
} else {
return Ok(Constraint::Single(v1));
}
}
"~" => {
let v1 = Semver::parse(cap.get(2).context("invalid description")?.as_str())?;
Expand Down
16 changes: 16 additions & 0 deletions src/tests/range.rs
Expand Up @@ -74,6 +74,22 @@ fn test_satisfies() -> Result<()> {
assert!(!rd.satisfies(&sa));
assert!(rd.satisfies(&sb));

let re = Range::parse("^0.1.0")?;

let se = Semver::parse("0.1.1")?;
let sf = Semver::parse("0.2.1")?;

assert!(re.satisfies(&se));
assert!(!re.satisfies(&sf));

let rg = Range::parse("^0.0.5")?;

let sg = Semver::parse("0.0.5")?;
let sh = Semver::parse("0.0.6")?;

assert!(rg.satisfies(&sg));
assert!(!rg.satisfies(&sh));

Ok(())
}

Expand Down

0 comments on commit 7d8ae45

Please sign in to comment.