Files
privacy.sexy/tests/unit/shared/Stubs/FunctionCallArgumentCollectionStub.ts
undergroundwires c138f74460 Refactor to unify scripts/categories as Executable
This commit consolidates scripts and categories under a unified
'Executable' concept. This simplifies the architecture and improves code
readability.

- Introduce subfolders within `src/domain` to segregate domain elements.
- Update class and interface names by removing the 'I' prefix in
  alignment with new coding standards.
- Replace 'Node' with 'Executable' to clarify usage; reserve 'Node'
  exclusively for the UI's tree component.
2024-06-12 12:36:40 +02:00

55 lines
1.9 KiB
TypeScript

import type { IFunctionCallArgument } from '@/application/Parser/Executable/Script/Compiler/Function/Call/Argument/IFunctionCallArgument';
import type { IFunctionCallArgumentCollection } from '@/application/Parser/Executable/Script/Compiler/Function/Call/Argument/IFunctionCallArgumentCollection';
import { FunctionCallArgumentStub } from './FunctionCallArgumentStub';
export class FunctionCallArgumentCollectionStub implements IFunctionCallArgumentCollection {
private args = new Array<IFunctionCallArgument>();
public withEmptyArguments(): this {
this.args.length = 0;
return this;
}
public withSomeArguments(): this {
return this
.withArgument('firstTestParameterName', 'first-parameter-argument-value')
.withArgument('secondTestParameterName', 'second-parameter-argument-value')
.withArgument('thirdTestParameterName', 'third-parameter-argument-value');
}
public withArgument(parameterName: string, argumentValue: string): this {
const arg = new FunctionCallArgumentStub()
.withParameterName(parameterName)
.withArgumentValue(argumentValue);
this.addArgument(arg);
return this;
}
public withArguments(args: { readonly [index: string]: string }): this {
for (const [name, value] of Object.entries(args)) {
this.withArgument(name, value);
}
return this;
}
public hasArgument(parameterName: string): boolean {
return this.args.some((a) => a.parameterName === parameterName);
}
public addArgument(argument: IFunctionCallArgument): void {
this.args.push(argument);
}
public getAllParameterNames(): string[] {
return this.args.map((a) => a.parameterName);
}
public getArgument(parameterName: string): IFunctionCallArgument {
const arg = this.args.find((a) => a.parameterName === parameterName);
if (!arg) {
throw new Error(`no argument exists for parameter "${parameterName}"`);
}
return arg;
}
}