From 917a5130f1913684ba56821a90dc2fa4ae3c8b96 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Tue, 7 Mar 2023 13:29:10 +0000 Subject: [PATCH] Made enum for every known loader --- src/loaders/loader-type.ts | 48 ++++++++++++++++++++++++++ tests/unit/loaders/loader-type.spec.ts | 29 ++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/loaders/loader-type.ts create mode 100644 tests/unit/loaders/loader-type.spec.ts diff --git a/src/loaders/loader-type.ts b/src/loaders/loader-type.ts new file mode 100644 index 0000000..8e9a16b --- /dev/null +++ b/src/loaders/loader-type.ts @@ -0,0 +1,48 @@ +import { Enum, EnumOptions } from "@/utils/enum"; + +/** + * Represents different mod loader types. + * + * @partial + */ +enum LoaderTypeValues { + /** + * Fabric mod loader. + */ + FABRIC = "fabric", + + /** + * Forge mod loader. + */ + FORGE = "forge", + + /** + * Quilt mod loader. + */ + QUILT = "quilt", +} + +/** + * Options for configuring the behavior of the `LoaderType` enum. + * + * @partial + */ +const LoaderTypeOptions: EnumOptions = { + /** + * The case should be ignored while parsing the mod loader type. + */ + ignoreCase: true, +}; + +/** + * Represents different mod loader types. + */ +export const LoaderType = Enum.create( + LoaderTypeValues, + LoaderTypeOptions, +); + +/** + * Represents different mod loader types. + */ +export type LoaderType = Enum; diff --git a/tests/unit/loaders/loader-type.spec.ts b/tests/unit/loaders/loader-type.spec.ts new file mode 100644 index 0000000..8ee894e --- /dev/null +++ b/tests/unit/loaders/loader-type.spec.ts @@ -0,0 +1,29 @@ +import { LoaderType } from "@/loaders/loader-type"; + +describe("LoaderType", () => { + describe("parse", () => { + test("parses all its own formatted values", () => { + for (const value of LoaderType.values()) { + expect(LoaderType.parse(LoaderType.format(value))).toBe(value); + } + }); + + test("parses all friendly names of its own values", () => { + for (const value of LoaderType.values()) { + expect(LoaderType.parse(LoaderType.friendlyNameOf(value))).toBe(value); + } + }); + + test("parses all its own formatted values in lowercase", () => { + for (const value of LoaderType.values()) { + expect(LoaderType.parse(LoaderType.format(value).toLowerCase())).toBe(value); + } + }); + + test("parses all its own formatted values in UPPERCASE", () => { + for (const value of LoaderType.values()) { + expect(LoaderType.parse(LoaderType.format(value).toUpperCase())).toBe(value); + } + }); + }); +});