public void TestStore1() { IntA = 5; IntB = 9; MyTestObject = new TestClass(21); var backingStore = new PocoBackingStore(this); ExpressionParser e = new ExpressionParser(); var compiledExpression = e.Parse("(IntA + IntB) * MyTestObject.TestInt"); int expectedResult = (IntA + IntB) * MyTestObject.TestInt; var evalResult = compiledExpression.Evaluate(backingStore); Assert.AreEqual(1, evalResult.Count); var actualResult = (int)evalResult.Pop().GetValue(); Assert.AreEqual(expectedResult, actualResult); IntA++; IntB++; MyTestObject.TestInt++; expectedResult = (IntA + IntB) * MyTestObject.TestInt; evalResult = compiledExpression.Evaluate(backingStore); Assert.AreEqual(1, evalResult.Count); actualResult = (int)evalResult.Pop().GetValue(); Assert.AreEqual(expectedResult, actualResult); }
public void TestBoolOrBoolNoShortCircuit() { ExpressionParser e = new ExpressionParser(); var backingStore = new PocoBackingStore(this); var compiledExpression = e.Parse("false || true"); var evalResult = compiledExpression.Evaluate(backingStore); Assert.AreEqual(1, evalResult.Count); Assert.AreEqual(true, (bool)evalResult.Pop().GetValue()); }
public void TestBoolVariableAndBoolShortCircuit() { ExpressionParser e = new ExpressionParser(); var backingStore = new PocoBackingStore(this); TestBool = false; var compiledExpression = e.Parse("TestBool && true"); var evalResult = compiledExpression.Evaluate(backingStore); Assert.AreEqual(1, evalResult.Count); Assert.AreEqual(false, (bool)evalResult.Pop().GetValue()); }
public void TestStoreNew() { IntA = 5; LongC = 9; var backingStore = new PocoBackingStore(this); ExpressionParser e = new ExpressionParser(); var compiledExpression = e.Parse("LongC = IntA"); //LongC = IntA; var evalResult = compiledExpression.Evaluate(backingStore); Assert.AreEqual(IntA, LongC); Assert.AreEqual(IntA, 5); Assert.AreEqual(1, evalResult.Count); }
public void TestStore3() { IntA = 5; IntB = 9; MyTestObject = new TestClass(21); var backingStore = new PocoBackingStore(this); ExpressionParser e = new ExpressionParser(); var compiledExpression = e.Parse("MyTestObject.TestInt = IntA"); var evalResult = compiledExpression.Evaluate(backingStore); Assert.AreEqual(1, evalResult.Count); Assert.AreEqual(MyTestObject.TestInt, IntA); Assert.AreEqual(IntA, 5); var actualResult = (int)evalResult.Pop().GetValue(); Assert.AreEqual(5, actualResult); }
public void TestStore6() { try { IntA = 5; IntB = 9; MyTestObject = new TestClass(21); var backingStore = new PocoBackingStore(this); ExpressionParser e = new ExpressionParser(); var compiledExpression = e.Parse("IntB_ROKEN = MyTestObject.TestInt"); var evalResult = compiledExpression.Evaluate(backingStore); throw new Exception("Broken"); } catch (ExpressionEvaluatorException eeex) { Assert.AreEqual(eeex.Cause, ExpressionEvaluatorException.ExceptionCause.UndefinedVariable); Assert.AreEqual(eeex.Message, "'IntB_ROKEN'"); } }