public void ParseCast() { double x = 5.1; Expression<Func<int>> f = () => (int)x; var node = ExpressionParser.Parse(f.Body); var expected = new UnaryNode { Prefix = "(int)(", PrefixValue = "5", Operand = new ConstantNode(){Text = "x", Value = 5.1M.ToString()}, Suffix = ")" }; Assert.AreEqual(expected, node); }
public void ParseUnaryNegate() { var v = 5; Expression<Func<int>> f = () => -v; var node = ExpressionParser.Parse(f.Body); var expected = new UnaryNode { Prefix = "-", PrefixValue = "-5", Operand = new ConstantNode(){Text = "v", Value = "5"}, }; Assert.AreEqual(expected, node); }
public void ParseUnaryNot() { var v = true; Expression<Func<bool>> f = () => !v; var node = ExpressionParser.Parse(f.Body); var expected = new UnaryNode { Prefix = "!", PrefixValue = "False", Operand = new ConstantNode(){Text = "v", Value = "True"}, }; Assert.AreEqual(expected, node); }
public void ParseUnaryNotWrappingBinaryOperation() { var v = true; Expression<Func<bool>> f = () => !(v == false); var node = ExpressionParser.Parse(f.Body); var expected = new UnaryNode { Prefix = "!(", PrefixValue = "True", Operand = new BinaryNode { Left = new ConstantNode { Text = "v", Value = "True" }, Right = new ConstantNode { Text = "False", Value = null }, Operator = "==", Value = "False" }, Suffix = ")" }; Assert.AreEqual(expected, node); }