public void ParseBinaryWithNullRightHandSide() { string rightHandSide = null; Expression<Func<bool>> f = () => "foo" == rightHandSide; var node = ExpressionParser.Parse(f.Body); var expected = new BinaryNode { Left = new ConstantNode { Text = "\"foo\"" }, Right = new ConstantNode { Text = "rightHandSide", Value = "null" }, Operator = "==", Value = "False" }; Assert.AreEqual(expected, node); }
public void ParseUnaryNotAsPartOfBinaryOperation() { var v = true; Expression<Func<bool>> f = () => !v == false; var node = ExpressionParser.Parse(f.Body); var expected = new BinaryNode { Left = new UnaryNode { Prefix = "!", PrefixValue = "False", Operand = new ConstantNode() { Text = "v", Value = "True" }, }, Right = new ConstantNode { Text = "False", Value = null }, Operator = "==", Value = "True" }; Assert.AreEqual(expected, node); }
public void ParseIsOperator() { object x = "xValue"; Expression<Func<bool>> f = () => x is string; var node = ExpressionParser.Parse(f.Body); var expected = new BinaryNode() { Left = new ConstantNode() {Text = "x", Value = "\"xValue\""}, Operator = "is", Right = new ConstantNode() { Text = "string" }, Value = "True" }; Assert.AreEqual(expected, node); }
public void ParseCoalesce() { string x = null; Expression<Func<string>> f = () => x ?? "foo"; var p = new ExpressionParser(f.Body); var node = p.Parse(); var expected = new BinaryNode { Left = new ConstantNode { Text = "x", Value = "null" }, Right = new ConstantNode { Text = "\"foo\"" }, Operator = "??", Value = "\"foo\"" }; Assert.AreEqual(expected, node); }