Added enum for Quilt environment types

This commit is contained in:
Kir_Antipov 2023-03-16 18:01:33 +00:00
parent 8df878c5ba
commit 71525b9c9f
2 changed files with 78 additions and 0 deletions

View file

@ -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<typeof QuiltEnvironmentTypeValues>;

View file

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