Improve script/category name validation

- Use better error messages with more context.
- Unify their validation logic and share tests.
- Validate also type of the name.
- Refactor node (Script/Category) parser tests for easier future
  changes and cleaner test code (using `TestBuilder` to do dirty work in
  unified way).
- Add more tests. Custom `Error` properties are compared manually due to
  `chai` not supporting deep equality checks (chaijs/chai#1065,
  chaijs/chai#1405).
This commit is contained in:
undergroundwires
2021-12-16 02:40:56 +01:00
parent 65902e5b72
commit b210aaddf2
17 changed files with 857 additions and 196 deletions

View File

@@ -1,16 +1,18 @@
export function itEachAbsentStringValue(runner: (absentValue: string) => void): void {
itEachTestCase(AbsentStringTestCases, runner);
itEachAbsentTestCase(AbsentStringTestCases, runner);
}
export function itEachAbsentObjectValue(runner: (absentValue: AbsentObjectType) => void): void {
itEachTestCase(AbsentObjectTestCases, runner);
export function itEachAbsentObjectValue(
runner: (absentValue: AbsentObjectType) => void,
): void {
itEachAbsentTestCase(AbsentObjectTestCases, runner);
}
export function itEachAbsentCollectionValue<T>(runner: (absentValue: []) => void): void {
itEachTestCase(getAbsentCollectionTestCases<T>(), runner);
itEachAbsentTestCase(getAbsentCollectionTestCases<T>(), runner);
}
function itEachTestCase<T>(
export function itEachAbsentTestCase<T>(
testCases: readonly IAbsentTestCase<T>[],
runner: (absentValue: T) => void,
): void {
@@ -53,8 +55,8 @@ export function getAbsentCollectionTestCases<T>(): readonly IAbsentCollectionCas
type AbsentObjectType = undefined | null;
interface IAbsentTestCase<T> {
valueName: string;
absentValue: T;
readonly valueName: string;
readonly absentValue: T;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface