Пример #1
0
        private void Assign(Scope scope, string name, object val, bool isConst, object expected)
        {
            Expression expr = isConst
                            ? (Expression) new ConstantExpression(val)
                            : (Expression) new VariableExpression(val.ToString(), scope);
            var exp = new AssignmentStatement(name, expr, scope);

            exp.Execute();
            Assert.AreEqual(expected, scope.Get <object>(name));
        }
Пример #2
0
        public void TestAssignmentStatement()
        {
            ExecutionEnvironment e = new ExecutionEnvironment();

            e.RegisterValue("a", 5);
            Identifier i = new Identifier();

            i.Variable = "a";
            AssignmentStatement s = new AssignmentStatement();

            s.Left = i;
            Literal l = new Literal()
            {
                Raw = "7"
            };

            s.Right = l;
            var c = s.Execute(e);

            Assert.AreEqual(c.ReturnValue, 7);
            e.RegisterValue("c", 5);
            var dd = new AssignmentStatement()
            {
                Left = new Identifier()
                {
                    Variable = "c"
                }, Right = new BinaryExpression()
                {
                    Left = new Identifier()
                    {
                        Variable = "c"
                    }, Operator = Operator.Add, Right = new Literal()
                    {
                        Raw = "2"
                    }
                }
            };
            var cx = dd.Execute(e);

            Assert.AreEqual(cx.ReturnValue, 7);
        }