import { ICompiledCode } from '@/application/Parser/Script/Compiler/Function/Call/Compiler/ICompiledCode' ; import { IFunctionCallCompiler } from '@/application/Parser/Script/Compiler/Function/Call/Compiler/IFunctionCallCompiler' ; import { ISharedFunctionCollection } from '@/application/Parser/Script/Compiler/Function/ISharedFunctionCollection' ; import { IFunctionCall } from '@/application/Parser/Script/Compiler/Function/Call/IFunctionCall' ; interface IScenario { calls : IFunctionCall [ ] ; functions : ISharedFunctionCollection ; result : ICompiledCode ; } export class FunctionCallCompilerStub implements IFunctionCallCompiler { public scenarios = new Array < IScenario > ( ) ; public setup ( calls , functions , result ) { this . scenarios . push ( { calls , functions , result } ) ; } public compileCall ( calls , functions ) { const predefined = this . scenarios . find ( ( s ) => areEqual ( s . calls , calls ) && s . functions === functions ) ; if ( predefined ) { return predefined . result ; } return { code : 'function code [FunctionCallCompilerStub]' , revertCode : 'function revert code [FunctionCallCompilerStub]' , } ; } } function areEqual ( first , second ) { const comparer = ( a , b ) => a . functionName . localeCompare ( b . functionName ) ; const printSorted = ( calls ) => JSON . stringify ( [ ... calls ] . sort ( comparer ) ) ; return printSorted ( first ) === printSorted ( second ) ; }