allow functions to call other functions #53
This commit is contained in:
28
tests/unit/stubs/ExpressionsCompilerStub.ts
Normal file
28
tests/unit/stubs/ExpressionsCompilerStub.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { IExpressionsCompiler, ParameterValueDictionary } from '@/application/Parser/Script/Compiler/Expressions/IExpressionsCompiler';
|
||||
|
||||
interface Scenario { code: string; parameters: ParameterValueDictionary; result: string; }
|
||||
|
||||
export class ExpressionsCompilerStub implements IExpressionsCompiler {
|
||||
private readonly scenarios = new Array<Scenario>();
|
||||
public setup(code: string, parameters: ParameterValueDictionary, result: string) {
|
||||
this.scenarios.push({ code, parameters, result });
|
||||
return this;
|
||||
}
|
||||
public compileExpressions(code: string, parameters?: ParameterValueDictionary): string {
|
||||
const scenario = this.scenarios.find((s) => s.code === code && deepEqual(s.parameters, parameters));
|
||||
if (scenario) {
|
||||
return scenario.result;
|
||||
}
|
||||
return `[ExpressionsCompilerStub] code: "${code}"` +
|
||||
`| parameters: ${Object.keys(parameters || {}).map((p) => p + '=' + parameters[p]).join(',')}`;
|
||||
}
|
||||
}
|
||||
|
||||
function deepEqual(dict1: ParameterValueDictionary, dict2: ParameterValueDictionary) {
|
||||
const dict1Keys = Object.keys(dict1 || {});
|
||||
const dict2Keys = Object.keys(dict2 || {});
|
||||
if (dict1Keys.length !== dict2Keys.length) {
|
||||
return false;
|
||||
}
|
||||
return dict1Keys.every((key) => dict2.hasOwnProperty(key) && dict2[key] === dict1[key]);
|
||||
}
|
||||
Reference in New Issue
Block a user