- Unify test data for nonexistence of an object/string and collection. - Introduce more test through adding missing test data to existing tests. - Improve logic for checking absence of values to match tests. - Add missing tests for absent value validation. - Update documentation to include shared test functionality.
28 lines
921 B
TypeScript
28 lines
921 B
TypeScript
import { ISharedFunction } from './ISharedFunction';
|
|
import { ISharedFunctionCollection } from './ISharedFunctionCollection';
|
|
|
|
export class SharedFunctionCollection implements ISharedFunctionCollection {
|
|
private readonly functionsByName = new Map<string, ISharedFunction>();
|
|
|
|
public addFunction(func: ISharedFunction): void {
|
|
if (!func) { throw new Error('missing function'); }
|
|
if (this.has(func.name)) {
|
|
throw new Error(`function with name ${func.name} already exists`);
|
|
}
|
|
this.functionsByName.set(func.name, func);
|
|
}
|
|
|
|
public getFunctionByName(name: string): ISharedFunction {
|
|
if (!name) { throw Error('missing function name'); }
|
|
const func = this.functionsByName.get(name);
|
|
if (!func) {
|
|
throw new Error(`called function is not defined "${name}"`);
|
|
}
|
|
return func;
|
|
}
|
|
|
|
private has(functionName: string) {
|
|
return this.functionsByName.has(functionName);
|
|
}
|
|
}
|