Files
privacy.sexy/tests/unit/stubs/FunctionCallCompilerStub.ts
undergroundwires 60c80611ea add module alias '@tests/'
Alias would remove unnecessary repetitions and less relative paths make changes easier when moving around files. This commit cleans also up some relative paths ('../../../') by using the alias and orders imports. It updates both path alias in tsconfig and module alias in Vue CLI's bundler (vuejs/vue-cli#2398).
2021-04-15 18:34:40 +02:00

27 lines
1.3 KiB
TypeScript

import { ISharedFunctionCollection } from '@/application/Parser/Script/Compiler/Function/ISharedFunctionCollection';
import { ICompiledCode } from '@/application/Parser/Script/Compiler/FunctionCall/ICompiledCode';
import { IFunctionCallCompiler } from '@/application/Parser/Script/Compiler/FunctionCall/IFunctionCallCompiler';
import { FunctionCallData, ScriptFunctionCallData } from 'js-yaml-loader!@/*';
interface Scenario { call: ScriptFunctionCallData; functions: ISharedFunctionCollection; result: ICompiledCode; }
export class FunctionCallCompilerStub implements IFunctionCallCompiler {
public scenarios = new Array<Scenario>();
public setup(call: ScriptFunctionCallData, functions: ISharedFunctionCollection, result: ICompiledCode) {
this.scenarios.push({ call, functions, result });
}
public compileCall(
call: ScriptFunctionCallData,
functions: ISharedFunctionCollection): ICompiledCode {
const predefined = this.scenarios.find((s) => s.call === call && s.functions === functions);
if (predefined) {
return predefined.result;
}
const callee = functions.getFunctionByName((call as FunctionCallData).function);
return {
code: callee.code,
revertCode: callee.revertCode,
};
}
}