Пример #1
0
        public void ExecuteSimpleForOnEmptyList()
        {
            ICommand body = new SetCommand("b", new BinaryOperatorExpression(new NameExpression("a"), new NameExpression("b"), BinaryOperator.Add));
            BindingEnvironment environment = new BindingEnvironment();
            environment.SetValue("b", 0);

            ForCommand command = new ForCommand("a", new ConstantExpression(new object[] { }), body);

            command.Execute(environment);

            Assert.AreEqual(0, environment.GetValue("b"));
        }
Пример #2
0
        public void ExecuteSimpleForWithContinue()
        {
            ICommand ifcmd = new IfCommand(new CompareExpression(ComparisonOperator.Equal, new NameExpression("a"), new ConstantExpression(2)), new ContinueCommand());
            ICommand setcmd = new SetCommand("b", new BinaryOperatorExpression(new NameExpression("a"), new NameExpression("b"), BinaryOperator.Add));
            ICommand body = new CompositeCommand(new ICommand[] { ifcmd, setcmd });

            BindingEnvironment environment = new BindingEnvironment();
            environment.SetValue("b", 0);

            ForCommand command = new ForCommand("a", new ConstantExpression(new object[] { 1, 2, 3 }), body);

            command.Execute(environment);

            Assert.AreEqual(4, environment.GetValue("b"));
        }
Пример #3
0
        public void RaiseWhenForOverAnInteger()
        {
            BindingEnvironment environment = new BindingEnvironment();
            environment.SetValue("b", 0);

            ForCommand command = new ForCommand("a", new ConstantExpression(1), null);

            try
            {
                command.Execute(environment);
                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(TypeError));
                Assert.AreEqual("'int' object is not iterable", ex.Message);
            }
        }