Exemplo n.º 1
0
        public void ExecuteCompositeCommand()
        {
            BindingEnvironment environment = new BindingEnvironment();

            SetVariableCommand command1 = new SetVariableCommand("foo", new ConstantExpression("bar"));
            SetVariableCommand command2 = new SetVariableCommand("one", new ConstantExpression(1));
            SetVariableCommand command3 = new SetVariableCommand("bar", new VariableExpression("foo"));

            List <ICommand> commands = new List <ICommand>();

            commands.Add(command1);
            commands.Add(command2);
            commands.Add(command3);

            CompositeCommand command = new CompositeCommand(commands);

            environment.SetValue("foo", null);
            environment.SetValue("one", null);

            command.Execute(environment);

            Assert.AreEqual("bar", environment.GetValue("foo"));
            Assert.AreEqual(1, environment.GetValue("one"));
            Assert.AreEqual("bar", environment.GetValue("bar"));
        }
Exemplo n.º 2
0
        public void ExecuteWhileCommand()
        {
            IExpression     incrementX = new ArithmeticBinaryExpression(ArithmeticOperator.Add, new ConstantExpression(1), new VariableExpression("x"));
            IExpression     decrementY = new ArithmeticBinaryExpression(ArithmeticOperator.Subtract, new VariableExpression("y"), new ConstantExpression(1));
            ICommand        setX       = new SetVariableCommand("x", incrementX);
            ICommand        setY       = new SetVariableCommand("y", decrementY);
            List <ICommand> commands   = new List <ICommand>();

            commands.Add(setX);
            commands.Add(setY);
            ICommand    command = new CompositeCommand(commands);
            IExpression yexpr   = new VariableExpression("y");

            WhileCommand whilecmd = new WhileCommand(yexpr, command);

            BindingEnvironment environment = new BindingEnvironment();

            environment.SetValue("x", 0);
            environment.SetValue("y", 5);

            whilecmd.Execute(environment);

            Assert.AreEqual(0, environment.GetValue("y"));
            Assert.AreEqual(5, environment.GetValue("x"));
        }
Exemplo n.º 3
0
        public void ExecCommandList()
        {
            BindingEnvironment environment = new BindingEnvironment();

            this.exec.Apply(environment, new object[] { "a = 1; b = 2" }, null);

            Assert.AreEqual(1, environment.GetValue("a"));
            Assert.AreEqual(2, environment.GetValue("b"));
        }
Exemplo n.º 4
0
        public void ExecCommandList()
        {
            BindingEnvironment environment = new BindingEnvironment();

            this.exec.Apply(environment, new object[] { "a = 1; b = 2" }, null);

            Assert.AreEqual(1, environment.GetValue("a"));
            Assert.AreEqual(2, environment.GetValue("b"));
        }
Exemplo n.º 5
0
        public void ExecuteSetLocalVariable()
        {
            BindingEnvironment environment = new BindingEnvironment();

            Assert.IsNull(environment.GetValue("foo"));

            SetLocalVariableCommand cmd = new SetLocalVariableCommand("foo", new ConstantExpression("bar"));

            cmd.Execute(environment);

            Assert.AreEqual("bar", environment.GetValue("foo"));
        }
Exemplo n.º 6
0
        public void CreateAndExecuteTryCommandWithFinally()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ICommand body = new SetCommand("a", new ConstantExpression(1));
            ICommand @finally = new SetCommand("b", new ConstantExpression(2));
            TryCommand command = new TryCommand(body);
            command.SetFinally(@finally);

            command.Execute(environment);

            Assert.AreEqual(1, environment.GetValue("a"));
            Assert.AreEqual(2, environment.GetValue("b"));
        }
Exemplo n.º 7
0
        public void SetValueThruBindingEnvironmentIfDefinedInObject()
        {
            this.environment.SetValue("Age", null);

            BindingEnvironment binding = new BindingEnvironment(this.environment);

            binding.SetValue("Age", 800);
            binding.SetValue("Local", 100);

            Assert.AreEqual(800, binding.GetValue("Age"));
            Assert.AreEqual(100, binding.GetValue("Local"));
            Assert.AreEqual(800, this.environment.GetValue("Age"));
            Assert.IsNull(this.environment.GetValue("Local"));
        }
Exemplo n.º 8
0
        public void ExecuteIfCommandElseWhenFalse()
        {
            IExpression condition   = new ConstantExpression(false);
            ICommand    setXCommand = new SetVariableCommand("x", new ConstantExpression(1));
            ICommand    setYCommand = new SetVariableCommand("y", new ConstantExpression(2));
            IfCommand   command     = new IfCommand(condition, setXCommand, setYCommand);

            BindingEnvironment environment = new BindingEnvironment();

            command.Execute(environment);

            Assert.IsNull(environment.GetValue("x"));
            Assert.AreEqual(2, environment.GetValue("y"));
        }
Exemplo n.º 9
0
        public void CreateAndExecuteTryCommandWithFinally()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ICommand           body        = new SetCommand("a", new ConstantExpression(1));
            ICommand           @finally    = new SetCommand("b", new ConstantExpression(2));
            TryCommand         command     = new TryCommand(body);

            command.SetFinally(@finally);

            command.Execute(environment);

            Assert.AreEqual(1, environment.GetValue("a"));
            Assert.AreEqual(2, environment.GetValue("b"));
        }
Exemplo n.º 10
0
        public void SetValueThruBindingEnvironmentIfDefinedInObject()
        {
            this.environment.SetValue("Age", null);

            BindingEnvironment binding = new BindingEnvironment(this.environment);

            binding.SetValue("Age", 800);
            binding.SetValue("Local", 100);

            Assert.AreEqual(800, binding.GetValue("Age"));
            Assert.AreEqual(100, binding.GetValue("Local"));
            Assert.AreEqual(800, this.environment.GetValue("Age"));
            Assert.IsNull(this.environment.GetValue("Local"));
        }
Exemplo n.º 11
0
        public void EvaluateIfCommandWithNullAsCondition()
        {
            IExpression condition   = new ConstantExpression(null);
            ICommand    thenCommand = new SetCommand("a", new ConstantExpression(1));
            ICommand    elseCommand = new SetCommand("b", new ConstantExpression(2));

            IfCommand command = new IfCommand(condition, thenCommand, elseCommand);

            BindingEnvironment environment = new BindingEnvironment();

            command.Execute(environment);

            Assert.IsNull(environment.GetValue("a"));
            Assert.AreEqual(2, environment.GetValue("b"));
        }
Exemplo n.º 12
0
        public void ExecuteSetArrayCommandWithDotExpression()
        {
            BindingEnvironment environment = new BindingEnvironment();
            DotExpression      dotexpr     = new DotExpression(new VariableExpression("foo"), "Values");
            SetArrayCommand    command     = new SetArrayCommand(dotexpr, new IExpression[] { new ConstantExpression(0) }, new ConstantExpression("bar"));

            command.Execute(environment);

            object obj = environment.GetValue("foo");

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(DynamicObject));

            DynamicObject dynobj = (DynamicObject)obj;

            object obj2 = dynobj.GetValue("Values");

            Assert.IsNotNull(obj2);
            Assert.IsInstanceOfType(obj2, typeof(IList));

            IList list = (IList)obj2;

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual("bar", list[0]);
        }
Exemplo n.º 13
0
        public void ExecuteSetCommandWithComplexDotExpression()
        {
            BindingEnvironment environment = new BindingEnvironment();
            DotExpression      dot         = new DotExpression(new VariableExpression("foo"), "Address");
            DotExpression      dotexpr     = new DotExpression(dot, "Street");
            SetCommand         command     = new SetCommand(dotexpr, new ConstantExpression("bar"));

            command.Execute(environment);

            object obj = environment.GetValue("foo");

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(DynamicObject));

            DynamicObject dynobj = (DynamicObject)obj;

            object obj2 = dynobj.GetValue("Address");

            Assert.IsNotNull(obj2);
            Assert.IsInstanceOfType(obj2, typeof(DynamicObject));

            DynamicObject dynobj2 = (DynamicObject)obj2;

            Assert.AreEqual("bar", dynobj2.GetValue("Street"));
        }
Exemplo n.º 14
0
        public void ExecuteForCommand()
        {
            ICommand        setX     = new SetVariableCommand("x", new ConstantExpression(0));
            ICommand        setY     = new SetVariableCommand("y", new ConstantExpression(0));
            List <ICommand> commands = new List <ICommand>();

            commands.Add(setX);
            commands.Add(setY);
            ICommand initialCommand = new CompositeCommand(commands);

            IExpression condition = new CompareExpression(ComparisonOperator.Less, new VariableExpression("x"), new ConstantExpression(6));

            IExpression addXtoY = new ArithmeticBinaryExpression(ArithmeticOperator.Add, new VariableExpression("y"), new VariableExpression("x"));
            ICommand    addToY  = new SetVariableCommand("y", addXtoY);

            ICommand endCommand = new SetVariableCommand("x", new ArithmeticBinaryExpression(ArithmeticOperator.Add, new VariableExpression("x"), new ConstantExpression(1)));

            ForCommand forcmd = new ForCommand(initialCommand, condition, endCommand, addToY);

            BindingEnvironment environment = new BindingEnvironment();

            environment.SetValue("y", null);

            forcmd.Execute(environment);

            Assert.AreEqual(15, environment.GetValue("y"));
        }
Exemplo n.º 15
0
        public void CanCreate()
        {
            BindingEnvironment environment = new BindingEnvironment();

            Assert.IsNotNull(environment);
            Assert.AreSame(environment, environment.GetValue("Environment"));
        }
        public void SetAndGetValue()
        {
            BindingEnvironment environment = new BindingEnvironment();

            environment.SetValue("one", 1);
            Assert.AreEqual(1, environment.GetValue("one"));
        }
Exemplo n.º 17
0
        public void CanCreate()
        {
            BindingEnvironment environment = new BindingEnvironment();

            Assert.IsNotNull(environment);
            Assert.AreSame(environment, environment.GetValue("Environment"));
        }
Exemplo n.º 18
0
        public void Execute(IContext context)
        {
            BindingEnvironment env = new BindingEnvironment(context);
            IList<IType> bases = null;

            if (this.baseExpressions != null && this.baseExpressions.Count > 0)
            {
                bases = new List<IType>();

                foreach (var expr in this.baseExpressions)
                    bases.Add((IType)expr.Evaluate(context));
            }

            DefinedClass klass = new DefinedClass(this.name, bases, context);
            this.body.Execute(klass);
            foreach (var name in env.GetNames())
            {
                var value = env.GetValue(name);
                var deffunc = value as DefinedFunction;

                if (deffunc != null)
                    klass.SetMethod(deffunc.Name, deffunc);
            }

            klass.SetValue("__doc__", this.doc);

            context.SetValue(this.name, klass);
        }
Exemplo n.º 19
0
        public void Execute(IContext context)
        {
            BindingEnvironment env   = new BindingEnvironment(context);
            IList <IType>      bases = null;

            if (this.baseExpressions != null && this.baseExpressions.Count > 0)
            {
                bases = new List <IType>();

                foreach (var expr in this.baseExpressions)
                {
                    bases.Add((IType)expr.Evaluate(context));
                }
            }

            DefinedClass klass = new DefinedClass(this.name, bases, context);

            this.body.Execute(klass);
            foreach (var name in env.GetNames())
            {
                var value   = env.GetValue(name);
                var deffunc = value as DefinedFunction;

                if (deffunc != null)
                {
                    klass.SetMethod(deffunc.Name, deffunc);
                }
            }

            klass.SetValue("__doc__", this.doc);

            context.SetValue(this.name, klass);
        }
Exemplo n.º 20
0
        public void GetValueFromParent()
        {
            BindingEnvironment parent = new BindingEnvironment();
            parent.SetValue("one", 1);
            BindingEnvironment environment = new BindingEnvironment(parent);

            Assert.AreEqual(1, environment.GetValue("one"));
        }
Exemplo n.º 21
0
        public void ExecSimpleText()
        {
            BindingEnvironment environment = new BindingEnvironment();

            this.exec.Apply(environment, new object[] { "a = 1" }, null);

            Assert.AreEqual(1, environment.GetValue("a"));
        }
Exemplo n.º 22
0
        public void SetAndGetValue()
        {
            BindingEnvironment environment = new BindingEnvironment();

            environment.SetValue("foo", "bar");

            Assert.AreEqual("bar", environment.GetValue("foo"));
        }
Exemplo n.º 23
0
        public void SetAndGetValue()
        {
            BindingEnvironment environment = new BindingEnvironment();

            environment.SetValue("foo", "bar");

            Assert.AreEqual("bar", environment.GetValue("foo"));
        }
Exemplo n.º 24
0
        public void GetValueDefinedInParent()
        {
            BindingEnvironment parent = new BindingEnvironment();
            parent.SetValue("foo", "bar");
            BindingEnvironment environment = new BindingEnvironment(parent);

            Assert.AreEqual("bar", environment.GetValue("foo"));
        }
Exemplo n.º 25
0
        public void ExecSimpleText()
        {
            BindingEnvironment environment = new BindingEnvironment();

            this.exec.Apply(environment, new object[] { "a = 1" }, null);

            Assert.AreEqual(1, environment.GetValue("a"));
        }
Exemplo n.º 26
0
        public void SetVariable()
        {
            IExpression expression = new ConstantExpression(1);
            BindingEnvironment environment = new BindingEnvironment();
            ICommand command = new SetCommand("spam", expression);
            command.Execute(environment);

            Assert.AreEqual(1, environment.GetValue("spam"));
        }
Exemplo n.º 27
0
        public void ExecuteSetCommandWithVariable()
        {
            BindingEnvironment environment = new BindingEnvironment();
            SetCommand         command     = new SetCommand(new VariableExpression("foo"), new ConstantExpression("bar"));

            command.Execute(environment);

            Assert.AreEqual("bar", environment.GetValue("foo"));
        }
Exemplo n.º 28
0
        public void ExecuteSetCommand()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ICommand           command     = new SetCommand("one", new ConstantExpression(1));

            command.Execute(environment);

            Assert.AreEqual(1, environment.GetValue("one"));
        }
Exemplo n.º 29
0
        public void GetValueDefinedInParent()
        {
            BindingEnvironment parent = new BindingEnvironment();

            parent.SetValue("foo", "bar");
            BindingEnvironment environment = new BindingEnvironment(parent);

            Assert.AreEqual("bar", environment.GetValue("foo"));
        }
Exemplo n.º 30
0
        public void GetValueFromParent()
        {
            BindingEnvironment parent = new BindingEnvironment();

            parent.SetValue("one", 1);
            BindingEnvironment environment = new BindingEnvironment(parent);

            Assert.AreEqual(1, environment.GetValue("one"));
        }
Exemplo n.º 31
0
        public void SetVariable()
        {
            IExpression        expression  = new ConstantExpression(1);
            BindingEnvironment environment = new BindingEnvironment();
            ICommand           command     = new SetCommand("spam", expression);

            command.Execute(environment);

            Assert.AreEqual(1, environment.GetValue("spam"));
        }
Exemplo n.º 32
0
        public void ExecuteIfCommandWhenTrue()
        {
            IExpression condition  = new ConstantExpression(true);
            ICommand    setCommand = new SetVariableCommand("x", new ConstantExpression(1));
            IfCommand   command    = new IfCommand(condition, setCommand);

            BindingEnvironment environment = new BindingEnvironment();

            command.Execute(environment);

            Assert.AreEqual(1, environment.GetValue("x"));
        }
Exemplo n.º 33
0
        public void DefineAndSetGlobalValue()
        {
            Machine machine = new Machine();
            BindingEnvironment environment = new BindingEnvironment();

            environment.DefineGlobal("global");

            environment.SetValue("global", 100);

            Assert.AreEqual(100, environment.GetValue("global"));
            Assert.AreEqual(100, machine.Environment.GetValue("global"));
        }
Exemplo n.º 34
0
        public void SetLocalValue()
        {
            BindingEnvironment parent = new BindingEnvironment();

            parent.SetValue("foo", "bar");
            BindingEnvironment environment = new BindingEnvironment(parent);

            environment.SetValue("foo", "newbar");

            Assert.AreEqual("newbar", environment.GetValue("foo"));
            Assert.AreEqual("bar", parent.GetValue("foo"));
        }
Exemplo n.º 35
0
        public void DefineAndSetGlobalValue()
        {
            Machine            machine     = new Machine();
            BindingEnvironment environment = new BindingEnvironment();

            environment.DefineGlobal("global");

            environment.SetValue("global", 100);

            Assert.AreEqual(100, environment.GetValue("global"));
            Assert.AreEqual(100, machine.Environment.GetValue("global"));
        }
        public void ResolveVariableExpressionToDictionary()
        {
            BindingEnvironment environment = new BindingEnvironment();
            IExpression        expression  = new VariableExpression("foo");

            object obj = ExpressionUtilities.ResolveToDictionary(expression, environment);

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(IDictionary));

            Assert.AreEqual(obj, environment.GetValue("foo"));
        }
Exemplo n.º 37
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"));
        }
Exemplo n.º 38
0
        public void ExecuteClassCommandWithEmptyMethod()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ClassCommand       command     = new ClassCommand("Spam", new DefCommand("foo", null, new PassCommand()));

            command.Execute(environment);

            var result = (DefinedClass)environment.GetValue("Spam");

            Assert.AreEqual("Spam", result.Name);

            Assert.IsNotNull(result.GetMethod("foo"));
        }
Exemplo n.º 39
0
        public void SetValueThruLocalEnviroment()
        {
            BindingEnvironment environment = new BindingEnvironment();

            environment.SetValue("one", 0);

            LocalBindingEnvironment local = new LocalBindingEnvironment(environment);

            local.SetValue("one", 1);

            Assert.AreEqual(1, local.GetValue("one"));
            Assert.AreEqual(1, environment.GetValue("one"));
        }
Exemplo n.º 40
0
        public void SetUndefinedValueUsingTwoLocalEnviroments()
        {
            BindingEnvironment environment = new BindingEnvironment();

            LocalBindingEnvironment local  = new LocalBindingEnvironment(environment);
            LocalBindingEnvironment local2 = new LocalBindingEnvironment(local);

            local2.SetValue("one", 1);

            Assert.AreEqual(1, local.GetValue("one"));
            Assert.AreEqual(1, local2.GetValue("one"));
            Assert.AreEqual(1, environment.GetValue("one"));
        }
Exemplo n.º 41
0
        public void CreateSimpleClassWithEmptyDocString()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ClassCommand       command     = new ClassCommand("Spam", new PassCommand());

            command.Execute(environment);

            var result = environment.GetValue("Spam");
            var dclass = (DefinedClass)result;

            Assert.IsNull(dclass.GetValue("__doc__"));
            Assert.IsTrue(dclass.HasValue("__doc__"));
        }
Exemplo n.º 42
0
        public void ExecuteClassCommandWithEmptyMethod()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ClassCommand command = new ClassCommand("Spam", new DefCommand("foo", null, new PassCommand()));

            command.Execute(environment);

            var result = (DefinedClass)environment.GetValue("Spam");

            Assert.AreEqual("Spam", result.Name);

            Assert.IsNotNull(result.GetMethod("foo"));
        }
Exemplo n.º 43
0
        public void CreateSimpleClassWithEmptyDocString()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ClassCommand command = new ClassCommand("Spam", new PassCommand());

            command.Execute(environment);

            var result = environment.GetValue("Spam");
            var dclass = (DefinedClass)result;

            Assert.IsNull(dclass.GetValue("__doc__"));
            Assert.IsTrue(dclass.HasValue("__doc__"));
        }
Exemplo n.º 44
0
        public void ExecuteFinallyEvenWhenRaiseException()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ICommand body = new SetCommand("a", new NameExpression("c"));
            ICommand @finally = new SetCommand("b", new ConstantExpression(2));
            TryCommand command = new TryCommand(body);
            command.SetFinally(@finally);

            try
            {
                command.Execute(environment);
                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(NameError));
                Assert.AreEqual("name 'c' is not defined", ex.Message);
            }

            Assert.IsNull(environment.GetValue("a"));
            Assert.AreEqual(2, environment.GetValue("b"));
        }
Exemplo n.º 45
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"));
        }
Exemplo n.º 46
0
        public void ExecuteCompositeCommandWithReturn()
        {
            SetCommand command1 = new SetCommand("foo", new ConstantExpression("bar"));
            ReturnCommand command2 = new ReturnCommand(new ConstantExpression("spam"));
            SetCommand command3 = new SetCommand("one", new ConstantExpression(1));

            CompositeCommand command = new CompositeCommand();
            command.AddCommand(command1);
            command.AddCommand(command2);
            command.AddCommand(command3);

            Machine machine = new Machine();
            BindingEnvironment environment = new BindingEnvironment(machine.Environment);

            command.Execute(environment);

            Assert.AreEqual("bar", environment.GetValue("foo"));
            Assert.IsNull(environment.GetValue("one"));
            Assert.IsTrue(environment.HasReturnValue());
            Assert.AreEqual("spam", environment.GetReturnValue());
            Assert.IsNotNull(command.Commands);
        }
Exemplo n.º 47
0
        public void DefineAndSetGlobalValueThruLocalEnvironment()
        {
            Machine machine = new Machine();
            BindingEnvironment environment = new BindingEnvironment();
            LocalBindingEnvironment local = new LocalBindingEnvironment(environment);

            local.DefineGlobal("global");

            local.SetValue("global", 100);

            Assert.AreEqual(100, local.GetValue("global"));
            Assert.AreEqual(100, environment.GetValue("global"));
            Assert.AreEqual(100, machine.Environment.GetValue("global"));
        }
Exemplo n.º 48
0
        public void CreateAndEvaluateSimpleWhileCommand()
        {
            BindingEnvironment environment = new BindingEnvironment();
            environment.SetValue("a", 1);
            IExpression condition = new CompareExpression(ComparisonOperator.Less, new NameExpression("a"), new ConstantExpression(10));
            ICommand body = new SetCommand("a", new BinaryOperatorExpression(new NameExpression("a"), new ConstantExpression(1), BinaryOperator.Add));

            WhileCommand command = new WhileCommand(condition, body);

            command.Execute(environment);

            Assert.AreEqual(condition, command.Condition);
            Assert.AreEqual(body, command.Command);
            Assert.AreEqual(10, environment.GetValue("a"));
        }
Exemplo n.º 49
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"));
        }
Exemplo n.º 50
0
        public void ExecuteSimpleClassCommand()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ClassCommand command = new ClassCommand("Spam", new PassCommand());

            command.Execute(environment);

            var result = environment.GetValue("Spam");
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(DefinedClass));

            var dclass = (DefinedClass)result;

            Assert.AreEqual("Spam", dclass.Name);
            Assert.IsNull(dclass.GetValue("__doc__"));
            Assert.IsTrue(dclass.HasValue("__doc__"));
        }
Exemplo n.º 51
0
        public void ResolveDotExpressionToDictionary()
        {
            BindingEnvironment environment = new BindingEnvironment();
            IExpression expression = new DotExpression(new VariableExpression("Project"), "Entities");

            object obj = ExpressionUtilities.ResolveToDictionary(expression, environment);

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(IDictionary));

            object project = environment.GetValue("Project");

            Assert.IsNotNull(project);
            Assert.IsInstanceOfType(project, typeof(IObject));

            object entities = ((IObject)project).GetValue("Entities");

            Assert.IsNotNull(entities);
            Assert.IsInstanceOfType(entities, typeof(IDictionary));

            Assert.AreEqual(obj, entities);
        }
Exemplo n.º 52
0
        public void ResolveDotExpressionToObject()
        {
            BindingEnvironment environment = new BindingEnvironment();
            IExpression expression = new DotExpression(new VariableExpression("Project"), "Title");

            object obj = ExpressionUtilities.ResolveToObject(expression, environment);

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(IObject));

            object project = environment.GetValue("Project");

            Assert.IsNotNull(project);
            Assert.IsInstanceOfType(project, typeof(IObject));

            object title = ((IObject)project).GetValue("Title");

            Assert.IsNotNull(title);
            Assert.IsInstanceOfType(title, typeof(IObject));

            Assert.AreEqual(obj, title);
        }
Exemplo n.º 53
0
        public void ExecuteClassCommandWithInheritance()
        {
            DefinedClass fooclass = new DefinedClass("Foo");
            DefinedClass barclass = new DefinedClass("Bar");
            BindingEnvironment environment = new BindingEnvironment();
            ClassCommand command = new ClassCommand("Spam", new IExpression[] { new ConstantExpression(fooclass), new ConstantExpression(barclass) }, new PassCommand());

            command.Execute(environment);

            var result = environment.GetValue("Spam");
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(DefinedClass));

            var dclass = (DefinedClass)result;

            Assert.AreEqual("Spam", dclass.Name);
            Assert.IsNotNull(dclass.Bases);
            Assert.AreEqual(2, dclass.Bases.Count);
            Assert.AreEqual(fooclass, dclass.Bases[0]);
            Assert.AreEqual(barclass, dclass.Bases[1]);
            Assert.IsNull(dclass.GetValue("__doc__"));
            Assert.IsTrue(dclass.HasValue("__doc__"));
        }
Exemplo n.º 54
0
        public void ResolveVariableExpressionToDictionary()
        {
            BindingEnvironment environment = new BindingEnvironment();
            IExpression expression = new VariableExpression("foo");

            object obj = ExpressionUtilities.ResolveToDictionary(expression, environment);

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(IDictionary));

            Assert.AreEqual(obj, environment.GetValue("foo"));
        }
Exemplo n.º 55
0
 public object Evaluate(BindingEnvironment environment)
 {
     return environment.GetValue(this.name);
 }
Exemplo n.º 56
0
        public void SetUndefinedValueUsingTwoLocalEnviroments()
        {
            BindingEnvironment environment = new BindingEnvironment();

            LocalBindingEnvironment local = new LocalBindingEnvironment(environment);
            LocalBindingEnvironment local2 = new LocalBindingEnvironment(local);

            local2.SetValue("one", 1);

            Assert.AreEqual(1, local.GetValue("one"));
            Assert.AreEqual(1, local2.GetValue("one"));
            Assert.AreEqual(1, environment.GetValue("one"));
        }
Exemplo n.º 57
0
        public void SetLocalValue()
        {
            BindingEnvironment parent = new BindingEnvironment();
            parent.SetValue("foo", "bar");
            BindingEnvironment environment = new BindingEnvironment(parent);
            environment.SetValue("foo", "newbar");

            Assert.AreEqual("newbar", environment.GetValue("foo"));
            Assert.AreEqual("bar", parent.GetValue("foo"));
        }
Exemplo n.º 58
0
        public void SetValueThruLocalAndNormalEnviroment()
        {
            BindingEnvironment parent = new BindingEnvironment();
            LocalBindingEnvironment toplocal = new LocalBindingEnvironment(parent);

            toplocal.SetLocalValue("one", 0);

            BindingEnvironment environment = new BindingEnvironment(toplocal);

            LocalBindingEnvironment local = new LocalBindingEnvironment(environment);
            local.SetValue("one", 1);

            Assert.AreEqual(1, local.GetValue("one"));
            Assert.AreEqual(1, environment.GetValue("one"));
            Assert.AreEqual(1, toplocal.GetValue("one"));
            Assert.IsNull(parent.GetValue("one"));
        }
Exemplo n.º 59
0
        public void GetNullIfUnknownName()
        {
            BindingEnvironment environment = new BindingEnvironment();

            Assert.IsNull(environment.GetValue("foo"));
        }
Exemplo n.º 60
0
        public void SetValueThruLocalEnviroment()
        {
            BindingEnvironment environment = new BindingEnvironment();
            environment.SetValue("one", 0);

            LocalBindingEnvironment local = new LocalBindingEnvironment(environment);
            local.SetValue("one", 1);

            Assert.AreEqual(1, local.GetValue("one"));
            Assert.AreEqual(1, environment.GetValue("one"));
        }