public void Visit_ValueNode_ShouldReturnStringValue() { var visitor = new ScriptVisitor(context => 1); var resultingValue = "string value"; Assert.Equal(resultingValue, visitor.Visit(new ValueNode(resultingValue))); }
public void Visit_EqualIntToDecimal_ShouldReturnTrue() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode(5); var rightValue = new ValueNode((decimal)5); Assert.True((bool)visitor.Visit(new EqualNode(leftValue, rightValue))); }
public void Visit_AddFloatValueToDoubleValue_ShouldReturnTheResultAsDecimal() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode((float)4.2); var rightValue = new ValueNode(1.2); Assert.Equal((decimal)5.4, visitor.Visit(new AddNode(leftValue, rightValue))); }
public void Visit_EqualFloatToBool_ShouldReturnFalse() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode((float)5); var rightValue = new ValueNode(true); Assert.False((bool)visitor.Visit(new EqualNode(leftValue, rightValue))); }
public void Visit_DivideValueByZero_ShouldThrowException() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode(4); var rightValue = new ValueNode(0); Assert.Throws <InvalidOperationException>(() => visitor.Visit(new DivideNode(leftValue, rightValue))); }
public void Visit_MultiplyIntAndInt_ShouldRunIfInstructions() { var visitor = new ScriptVisitor(context => 1); var value1 = new ValueNode(2); var value2 = new ValueNode(3); Assert.Equal(6, visitor.Visit(new MultiplyNode(value1, value2))); }
public void Visit_AddStringValueToNullValue_ShouldReturnResult() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode("i="); var rightValue = new ValueNode(null); Assert.Equal("i=", visitor.Visit(new AddNode(leftValue, rightValue))); }
public void Visit_AddIntValueToStringValue_ShouldReturnTheResult() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode(4); var rightValue = new ValueNode("kg"); Assert.Equal("4kg", visitor.Visit(new AddNode(leftValue, rightValue))); }
public void Visit_DivideFloatValueToDoubleValue_ShouldReturnTheResultAsDecimal() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode((float)5); var rightValue = new ValueNode((double)2); Assert.Equal((decimal)2.5, visitor.Visit(new DivideNode(leftValue, rightValue))); }
public void Visit_AddIntValueToObject_ShouldThrowException() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode(4); var rightValue = new ValueNode(new object()); Assert.Throws <InvalidOperationException>(() => visitor.Visit(new AddNode(leftValue, rightValue))); }
public void Visit_AddIntValueToStringValue_ShouldReturnAStringWithBothValues() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode(4); var rightValue = new ValueNode("1"); Assert.Equal("41", visitor.Visit(new AddNode(leftValue, rightValue))); }
public void Visit_SubIntValueToStringValue_ShouldThrowException() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode(4); var rightValue = new ValueNode("1"); Assert.Throws <InvalidOperationException>(() => visitor.Visit(new SubNode(leftValue, rightValue))); }
public void Visit_SubFloatValueToIntValue_ShouldReturnTheResultAsDecimal() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode((float)4.2); var rightValue = new ValueNode(1); Assert.Equal((decimal)3.2, visitor.Visit(new SubNode(leftValue, rightValue))); }
public void Visit_SubIntValueToIntValue_ShouldReturnTheResult() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode(4); var rightValue = new ValueNode(2); Assert.Equal(2, visitor.Visit(new SubNode(leftValue, rightValue))); }
public void Visit_NotEqualFloatToDouble_ShouldReturnTrue() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode((float)5); var rightValue = new ValueNode((double)2); Assert.True((bool)visitor.Visit(new NotEqualNode(leftValue, rightValue))); }
public void Visit_NotEqualIntToInt_ShouldReturnTrue() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode(5); var rightValue = new ValueNode(5); Assert.False((bool)visitor.Visit(new NotEqualNode(leftValue, rightValue))); }
public void Visit_DivideFloatValueToStringValue_ShouldThrowExceptiopn() { var visitor = new ScriptVisitor(context => 1); var leftValue = new ValueNode((float)5); var rightValue = new ValueNode("2"); Assert.Throws <InvalidOperationException>(() => visitor.Visit(new DivideNode(leftValue, rightValue))); }
public void Visit_MultiplyFloatAndObject_ShouldThrowException() { var visitor = new ScriptVisitor(context => 0); var value1 = new ValueNode((float)5); var value2 = new ValueNode(new object()); Assert.Throws <InvalidOperationException>(() => visitor.Visit(new MultiplyNode(value1, value2))); }
public void Visit_MultiplyFloatAndDecimal_ShouldRunIfInstructions() { var visitor = new ScriptVisitor(context => 1); var value1 = new ValueNode((float)5); var value2 = new ValueNode((decimal)3.2); Assert.Equal((decimal)16, visitor.Visit(new MultiplyNode(value1, value2))); }
public void Visit_IfElseTrueIfPart_ShouldRunIfInstructions() { var resultValue = Guid.NewGuid().ToString(); var visitor = new ScriptVisitor(context => 1); var conditionInstr = new ValueNode(true); var ifInstr = new ValueNode(resultValue); var elseInstr = new ValueNode(false); Assert.Equal(resultValue, visitor.Visit(new IfElseNode(conditionInstr, ifInstr, elseInstr))); }
public void Visit_FunctionWithSpecificName_NameShouldBePassedToInvoker() { var functionName = "NameOfFunction"; var visitor = new ScriptVisitor(context => { Assert.Equal(functionName, context.Name); return(true); }); visitor.Visit(new FunctionNode(functionName, new List <IAstNode>())); }
public void Visit_FunctionThatReturnsInt_ShouldReturnExpectedValue() { var visitor = new ScriptVisitor(context => 1); Assert.Equal(1, visitor.Visit(new FunctionNode("function name", new List <IAstNode>()))); }