This commit applies `strictNullChecks` to the entire codebase to improve maintainability and type safety. Key changes include: - Remove some explicit null-checks where unnecessary. - Add necessary null-checks. - Refactor static factory functions for a more functional approach. - Improve some test names and contexts for better debugging. - Add unit tests for any additional logic introduced. - Refactor `createPositionFromRegexFullMatch` to its own function as the logic is reused. - Prefer `find` prefix on functions that may return `undefined` and `get` prefix for those that always return a value.
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { expect } from 'vitest';
|
|
import { Constructible } from '@/TypeHelpers';
|
|
import { ICodeValidationRule } from '@/application/Parser/Script/Validation/ICodeValidationRule';
|
|
import { ICodeValidator } from '@/application/Parser/Script/Validation/ICodeValidator';
|
|
|
|
export class CodeValidatorStub implements ICodeValidator {
|
|
public callHistory = new Array<{
|
|
code: string,
|
|
rules: readonly ICodeValidationRule[],
|
|
}>();
|
|
|
|
public throwIfInvalid(
|
|
code: string,
|
|
rules: readonly ICodeValidationRule[],
|
|
): void {
|
|
this.callHistory.push({
|
|
code,
|
|
rules: Array.from(rules),
|
|
});
|
|
}
|
|
|
|
public assertHistory(expected: {
|
|
validatedCodes: readonly (string | undefined)[],
|
|
rules: readonly Constructible<ICodeValidationRule>[],
|
|
}) {
|
|
expect(this.callHistory).to.have.lengthOf(expected.validatedCodes.length);
|
|
const actualValidatedCodes = this.callHistory.map((args) => args.code);
|
|
expect(actualValidatedCodes.sort()).deep.equal([...expected.validatedCodes].sort());
|
|
for (const call of this.callHistory) {
|
|
const actualRules = call.rules.map((rule) => rule.constructor);
|
|
expect(actualRules.sort()).to.deep.equal([...expected.rules].sort());
|
|
}
|
|
}
|
|
}
|