示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }