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); + } + }); + }); +});