Skip to content

Commit

Permalink
fix >=0.47<1 toStringing to ~0.47
Browse files Browse the repository at this point in the history
  • Loading branch information
jhheider authored and mxcl committed Apr 16, 2023
1 parent 96e65a8 commit f7e0374
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class Range {
return this.set.map(v => {
if (!isArray(v)) return `=${v.toString()}`
const [v1, v2] = v
if (v2.major == v1.major + 1 && v2.minor == 0 && v2.patch == 0) {
if (v1.major > 0 && v2.major == v1.major + 1 && v2.minor == 0 && v2.patch == 0) {
const v = chomp(v1)
return `^${v}`
} else if (v2.major == v1.major && v2.minor == v1.minor + 1 && v2.patch == 0) {
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/semver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ Deno.test("semver", async test => {
assert(b.satisfies(new SemVer("12.9.0")))
})

await test.step(">=0.47<1", () => {
const a = new semver.Range(">=0.47<1")
assertEquals(a.toString(), ">=0.47<1")
assert(a.satisfies(new SemVer("0.47.0")))
assert(a.satisfies(new SemVer("0.47.9")))
assert(a.satisfies(new SemVer("0.48.0")))
assert(a.satisfies(new SemVer("0.80.0")))
assertFalse(a.satisfies(new SemVer("1.0.0")))
})

//FIXME this *should* work
// await test.step("^11,^12…^11.3,^12.2", () => {
// const a = new semver.Range("^11,^12")
Expand Down

0 comments on commit f7e0374

Please sign in to comment.