Added enum for Fabric environment types

This commit is contained in:
Kir_Antipov 2023-03-01 09:15:22 +00:00
parent beb1ecac69
commit e6ec53ad5a
2 changed files with 73 additions and 0 deletions

View file

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

View file

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