Moved FailMode to its own file

This commit is contained in:
Kir_Antipov 2023-01-22 11:03:59 +00:00
parent 5a2e5f176c
commit 9ca1e9f0d9
2 changed files with 77 additions and 0 deletions

48
src/utils/fail-mode.ts Normal file
View file

@ -0,0 +1,48 @@
import { Enum, EnumOptions } from "@/utils/enum";
/**
* Represents different failure modes for handling errors.
*
* @partial
*/
enum FailModeValues {
/**
* Fail mode, halts the operation on encountering an error.
*/
FAIL,
/**
* Warn mode, logs a warning and continues operation on encountering an error.
*/
WARN,
/**
* Skip mode, skips the current operation and continues with the next one on encountering an error.
*/
SKIP,
}
/**
* Options for configuring the behavior of the `FailMode` enum.
*
* @partial
*/
const FailModeOptions: EnumOptions = {
/**
* The case should be ignored while parsing the fail mode.
*/
ignoreCase: true,
};
/**
* Represents different failure modes for handling errors.
*/
export const FailMode = Enum.create(
FailModeValues,
FailModeOptions,
);
/**
* Represents different failure modes for handling errors.
*/
export type FailMode = Enum<typeof FailModeValues>;

View file

@ -0,0 +1,29 @@
import { FailMode } from "@/utils/fail-mode";
describe("FailMode", () => {
describe("parse", () => {
test("parses all its own formatted values", () => {
for (const value of FailMode.values()) {
expect(FailMode.parse(FailMode.format(value))).toBe(value);
}
});
test("parses all friendly names of its own values", () => {
for (const value of FailMode.values()) {
expect(FailMode.parse(FailMode.friendlyNameOf(value))).toBe(value);
}
});
test("parses all its own formatted values in lowercase", () => {
for (const value of FailMode.values()) {
expect(FailMode.parse(FailMode.format(value).toLowerCase())).toBe(value);
}
});
test("parses all its own formatted values in UPPERCASE", () => {
for (const value of FailMode.values()) {
expect(FailMode.parse(FailMode.format(value).toUpperCase())).toBe(value);
}
});
});
});