public void TestGetParametersNone() { var functionDefinition = new FunctionDefinitionExpression("f"); var scope = new InterpreterScope(); var functionCall = new FunctionCallExpression("f", new ExpressionBase[0]); ExpressionBase error; var innerScope = functionCall.GetParameters(functionDefinition, scope, out error); Assert.That(innerScope, Is.Not.Null); Assert.That(error, Is.Null); Assert.That(innerScope.VariableCount, Is.EqualTo(0)); }
public void TestGetParametersByIndexTooMany() { var functionDefinition = Parse("function func(i,j) { }"); var scope = new InterpreterScope(); var value1 = new IntegerConstantExpression(6); var functionCall = new FunctionCallExpression("func", new ExpressionBase[] { value1, value1, value1 }); ExpressionBase error; var innerScope = functionCall.GetParameters(functionDefinition, scope, out error); Assert.That(innerScope, Is.Null); Assert.That(error, Is.Not.Null); var parseError = (ParseErrorExpression)error; Assert.That(parseError.Message, Is.EqualTo("Too many parameters passed to function")); }
public void TestGetParametersByIndex() { var functionDefinition = Parse("function func(i,j) { }"); var scope = new InterpreterScope(); var value1 = new IntegerConstantExpression(6); var value2 = new StringConstantExpression("a"); var functionCall = new FunctionCallExpression("func", new ExpressionBase[] { value1, value2 }); ExpressionBase error; var innerScope = functionCall.GetParameters(functionDefinition, scope, out error); Assert.That(innerScope, Is.Not.Null); Assert.That(error, Is.Null); Assert.That(innerScope.VariableCount, Is.EqualTo(2)); Assert.That(innerScope.GetVariable("i"), Is.EqualTo(value1)); Assert.That(innerScope.GetVariable("j"), Is.EqualTo(value2)); }
public void TestGetParametersByNameRepeated() { var functionDefinition = Parse("function func(i,j) { }"); var scope = new InterpreterScope(); var value2 = new StringConstantExpression("a"); var assign2 = new AssignmentExpression(new VariableExpression("i"), value2); var functionCall = new FunctionCallExpression("func", new ExpressionBase[] { assign2, assign2 }); ExpressionBase error; var innerScope = functionCall.GetParameters(functionDefinition, scope, out error); Assert.That(innerScope, Is.Null); Assert.That(error, Is.Not.Null); var parseError = (ParseErrorExpression)error; Assert.That(parseError.Message, Is.EqualTo("'i' already has a value")); }
public void TestGetParametersByIndexUnknownVariable() { var functionDefinition = Parse("function func(i) { }"); var scope = new InterpreterScope(); var value1 = new VariableExpression("var"); var functionCall = new FunctionCallExpression("func", new ExpressionBase[] { value1 }); ExpressionBase error; var innerScope = functionCall.GetParameters(functionDefinition, scope, out error); Assert.That(innerScope, Is.Not.Null); Assert.That(error, Is.Not.Null); var parseError = (ParseErrorExpression)error; Assert.That(parseError.Message, Is.EqualTo("Invalid value for parameter: i")); Assert.That(parseError.InnermostError.Message, Is.EqualTo("Unknown variable: var")); }
public void TestGetParametersByNameBeforeIndex() { var functionDefinition = Parse("function func(i,j) { }"); var scope = new InterpreterScope(); var value1 = new IntegerConstantExpression(6); var value2 = new StringConstantExpression("a"); var assign1 = new AssignmentExpression(new VariableExpression("i"), value1); var functionCall = new FunctionCallExpression("func", new ExpressionBase[] { assign1, value2 }); ExpressionBase error; var innerScope = functionCall.GetParameters(functionDefinition, scope, out error); Assert.That(innerScope, Is.Null); Assert.That(error, Is.Not.Null); var parseError = (ParseErrorExpression)error; Assert.That(parseError.Message, Is.EqualTo("Non-named parameter following named parameter")); }