diff --git a/src/loaders/quilt/quilt-environment-type.ts b/src/loaders/quilt/quilt-environment-type.ts new file mode 100644 index 0000000..ce4feb1 --- /dev/null +++ b/src/loaders/quilt/quilt-environment-type.ts @@ -0,0 +1,49 @@ +import { Enum, EnumOptions } from "@/utils/enum"; + +/** + * Represents the different environments that a Quilt mod can run on. + */ +enum QuiltEnvironmentTypeValues { + /** + * The physical client. + */ + CLIENT = "client", + + /** + * The dedicated server. + */ + DEDICATED_SERVER = "dedicated_server", + + /** + * Runs on all environments. + */ + ALL = "*", +} + +/** + * Options for configuring the behavior of the `QuiltEnvironmentType` enum. + */ +const QuiltEnvironmentTypeOptions: EnumOptions = { + /** + * Ignore the case of the environment type string when parsing. + */ + ignoreCase: true, + + /** + * Non-word characters should be ignored while parsing the filter. + */ + ignoreNonWordCharacters: true, +}; + +/** + * Represents the different environments that a Quilt mod can run on. + */ +export const QuiltEnvironmentType = Enum.create( + QuiltEnvironmentTypeValues, + QuiltEnvironmentTypeOptions, +); + +/** + * Represents the different environments that a Quilt mod can run on. + */ +export type QuiltEnvironmentType = Enum; diff --git a/tests/unit/loaders/quilt/quilt-environment-type.spec.ts b/tests/unit/loaders/quilt/quilt-environment-type.spec.ts new file mode 100644 index 0000000..ca20d4f --- /dev/null +++ b/tests/unit/loaders/quilt/quilt-environment-type.spec.ts @@ -0,0 +1,29 @@ +import { QuiltEnvironmentType } from "@/loaders/quilt/quilt-environment-type"; + +describe("QuiltEnvironmentType", () => { + describe("parse", () => { + test("parses all its own formatted values", () => { + for (const value of QuiltEnvironmentType.values()) { + expect(QuiltEnvironmentType.parse(QuiltEnvironmentType.format(value))).toBe(value); + } + }); + + test("parses all friendly names of its own values", () => { + for (const value of QuiltEnvironmentType.values()) { + expect(QuiltEnvironmentType.parse(QuiltEnvironmentType.friendlyNameOf(value))).toBe(value); + } + }); + + test("parses all its own formatted values in lowercase", () => { + for (const value of QuiltEnvironmentType.values()) { + expect(QuiltEnvironmentType.parse(QuiltEnvironmentType.format(value).toLowerCase())).toBe(value); + } + }); + + test("parses all its own formatted values in UPPERCASE", () => { + for (const value of QuiltEnvironmentType.values()) { + expect(QuiltEnvironmentType.parse(QuiltEnvironmentType.format(value).toUpperCase())).toBe(value); + } + }); + }); +});