public void TestSetGetMemberInBody() { var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString("def test() { return @x + @y; }; def new() { @x = 12; @y = 10; };"); var scope = engine.CreateScope(); source.Execute(scope); var testClass = new NovaClass("Test", global::Nova.Nova.Box(typeof(object)), new List <NovaFunction> { scope.GetVariable("new") }, new List <NovaFunction> { scope.GetVariable("test") }); var nscope = engine.CreateScope(); nscope.SetVariable("Test", testClass); var nsource = engine.CreateScriptSourceFromString("x = Test(); x.test;"); Assert.That(nsource.Execute(nscope), Is.EqualTo(22)); }
public void TestNovaObjectBinaryIronRuby() { var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString("def +(x) { return @x + x; };"); var scope = engine.CreateScope(); source.Execute(scope); dynamic testClass = new NovaClass("Test", global::Nova.Nova.Box(typeof(object)), new List <NovaFunction>(), new List <NovaFunction> { scope.GetVariable("+") }); scope.RemoveVariable("+"); scope.SetVariable("TestClass", testClass); var rubyengine = GetRuntime().GetEngine("IronRuby"); var rubysource = rubyengine.CreateScriptSourceFromString("x = nova.TestClass; x.x = 17; x + 10;"); var rubyscope = rubyengine.CreateScope(); rubyscope.SetVariable("nova", scope); Assert.That(rubysource.Execute(rubyscope), Is.EqualTo(27)); }
public void TestInvokeMemberPartialFunctionIVarTestCSharp() { var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString("def new(z) { @z = z; }; def test(x,y) { return x + y + @z; };"); var scope = engine.CreateScope(); source.Execute(scope); dynamic testClass = new NovaClass("Test", global::Nova.Nova.Box(typeof(object)), new List <NovaFunction> { scope.GetVariable("new") }, new List <NovaFunction> { scope.GetVariable("test") }); scope.RemoveVariable("new"); scope.RemoveVariable("test"); var x = testClass(10); var px = x.test(10); Assert.That(px(17), Is.EqualTo(37)); }
public void TestInvokeMemberSuperCSharp() { var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString("def test(x) { return x + 10; };"); var source2 = engine.CreateScriptSourceFromString("def test(x) { super.test(x) + 15; };"); var scope = engine.CreateScope(); var scope2 = engine.CreateScope(); source.Execute(scope); source2.Execute(scope2); var testClassBase = new NovaClass("TestBase", global::Nova.Nova.Box(typeof(object)), new List <NovaFunction>(), new List <NovaFunction> { scope.GetVariable("test") }); dynamic testClass = new NovaClass("Test", testClassBase, new List <NovaFunction>(), new List <NovaFunction> { scope2.GetVariable("test") }); var x = testClass(); Assert.That((int)x.test(10), Is.EqualTo(35)); }
public void TestInvokeMemberIronRubyWithNewArg() { var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString("def new(z) { @y = z; }; def test(x) { return x + @y; };"); var scope = engine.CreateScope(); source.Execute(scope); dynamic testClass = new NovaClass("Test", global::Nova.Nova.Box(typeof(object)), new List <NovaFunction> { scope.GetVariable("new") }, new List <NovaFunction> { scope.GetVariable("test") }); scope.RemoveVariable("new"); scope.RemoveVariable("test"); scope.SetVariable("TestClass", testClass); var rubyengine = GetRuntime().GetEngine("IronRuby"); var rubysource = rubyengine.CreateScriptSourceFromString("x = nova.TestClass(22); x.test(17);"); var rubyscope = rubyengine.CreateScope(); rubyscope.SetVariable("nova", scope); Assert.That(rubysource.Execute(rubyscope), Is.EqualTo(39)); }
public void TestInvokeMemberMethodTable() { var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString("def test(x) { return x + 10; };"); var source2 = engine.CreateScriptSourceFromString("def test(x,y) { return x + y; };"); var scope = engine.CreateScope(); source.Execute(scope); var scope2 = engine.CreateScope(); source2.Execute(scope2); var testClass = new NovaClass("Test", global::Nova.Nova.Box(typeof(object)), new List <NovaFunction>(), new List <NovaFunction> { scope.GetVariable("test"), scope2.GetVariable("test") }); var nscope = engine.CreateScope(); nscope.SetVariable("Test", testClass); var nsource = engine.CreateScriptSourceFromString("x = Test(); x.test(17) + x.test(5,10);"); Assert.That(nsource.Execute(nscope), Is.EqualTo(42)); }
public void TestCustomOp() { var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString( "def new(x) { @x = x; }; def <==>(other) { return ((@x + other.x) / (other.x/2)); };"); var scope = engine.CreateScope(); source.Execute(scope); var testClass = new NovaClass("Test", global::Nova.Nova.Box(typeof(object)), new List <NovaFunction> { scope.GetVariable("new") }, new List <NovaFunction> { scope.GetVariable("<==>") }); scope.SetVariable("Test", testClass); scope.RemoveVariable("new"); scope.RemoveVariable("<==>"); source = engine.CreateScriptSourceFromString("x = Test(8); y = Test(8); x <==> y;"); Assert.That(source.Execute(scope), Is.EqualTo(4)); }
public void TestBoxExtensionIronRuby() { NovaClass strb = global::Nova.Nova.Box(typeof(StringBuilder)); var engine = GetRuntime().GetEngine("Nova"); var defsource = engine.CreateScriptSourceFromString( "def AppendFromNova() { self.Append('Appending from Nova extension method!'); };"); var defscope = engine.CreateScope(); defsource.Execute(defscope); NovaClass.AddMethod(strb.InstanceMethods, defscope.GetVariable("AppendFromNova")); var scope = engine.CreateScope(); scope.SetVariable("StringBuilder", strb); var str = new StringBuilder("Hello world! "); var strx = global::Nova.Nova.Box(str, new NovaScope(scope)); var rubyengine = GetRuntime().GetEngine("IronRuby"); var rubysource = rubyengine.CreateScriptSourceFromString("strx.AppendFromNova(); strx.ToString();"); var rubyscope = rubyengine.CreateScope(); rubyscope.SetVariable("strx", strx); Assert.That((string)rubysource.Execute(rubyscope), Is.EqualTo("Hello world! Appending from Nova extension method!")); }
public void TestSingleton() { var expect = new NovaArray { null, 5 }; var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString("def test(x) { return x + 10; };"); var scope = engine.CreateScope(); source.Execute(scope); var testClass = new NovaClass("Test", global::Nova.Nova.Box(typeof(object)), new List <NovaFunction>(), new List <NovaFunction> { scope.GetVariable("test") }); var nscope = engine.CreateScope(); nscope.SetVariable("Test", testClass); var nsource = engine.CreateScriptSourceFromString( "x = Test(); y = Test(); def x.single(y) { return y - 5; }; [y.single(10),x.single(10)];"); Assert.That(nsource.Execute(nscope), Is.EqualTo(expect)); }
public void TestNovaExportAttribute() { NovaClass klass = global::Nova.Nova.Box(typeof(ExportHelper)); var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString("x = Export(); x.test_me(13);"); var scope = engine.CreateScope(); scope.SetVariable(klass.Name, klass); Assert.That(source.Execute(scope), Is.EqualTo(40)); }
public void TestCSharpContructorMap() { NovaClass strb = global::Nova.Nova.Box(typeof(StringBuilder)); var engine = GetRuntime().GetEngine("Nova"); var defsource = engine.CreateScriptSourceFromString( "str = StringBuilder('Hello '); str.Append('from Nova!'); str.ToString();"); var defscope = engine.CreateScope(); defscope.SetVariable("StringBuilder", strb); Assert.That(defsource.Execute(defscope), Is.EqualTo("Hello from Nova!")); }
public void TestNovaDoNotExportAttribute() { NovaClass klass = global::Nova.Nova.Box(typeof(ExportHelper)); var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString("x = Export(); x.ShouldNotExport(10);"); var scope = engine.CreateScope(); scope.SetVariable(klass.Name, klass); object actual = source.Execute(scope); Assert.That(actual, Is.Null); }
public void TestNovaObjectBinaryCSharp() { var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString("def +(x) { return @x + x; };"); var scope = engine.CreateScope(); source.Execute(scope); dynamic testClass = new NovaClass("Test", global::Nova.Nova.Box(typeof(object)), new List <NovaFunction>(), new List <NovaFunction> { scope.GetVariable("+") }); var x = testClass(); x.x = 17; Assert.AreEqual(27, x + 10); }
public void TestNovaObjectBinary() { var engine = GetRuntime().GetEngine("Nova"); var source = engine.CreateScriptSourceFromString("def +(x) { return @x + x; };"); var scope = engine.CreateScope(); source.Execute(scope); var testClass = new NovaClass("Test", global::Nova.Nova.Box(typeof(object)), new List <NovaFunction>(), new List <NovaFunction> { scope.GetVariable("+") }); var nscope = engine.CreateScope(); nscope.SetVariable("Test", testClass); var nsource = engine.CreateScriptSourceFromString("x = Test(); x.x = 17; x + 10;"); Assert.That(nsource.Execute(nscope), Is.EqualTo(27)); }
public void TestCSharpClassExtend() { NovaClass strb = global::Nova.Nova.Box(typeof(StringBuilder)); var engine = GetRuntime().GetEngine("Nova"); var defsource = engine.CreateScriptSourceFromString( "def AppendFromNova() { self.Append('Appending from Nova extension method!'); };"); var defscope = engine.CreateScope(); defsource.Execute(defscope); NovaClass.AddMethod(strb.InstanceMethods, defscope.GetVariable("AppendFromNova")); var source = engine.CreateScriptSourceFromString( "str.AppendFormat('{0} world! ','hello'); str.AppendFromNova(); str.ToString();"); var scope = engine.CreateScope(); scope.SetVariable("str", new StringBuilder()); scope.SetVariable("StringBuilder", strb); Assert.That(source.Execute(scope), Is.EqualTo("hello world! Appending from Nova extension method!")); }
public static dynamic Box(Type type) { return(NovaClass.BoxClass(type)); }