-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
refactor(semver): clean up parseRange
, add missing tests
#6362
Changes from all commits
1383839
0b3ba59
6e447bc
06d2250
c05d863
67fe705
4fa8705
4b7ecbf
fb67093
2f6fec2
0f47239
ab02c95
6ed9efb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Copyright 2018-2025 the Deno authors. MIT license. | ||
// Copyright Isaac Z. Schlueter and npm contributors. All rights reserved. ISC license. | ||
|
||
import { assert, assertFalse } from "@std/assert"; | ||
import { assert, assertEquals, assertFalse } from "@std/assert"; | ||
import { | ||
format, | ||
formatRange, | ||
|
@@ -169,3 +169,23 @@ Deno.test("lessThanRange() checks if the SemVer is less than the range", async ( | |
}); | ||
} | ||
}); | ||
|
||
Deno.test("lessThanRange() handles not equals operator", () => { | ||
const version = { | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
prerelease: [], | ||
build: [], | ||
}; | ||
const range = [[{ | ||
operator: "!=" as const, | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
prerelease: [], | ||
build: [], | ||
}]]; | ||
// FIXME(kt3k): This demonstrates a bug. This should be false | ||
assertEquals(lessThanRange(version, range), true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This result feels wrong to me. I'd suggest skipping this test case for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should not skip test cases if they yield unexpected results but fix them instead. What would the proper result be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The range There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to create a PR to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That will be a breaking change and we currently don't have a plan for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this bug could be fixed by modifying the |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2018-2025 the Deno authors. MIT license. | ||
|
||
import { assertEquals } from "@std/assert"; | ||
import { tryParseRange } from "./try_parse_range.ts"; | ||
import type { Range } from "./types.ts"; | ||
|
||
Deno.test("tryParseRange()", () => { | ||
const actual = tryParseRange(">=1.2.3 <1.2.4"); | ||
const expected: Range = [ | ||
[ | ||
{ | ||
operator: ">=", | ||
major: 1, | ||
minor: 2, | ||
patch: 3, | ||
prerelease: [], | ||
build: [], | ||
}, | ||
{ | ||
operator: "<", | ||
major: 1, | ||
minor: 2, | ||
patch: 4, | ||
prerelease: [], | ||
build: [], | ||
}, | ||
], | ||
]; | ||
assertEquals(actual, expected); | ||
}); | ||
|
||
Deno.test("tryParseRange() handles invalid range", () => { | ||
assertEquals(tryParseRange("blerg"), undefined); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case looks comparing invalid semvers. I don't think this is an intentional behavior, but an undefined behavior. I'd suggest we should remove this test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is undefined behavior we probably should remove
if (a === undefined && b === undefined) return 0;
fromcompareIdentifier()
as this is specifically handled there.