From e6ec53ad5afaf880bd8aaf07ccfb6568cdc8134c Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Wed, 1 Mar 2023 09:15:22 +0000 Subject: [PATCH] Added enum for Fabric environment types --- src/loaders/fabric/fabric-environment-type.ts | 44 +++++++++++++++++++ .../fabric/fabric-environment-type.spec.ts | 29 ++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/loaders/fabric/fabric-environment-type.ts create mode 100644 tests/unit/loaders/fabric/fabric-environment-type.spec.ts diff --git a/src/loaders/fabric/fabric-environment-type.ts b/src/loaders/fabric/fabric-environment-type.ts new file mode 100644 index 0000000..56f38a9 --- /dev/null +++ b/src/loaders/fabric/fabric-environment-type.ts @@ -0,0 +1,44 @@ +import { Enum, EnumOptions } from "@/utils/enum"; + +/** + * Represents the different environments that a Fabric mod can run on. + */ +enum FabricEnvironmentTypeValues { + /** + * Runs only on the client side. + */ + CLIENT = "client", + + /** + * Runs only on the server side. + */ + SERVER = "server", + + /** + * Runs on both the client and server side. + */ + BOTH = "*", +} + +/** + * Options for configuring the behavior of the `FabricEnvironmentType` enum. + */ +const FabricEnvironmentTypeOptions: EnumOptions = { + /** + * Ignore the case of the environment type string when parsing. + */ + ignoreCase: true, +}; + +/** + * Represents the different environments that a Fabric mod can run on. + */ +export const FabricEnvironmentType = Enum.create( + FabricEnvironmentTypeValues, + FabricEnvironmentTypeOptions, +); + +/** + * Represents the different environments that a Fabric mod can run on. + */ +export type FabricEnvironmentType = Enum; diff --git a/tests/unit/loaders/fabric/fabric-environment-type.spec.ts b/tests/unit/loaders/fabric/fabric-environment-type.spec.ts new file mode 100644 index 0000000..7afcadc --- /dev/null +++ b/tests/unit/loaders/fabric/fabric-environment-type.spec.ts @@ -0,0 +1,29 @@ +import { FabricEnvironmentType } from "@/loaders/fabric/fabric-environment-type"; + +describe("FabricEnvironmentType", () => { + describe("parse", () => { + test("parses all its own formatted values", () => { + for (const value of FabricEnvironmentType.values()) { + expect(FabricEnvironmentType.parse(FabricEnvironmentType.format(value))).toBe(value); + } + }); + + test("parses all friendly names of its own values", () => { + for (const value of FabricEnvironmentType.values()) { + expect(FabricEnvironmentType.parse(FabricEnvironmentType.friendlyNameOf(value))).toBe(value); + } + }); + + test("parses all its own formatted values in lowercase", () => { + for (const value of FabricEnvironmentType.values()) { + expect(FabricEnvironmentType.parse(FabricEnvironmentType.format(value).toLowerCase())).toBe(value); + } + }); + + test("parses all its own formatted values in UPPERCASE", () => { + for (const value of FabricEnvironmentType.values()) { + expect(FabricEnvironmentType.parse(FabricEnvironmentType.format(value).toUpperCase())).toBe(value); + } + }); + }); +});