Example #1
0
        public void GetAndEvaluateIfExpression()
        {
            IfExpression expression = IfExpression.Instance;

            Assert.IsNotNull(expression);

            Machine machine = new Machine();

            machine.Push(true);
            machine.Push(new IntegerExpression(1));
            machine.Push(new IntegerExpression(2));

            expression.Evaluate(machine);

            Assert.AreEqual(1, machine.StackCount);
            Assert.AreEqual(1, machine.Pop());

            machine.Push(false);
            machine.Push(new IntegerExpression(1));
            machine.Push(new IntegerExpression(2));

            expression.Evaluate(machine);

            Assert.AreEqual(1, machine.StackCount);
            Assert.AreEqual(2, machine.Pop());
        }
Example #2
0
        public void EvaluateElseExpression()
        {
            IfExpression ifexpr = new IfExpression(new ConstantExpression(false), new ConstantExpression(1), new ConstantExpression(2));

            Assert.AreSame(TypeInfo.Int, ifexpr.TypeInfo);
            Assert.AreEqual(2, ifexpr.Evaluate(null));
        }
        public void ExecuteThenWhenConditionIsZero()
        {
            IfExpression cmd     = new IfExpression(new ConstantExpression(0), new AssignExpression("one", new ConstantExpression(1)));
            Context      context = new Context();

            Assert.AreEqual(1, cmd.Evaluate(context));
            Assert.AreEqual(1, context.GetValue("one"));
        }
        public void DontExecuteThenWhenConditionIsNull()
        {
            IfExpression cmd     = new IfExpression(new ConstantExpression(null), new AssignExpression("one", new ConstantExpression(1)));
            Context      context = new Context();

            Assert.IsNull(cmd.Evaluate(context));
            Assert.IsNull(context.GetValue("one"));
        }
        public void ExecuteElseWhenConditionIsNull()
        {
            IfExpression cmd     = new IfExpression(new ConstantExpression(null), new AssignExpression("one", new ConstantExpression(1)), new AssignExpression("two", new ConstantExpression(2)));
            Context      context = new Context();

            Assert.AreEqual(cmd.Evaluate(context), 2);
            Assert.IsNull(context.GetValue("one"));
            Assert.AreEqual(2, context.GetValue("two"));
        }