mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 00:11:02 -05:00
Made method that parses Minecraft version
...from version name
This commit is contained in:
parent
dc7721454f
commit
90929a7f48
2 changed files with 27 additions and 1 deletions
|
@ -127,6 +127,11 @@ export function parseVersionNameFromFileVersion(fileVersion: string): string | n
|
|||
}
|
||||
}
|
||||
|
||||
export function parseVersionName(version: string): string | null {
|
||||
const versionCandidates = [...(version.match(/\d+\.\d+(?:\.\d+)?/g) || [])];
|
||||
return versionCandidates.filter(x => x.startsWith("1."))[0] || null;
|
||||
}
|
||||
|
||||
export async function getLatestRelease(): Promise<MinecraftVersion | null> {
|
||||
return (await getVersions()).find(x => x.isRelease) || null;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { describe, test, expect } from "@jest/globals";
|
||||
import { getVersionById, findVersionByName, isSnapshot, parseVersionNameFromFileVersion, getVersions, getLatestRelease, getCompatibleBuilds } from "../src/utils/minecraft-utils";
|
||||
import { getVersionById, findVersionByName, isSnapshot, parseVersionName, parseVersionNameFromFileVersion, getVersions, getLatestRelease, getCompatibleBuilds } from "../src/utils/minecraft-utils";
|
||||
import Version from "../src/utils/version";
|
||||
|
||||
describe("getVersionById", () => {
|
||||
|
@ -78,6 +78,27 @@ describe("isSnapshot", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("parseVersionName", () => {
|
||||
test("Minecraft versions are parsed correctly", () => {
|
||||
expect(parseVersionName("1.17.1")).toStrictEqual("1.17.1");
|
||||
expect(parseVersionName("1.16.3")).toStrictEqual("1.16.3");
|
||||
expect(parseVersionName("1.17")).toStrictEqual("1.17");
|
||||
expect(parseVersionName("1.16")).toStrictEqual("1.16");
|
||||
});
|
||||
|
||||
test("weird formats that contain Minecraft version are parsed correctly", () => {
|
||||
expect(parseVersionName("1.17-5.0.1-beta+build.29")).toStrictEqual("1.17");
|
||||
expect(parseVersionName("[1.16.5, 1.17)")).toStrictEqual("1.16.5");
|
||||
expect(parseVersionName(">=1.17")).toStrictEqual("1.17");
|
||||
});
|
||||
|
||||
test("null is returned if version string does not contain Minecraft version", () => {
|
||||
expect(parseVersionName("5.0.8-beta+build.111")).toBeNull();
|
||||
expect(parseVersionName("5.3.3-BETA+ec3b0e5d")).toBeNull();
|
||||
expect(parseVersionName("2.0.12")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseVersionNameFromFileVersion", () => {
|
||||
test("Sodium-like versions are parsed correctly", () => {
|
||||
expect(parseVersionNameFromFileVersion("mc1.17.1-0.3.2+build.7")).toStrictEqual("1.17.1");
|
||||
|
|
Loading…
Reference in a new issue