コード例 #1
0
        public void EvaluateDefinedMethod()
        {
            Context context = new Context();
            IList<ICommand> commandlist = new List<ICommand>();

            commandlist.Add(new SetVariableCommand("a", new ConstantExpression(1)));
            commandlist.Add(new SetVariableCommand("b", new ConstantExpression(2)));
            commandlist.Add(new ExpressionCommand(new VariableExpression("b")));

            CompositeCommand commands = new CompositeCommand(commandlist);

            DefinedMethod method = new DefinedMethod(null, commands);

            context.SetValue("foo", method);

            VariableExpression expr = new VariableExpression("foo");

            Assert.AreEqual(2, expr.Evaluate(context));
        }
コード例 #2
0
ファイル: CallExpressionTests.cs プロジェクト: ajlopez/AjLang
        public void ExecuteCallExpression()
        {
            Context context = new Context();
            IList<ICommand> commandlist = new List<ICommand>();

            commandlist.Add(new SetVariableCommand("a", new ConstantExpression(1)));
            commandlist.Add(new SetVariableCommand("b", new ConstantExpression(2)));
            commandlist.Add(new ExpressionCommand(new VariableExpression("b")));

            CompositeCommand commands = new CompositeCommand(commandlist);

            DefinedMethod method = new DefinedMethod(null, commands);

            CallExpression callexpr = new CallExpression(new ConstantExpression(method), null);

            object result = callexpr.Evaluate(context);

            Assert.AreEqual(2, result);
        }
コード例 #3
0
ファイル: DefinedMethodTests.cs プロジェクト: ajlopez/AjLang
        public void ExecuteDefinedMethod()
        {
            Context context = new Context();
            IList<ICommand> commandlist = new List<ICommand>();

            commandlist.Add(new SetVariableCommand("a", new ConstantExpression(1)));
            commandlist.Add(new SetVariableCommand("b", new ConstantExpression(2)));
            commandlist.Add(new ExpressionCommand(new VariableExpression("b")));

            CompositeCommand commands = new CompositeCommand(commandlist);

            DefinedMethod method = new DefinedMethod(null, commands);

            object result = method.Call(context, null);

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result);

            Assert.IsNull(context.GetValue("a"));
            Assert.IsNull(context.GetValue("b"));
        }