Files
privacy.sexy/tests/unit/shared/Stubs/SingleCallCompilerStub.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

48 lines
1.8 KiB
TypeScript

import type { CompiledCode } from '@/application/Parser/Executable/Script/Compiler/Function/Call/Compiler/CompiledCode';
import type { FunctionCallCompilationContext } from '@/application/Parser/Executable/Script/Compiler/Function/Call/Compiler/FunctionCallCompilationContext';
import type { SingleCallCompiler } from '@/application/Parser/Executable/Script/Compiler/Function/Call/Compiler/SingleCall/SingleCallCompiler';
import type { FunctionCall } from '@/application/Parser/Executable/Script/Compiler/Function/Call/FunctionCall';
import { StubWithObservableMethodCalls } from './StubWithObservableMethodCalls';
import { CompiledCodeStub } from './CompiledCodeStub';
interface CallCompilationScenario {
readonly givenCall: FunctionCall;
readonly result: CompiledCode[];
}
export class SingleCallCompilerStub
extends StubWithObservableMethodCalls<SingleCallCompiler>
implements SingleCallCompiler {
private readonly callCompilationScenarios = new Array<CallCompilationScenario>();
public withCallCompilationScenarios(scenarios: Map<FunctionCall, CompiledCode[]>): this {
for (const [call, result] of scenarios) {
this.withCallCompilationScenario({
givenCall: call,
result,
});
}
return this;
}
public withCallCompilationScenario(scenario: CallCompilationScenario): this {
this.callCompilationScenarios.push(scenario);
return this;
}
public compileSingleCall(
call: FunctionCall,
context: FunctionCallCompilationContext,
): CompiledCode[] {
this.registerMethodCall({
methodName: 'compileSingleCall',
args: [call, context],
});
const callCompilation = this.callCompilationScenarios.find((s) => s.givenCall === call);
if (callCompilation) {
return callCompilation.result;
}
return [new CompiledCodeStub()];
}
}