public void Multiple_Math() { var interpreter = new XzaarScriptInterpreter(); var expression = interpreter.CompileExpression("25 + 10 * 100") as LambdaXzaarCompiledScript; Assert.AreEqual("() => (25 + (10 * 100))", expression.GetLambdaExpression().ToString()); }
public void Multiple_Math_test_op_ordering_1() { var interpreter = new XzaarScriptInterpreter(); var expression = interpreter.CompileExpression("10 * 100 - 8 / 2 * 5") as LambdaXzaarCompiledScript; Assert.AreEqual("() => ((10 * 100) - ((8 / 2) * 5))", expression.GetLambdaExpression().ToString()); }
public void EmptyStatement() { var interpreter = new XzaarScriptInterpreter(); var expression = interpreter.CompileExpression("()") as LambdaXzaarCompiledScript; var lambdaExpression = expression.GetLambdaExpression(); Assert.AreEqual(null, lambdaExpression); }
public void AssignExpression_2() { var interpreter = new XzaarScriptInterpreter(); interpreter.RegisterVariable <int>("a"); var expression = interpreter.CompileExpression("a += 5 > 0") as LambdaXzaarCompiledScript; Assert.AreEqual("a => ((a = (a + 5)) > 0)", expression.GetLambdaExpression().ToString()); }
public void AssignExpression_decimal() { var interpreter = new XzaarScriptInterpreter(); interpreter.RegisterVariable <double>("a"); var expression = interpreter.CompileExpression("a = 1.01") as LambdaXzaarCompiledScript; Assert.AreEqual("a => (a = 1,01)", expression.GetLambdaExpression().ToString()); }
public void AssignExpression_strings_2() { var interpreter = new XzaarScriptInterpreter(); interpreter.RegisterVariable <string>("a"); var expression = interpreter.CompileExpression("a = '100'") as LambdaXzaarCompiledScript; Assert.AreEqual("a => (a = \"100\")", expression.GetLambdaExpression().ToString()); }
public void Interpreter_full_chain_complex_2() { var interpreter = new XzaarScriptInterpreter(); interpreter.RegisterVariable <int>("apa"); interpreter.RegisterVariable <int>("over"); var expression = interpreter.CompileExpression("apa == 8 || over == 9000 || apa == 24") as LambdaXzaarCompiledScript; Assert.AreEqual("(apa, over) => (((apa == 8) Or (over == 9000)) Or (apa == 24))", expression.GetLambdaExpression().ToString()); Assert.IsTrue(expression.Invoke <bool>(8, 0)); Assert.IsTrue(expression.Invoke <bool>(0, 9000)); Assert.IsTrue(expression.Invoke <bool>(24, 0)); Assert.IsFalse(expression.Invoke <bool>(0, 0)); }
public void Interpreter_full_chain_complex() { var interpreter = new XzaarScriptInterpreter( new KeyValuePair <string, Type>("apa", typeof(int)) ); var expression = interpreter.CompileExpression("((apa == 8) || (apa < (1 * 2))) || (apa >= 100)") as LambdaXzaarCompiledScript; var lambdaExpression = expression.GetLambdaExpression(); var actual = lambdaExpression.ToString(); Assert.AreEqual("apa => (((apa == 8) Or (apa < (1 * 2))) Or (apa >= 100))", actual); Assert.IsTrue(expression.Invoke <bool>(0)); Assert.IsTrue(expression.Invoke <bool>(8)); Assert.IsFalse(expression.Invoke <bool>(10)); Assert.IsTrue(expression.Invoke <bool>(100)); }