Ejemplo n.º 1
0
        public void DefineAndEvaluateDotExpression()
        {
            DotExpression expr = new DotExpression(new ConstantExpression(new MockObject()), "foo", null);

            object result = expr.Evaluate(null);

            Assert.IsNotNull(result);
            Assert.AreEqual("foo", result);
        }
Ejemplo n.º 2
0
        public void EvaluateNativeObjectClassMethod()
        {
            Machine machine = new Machine();

            DotExpression expression = new DotExpression(new ConstantExpression(1), "class", null);

            var result = expression.Evaluate(machine.RootContext);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FixnumClass));
        }
Ejemplo n.º 3
0
        public void EvaluateDotExpression()
        {
            Context     parent  = new Context();
            Context     context = new Context(parent);
            IExpression lexpr   = new ConstantExpression(context);

            var expr  = new DotExpression(lexpr, "Parent");
            var value = expr.Evaluate(null);

            Assert.IsNotNull(value);
            Assert.AreSame(parent, value);
        }
Ejemplo n.º 4
0
        public void DefineAndEvaluateDotExpressionWithArguments()
        {
            List <IExpression> arguments = new List <IExpression>();

            arguments.Add(new ConstantExpression(1));
            arguments.Add(new ConstantExpression(2));
            DotExpression expr = new DotExpression(new ConstantExpression(new MockObject()), "foo", arguments);

            object result = expr.Evaluate(null);

            Assert.IsNotNull(result);
            Assert.AreEqual("foo:1:2", result);
        }
        public void GetName()
        {
            IObject dobj    = new DynamicObject("Name", "Adam", "Age", 800);
            Context context = new Context();

            context.SetMember("adam", dobj);

            DotExpression expression = new DotExpression(new NameExpression("adam"), "Name");

            var result = expression.Evaluate(context);

            Assert.IsNotNull(result);
            Assert.AreEqual("Adam", result);
        }
Ejemplo n.º 6
0
        public void EvaluateInstanceMethod()
        {
            Machine machine = new Machine();

            machine.ExecuteText("class MyClass;def foo;3;end;end");

            var dclass = (DynamicClass)machine.RootContext.GetValue("MyClass");

            var myobj = dclass.CreateInstance();

            DotExpression expression = new DotExpression(new ConstantExpression(myobj), "foo", new IExpression[0]);

            var result = expression.Evaluate(null);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result);
        }
Ejemplo n.º 7
0
        public void EvaluateUndefinedInstanceMethod()
        {
            Machine machine = new Machine();

            machine.ExecuteText("class MyClass;end");

            var dclass = (DynamicClass)machine.RootContext.GetValue("MyClass");

            var myobj = dclass.CreateInstance();

            DotExpression expression = new DotExpression(new ConstantExpression(myobj), "foo", new IExpression[0]);

            try
            {
                expression.Evaluate(null);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(NoMethodError));
                Assert.AreEqual("undefined method 'foo'", ex.Message);
            }
        }
Ejemplo n.º 8
0
        public void EvaluateDotExpressionAsTypeInvocation()
        {
            DotExpression dot = new DotExpression(new DotExpression(new DotExpression(new VariableExpression("System"), "IO"), "File"), "Exists", new IExpression[] { new ConstantExpression("unknown.txt") });

            Assert.IsFalse((bool)dot.Evaluate(new Context()));
        }
Ejemplo n.º 9
0
        public void EvaluateDotExpressionOnString()
        {
            IExpression expression = new DotExpression(new ConstantExpression("foo"), "Length");

            Assert.AreEqual(3, expression.Evaluate(null));
        }
Ejemplo n.º 10
0
        public void EvaluateDotExpressionOnInteger()
        {
            IExpression expression = new DotExpression(new ConstantExpression(1), "ToString", new List <IExpression>());

            Assert.AreEqual("1", expression.Evaluate(null));
        }