示例#1
0
        public void ShouldEvaluateIndexersAsClrFields() {
            var box = new Box { width = 10, height = 20 };

            var jint = new JintEngine()
            .SetDebugMode(true)
            .AllowClr()
            .SetParameter("box", box);

            Assert.AreEqual(10, jint.Run("return box.width"));
            Assert.AreEqual(10, jint.Run("return box['width']"));
            jint.Run("box['height'] = 30;");

            Assert.AreEqual(30, box.height);

            jint.Run("box.height = 18;");

            Assert.AreEqual(18, box.height);

        }
示例#2
0
        public void ShouldFindOverloadWithNullParam() {
            var box = new Box { Width = 10, Height = 20 };

            var jint = new Jint.JintEngine()
            .SetDebugMode(true)
            .SetFunction("assert", new Action<object, object>(Assert.AreEqual))
            .SetParameter("box", box);

            jint.Run(@"
                assert(1, Number(box.Foo(1)));
                assert(2, Number(box.Foo(2, null)));    
            ");
        }
示例#3
0
文件: Fixtures.cs 项目: cosh/Jint
        public void ShouldEvaluateIndexersAsClrProperties()
        {
            var box = new Box { Width = 10, Height = 20 };

            var jint = new JintEngine()
            .SetDebugMode(true)
            .SetParameter("box", box);

            Assert.AreEqual(10, jint.Run("return box.Width"));
            Assert.AreEqual(10, jint.Run("return box['Width']"));
            jint.Run("box['Height'] = 30;");

            Assert.AreEqual(30, box.Height);

            jint.Run("box.Height = 18;");
            Assert.AreEqual(18, box.Height);
        }