public void FunctionCallFunction_UsingLocalReference_PassesCorrectFunctionNodeToFunctionFunction() { IntegerLiteralExpression functionLit = new IntegerLiteralExpression("1.0", 1, 1); List <ExpressionNode> funcParams = new List <ExpressionNode> { functionLit }; FunctionCallExpression funcCallExpr = new FunctionCallExpression("test", funcParams, 1, 1); funcCallExpr.LocalReference = 0; funcCallExpr.GlobalReferences = new List <int>(); IInterpreterGeneric parent = Substitute.For <IInterpreterGeneric>(); parent.Dispatch(funcParams[0], Arg.Any <List <object> >(), TypeEnum.Function).Returns((Object)1); GenericHelper functionHelper = SetUpHelper(parent); List <TypeNode> typeNodes = new List <TypeNode> { new TypeNode(TypeEnum.Function, 1, 1) }; FunctionTypeNode funcTypeNode = new FunctionTypeNode(null, typeNodes, 1, 1); FunctionNode funcNode = new FunctionNode("", null, null, funcTypeNode, 1, 1); AST ast = new AST(new List <FunctionNode> { funcNode }, null, 1, 1); functionHelper.SetASTRoot(ast); FunctionNode res = null; parent.Function <Function>(Arg.Do <FunctionNode>(x => res = x), Arg.Any <List <object> >()); functionHelper.FunctionCall <Function>(funcCallExpr, new List <object> { new Function(0) }); res.Should().BeEquivalentTo(funcNode); }
public void FunctionCallBoolean_GlobalRef_CorrectParameterTypes(int expectedElementCount, TypeEnum type) { int funcIndex = 0; var parameters = new List <object>(); var children = Utilities.GetIntLitExprNodes(expectedElementCount); var expr = new FunctionCallExpression("", children, 0, 0); expr.GlobalReferences.Add(funcIndex); var funcType = Utilities.GetFunctionTypeNode(expectedElementCount, type); var func = Utilities.GetFunction(funcType); AST ast = Utilities.GetAst(func); IInterpreterGeneric parent = Substitute.For <IInterpreterGeneric>(); var res = new List <object>(); parent.Function <bool>(Arg.Any <FunctionNode>(), Arg.Do <List <object> >(x => res = x)).Returns(false); parent.Dispatch(Arg.Any <ExpressionNode>(), Arg.Any <List <object> >(), Arg.Is <TypeEnum>(x => x == type)).Returns(1); GenericHelper booleanHelper = Utilities.GetGenericHelper(parent, ast); booleanHelper.FunctionCall <bool>(expr, parameters); foreach (var elem in res) { Assert.IsNotNull(elem); } }
public void FunctionCallBoolean_LocalRef_( int paramIndex, int paramCount, int funcIndex, int funcCount, bool expected) { var parameters = Utilities.GetParameterList(paramCount); parameters[paramIndex] = new Function(funcIndex); var children = new List <ExpressionNode>(); var expr = new FunctionCallExpression("", children, 0, 0); expr.LocalReference = paramIndex; AST ast = Utilities.GetAst(funcCount); var targetFunc = ast.Functions[funcIndex]; IInterpreterGeneric parent = Substitute.For <IInterpreterGeneric>(); parent.Function <bool>(targetFunc, Arg.Any <List <object> >()).Returns(expected); GenericHelper booleanHelper = Utilities.GetGenericHelper(parent, ast); bool res = booleanHelper.FunctionCall <bool>(expr, parameters); Assert.AreEqual(expected, res); }
public void FunctionCallFunction_f_f(Object[] numbers, TypeEnum[] types) { List <Object> expected = numbers.ToList(); List <TypeEnum> exTypes = types.ToList(); List <ExpressionNode> funcParams = new List <ExpressionNode>(); IInterpreterGeneric parent = Substitute.For <IInterpreterGeneric>(); List <TypeNode> typeNodes = new List <TypeNode>(); for (int i = 0; i < expected.Count; i++) { switch (expected[i]) { case int x: funcParams.Add(new IntegerLiteralExpression(x.ToString(), 1, 1)); break; case double x: funcParams.Add(new RealLiteralExpression(x.ToString(), 1, 1)); break; default: throw new Exception("Unexpected shit"); } parent.Dispatch(funcParams[i], Arg.Any <List <object> >(), exTypes[i]).Returns(expected[i]); typeNodes.Add(new TypeNode(exTypes[i], 1, 1)); } FunctionCallExpression funcCallExpr = new FunctionCallExpression("test", funcParams, 1, 1); funcCallExpr.GlobalReferences = new List <int> { 0 }; funcCallExpr.LocalReference = -1; GenericHelper functionHelper = SetUpHelper(parent); FunctionTypeNode funcTypeNode = new FunctionTypeNode(null, typeNodes, 1, 1); FunctionNode funcNode = new FunctionNode("", null, null, funcTypeNode, 1, 1); AST ast = new AST(new List <FunctionNode> { funcNode }, null, 1, 1); functionHelper.SetASTRoot(ast); List <object> res = new List <object>(); parent.Function <Function>(Arg.Any <FunctionNode>(), Arg.Do <List <object> >(x => res = x)); functionHelper.FunctionCall <Function>(funcCallExpr, new List <Object>()); res.Should().BeEquivalentTo(expected); }
public void FunctionCallBoolean_GlobalRef_ParameterCount(int expectedElementCount) { int funcIndex = 0; var parameters = new List <object>(); var children = Utilities.GetIntLitExprNodes(expectedElementCount); var expr = new FunctionCallExpression("", children, 0, 0); expr.GlobalReferences.Add(funcIndex); var funcType = Utilities.GetFunctionTypeNode(expectedElementCount, TypeEnum.Integer); var func = Utilities.GetFunction(funcType); AST ast = Utilities.GetAst(func); IInterpreterGeneric parent = Substitute.For <IInterpreterGeneric>(); var res = new List <object>(); parent.Function <bool>(Arg.Any <FunctionNode>(), Arg.Do <List <object> >(x => res = x)); GenericHelper booleanHelper = Utilities.GetGenericHelper(parent, ast); booleanHelper.FunctionCall <bool>(expr, parameters); Assert.AreEqual(expectedElementCount, res.Count); }