mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-25 01:41:05 -05:00
parent
0a3874adee
commit
6e1bcb10b6
2 changed files with 69 additions and 1 deletions
|
@ -122,7 +122,7 @@ function intervalToSemver(range: string): string {
|
|||
/**
|
||||
* Regular expression for matching semver-like tags in version strings with optional patch version.
|
||||
*/
|
||||
const SEMVER_OPTIONAL_PATCH_REGEX = /(\d+\.\d+)(\.\d+|\.[Xx])?([\w\-.+]*)/g;
|
||||
const SEMVER_OPTIONAL_PATCH_REGEX = /((?:\d+|[Xx*])(?:\.\d+|\.[Xx*]))(\.\d+|\.[Xx*])?([\w\-.+]*)/g;
|
||||
|
||||
/**
|
||||
* Ensures that a semver string has a patch version, adding ".0" if it is missing.
|
||||
|
|
|
@ -20,6 +20,40 @@ describe("parseVersionRange", () => {
|
|||
expect(versionRange.includes("2.0.1")).toBe(false);
|
||||
});
|
||||
|
||||
test("parses a semver string with X-ranges correctly", () => {
|
||||
const versionRange = parseVersionRange(">=1.2.x <2.0.X");
|
||||
|
||||
expect(versionRange).toBeDefined();
|
||||
expect(versionRange.toString()).toBe(">=1.2.x <2.0.X");
|
||||
|
||||
expect(versionRange.includes("1.2.0")).toBe(true);
|
||||
expect(versionRange.includes("1.2.1")).toBe(true);
|
||||
expect(versionRange.includes("1.2.2")).toBe(true);
|
||||
expect(versionRange.includes("1.2.3")).toBe(true);
|
||||
expect(versionRange.includes("1.2.4")).toBe(true);
|
||||
expect(versionRange.includes("1.9999.9999")).toBe(true);
|
||||
expect(versionRange.includes("2.0.0")).toBe(false);
|
||||
expect(versionRange.includes("1.0.0")).toBe(false);
|
||||
expect(versionRange.includes("2.0.1")).toBe(false);
|
||||
});
|
||||
|
||||
test("parses a semver string with *-ranges correctly", () => {
|
||||
const versionRange = parseVersionRange(">=1.2.* <2.0.*");
|
||||
|
||||
expect(versionRange).toBeDefined();
|
||||
expect(versionRange.toString()).toBe(">=1.2.* <2.0.*");
|
||||
|
||||
expect(versionRange.includes("1.2.0")).toBe(true);
|
||||
expect(versionRange.includes("1.2.1")).toBe(true);
|
||||
expect(versionRange.includes("1.2.2")).toBe(true);
|
||||
expect(versionRange.includes("1.2.3")).toBe(true);
|
||||
expect(versionRange.includes("1.2.4")).toBe(true);
|
||||
expect(versionRange.includes("1.9999.9999")).toBe(true);
|
||||
expect(versionRange.includes("2.0.0")).toBe(false);
|
||||
expect(versionRange.includes("1.0.0")).toBe(false);
|
||||
expect(versionRange.includes("2.0.1")).toBe(false);
|
||||
});
|
||||
|
||||
test("parses an interval notation string correctly", () => {
|
||||
const versionRange = parseVersionRange("[1.2.3,2.0.0)");
|
||||
|
||||
|
@ -35,6 +69,40 @@ describe("parseVersionRange", () => {
|
|||
expect(versionRange.includes("2.0.1")).toBe(false);
|
||||
});
|
||||
|
||||
test("parses an interval notation string with X-ranges correctly", () => {
|
||||
const versionRange = parseVersionRange("[1.2.x,2.0.X)");
|
||||
|
||||
expect(versionRange).toBeDefined();
|
||||
expect(versionRange.toString()).toBe("[1.2.x,2.0.X)");
|
||||
|
||||
expect(versionRange.includes("1.2.0")).toBe(true);
|
||||
expect(versionRange.includes("1.2.1")).toBe(true);
|
||||
expect(versionRange.includes("1.2.2")).toBe(true);
|
||||
expect(versionRange.includes("1.2.3")).toBe(true);
|
||||
expect(versionRange.includes("1.2.4")).toBe(true);
|
||||
expect(versionRange.includes("1.9999.9999")).toBe(true);
|
||||
expect(versionRange.includes("2.0.0")).toBe(false);
|
||||
expect(versionRange.includes("1.0.0")).toBe(false);
|
||||
expect(versionRange.includes("2.0.1")).toBe(false);
|
||||
});
|
||||
|
||||
test("parses an interval notation string with *-ranges correctly", () => {
|
||||
const versionRange = parseVersionRange("[1.2.*,2.0.*)");
|
||||
|
||||
expect(versionRange).toBeDefined();
|
||||
expect(versionRange.toString()).toBe("[1.2.*,2.0.*)");
|
||||
|
||||
expect(versionRange.includes("1.2.0")).toBe(true);
|
||||
expect(versionRange.includes("1.2.1")).toBe(true);
|
||||
expect(versionRange.includes("1.2.2")).toBe(true);
|
||||
expect(versionRange.includes("1.2.3")).toBe(true);
|
||||
expect(versionRange.includes("1.2.4")).toBe(true);
|
||||
expect(versionRange.includes("1.9999.9999")).toBe(true);
|
||||
expect(versionRange.includes("2.0.0")).toBe(false);
|
||||
expect(versionRange.includes("1.0.0")).toBe(false);
|
||||
expect(versionRange.includes("2.0.1")).toBe(false);
|
||||
});
|
||||
|
||||
test("parses a string that mixes semver and interval notation correctly", () => {
|
||||
const versionRange = parseVersionRange(">=1.2.3 <2.0.0 || [2.0.0,3.0.0)");
|
||||
|
||||
|
|
Loading…
Reference in a new issue