public void Execute_NullScopeArgumentTest() { ScriptSource source = _testEng.CreateScriptSourceFromString( _codeSnippets[CodeType.SimpleExpressionOnePlusOne]); MyErrorListener errorListen = new MyErrorListener(); CompiledCode compiled = source.Compile(errorListen); Assert.IsTrue(errorListen._message == null); compiled.Execute((ScriptScope)null); }
public void Execute_ReturnExpressionValueNoArgs() { ScriptSource source = _PYEng.CreateScriptSourceFromString("1+1"); MyErrorListener errorListen = new MyErrorListener(); CompiledCode compiled = source.Compile(errorListen); Assert.IsTrue(errorListen._message == null); object result = compiled.Execute(); Assert.AreEqual(result, (object)2); }
public void Execute_GenericTypeCastSmokeTest() { ScriptSource source = _PYEng.CreateScriptSourceFromFile(TestHelpers.CreateTempSourceFile(_codeSnippets[CodeType.SimpleExpressionOnePlusOne], ".py")); MyErrorListener errorListen = new MyErrorListener(); CompiledCode compiled = source.Compile(errorListen); Assert.IsTrue(errorListen._message == null); // ScriptScope scope = _PYEng.CreateScope(); // double result = compiled.Execute<double>(scope); // Assert.AreEqual(result, (double)2); }
public void Execute_ReturnExpressionValueForDefaultScopeArg() { ScriptSource source = _PYEng.CreateScriptSourceFromString("x=1+1", SourceCodeKind.Statements); MyErrorListener errorListen = new MyErrorListener(); CompiledCode compiled = source.Compile(errorListen); Assert.IsTrue(errorListen._message == null); compiled.Execute(); // ScriptScope scope = compiled.DefaultScope(); // object result = scope.GetVariable("x"); // Assert.AreEqual(result, (object)2); }
public void Engine_Property_Validation() { ScriptSource source = _testEng.CreateScriptSourceFromFile(TestHelpers.CreateTempSourceFile( _codeSnippets[CodeType.OneLineAssignmentStatement], ".py")); MyErrorListener errorListen = new MyErrorListener(); CompiledCode compiled = source.Compile(errorListen); Assert.IsTrue(errorListen._message == null); ScriptScope scope = compiled.Engine.CreateScope(); compiled.Execute(scope); ScriptEngine engine = compiled.Engine; object result = scope.GetVariable("x"); // Verify that engine has the same scope? Assert.AreEqual(engine, _testEng); }
public void Execute_ReturnExpressionValueForScopeArg() { ScriptSource source = _testEng.CreateScriptSourceFromString( _codeSnippets[CodeType.SimpleExpressionOnePlusOne]); MyErrorListener errorListen = new MyErrorListener(); object result; int expectedResult = 2; CompiledCode compiled = source.Compile(errorListen); Assert.IsTrue(errorListen._message == null); ScriptScope scope = _testEng.CreateScope(); result = compiled.Execute(scope); Assert.AreEqual(result, (object)expectedResult); }
public void Execute_ReturnExpressionValueNoArgs_MultipleCalls() { ScriptSource source = _PYEng.CreateScriptSourceFromString( _codeSnippets[CodeType.SimpleExpressionOnePlusOne]); MyErrorListener errorListen = new MyErrorListener(); CompiledCode compiled = source.Compile(errorListen); Assert.IsTrue(errorListen._message == null); object result; int testLoops = 10; int expectedResult = 2; for (int i = 0; i < testLoops; i++) { result = compiled.Execute(); Assert.AreEqual(result, (object)expectedResult); } }
public void Execute_AccessVarPreDefinedInScope() { ScriptScopeDictionary env = new ScriptScopeDictionary(); env["k"] = (object)1; ScriptSource source = _testEng.CreateScriptSourceFromString(_codeSnippets[CodeType.OneLineAssignmentStatement] + "\nw=k+x", SourceCodeKind.Statements); MyErrorListener errorListen = new MyErrorListener(); CompiledCode compiled = source.Compile(errorListen); Assert.IsTrue(errorListen._message == null); ScriptScope scope = _testEng.CreateScope(new ObjectDictionaryExpando(env)); compiled.Execute(scope); object result = scope.GetVariable("x"); Assert.AreEqual(result, (object)3); result = scope.GetVariable("w"); Assert.AreEqual(result, (object)4); }
public void Execute_ManyTimesUsingDelegate() { ScriptSource source = _testEng.CreateScriptSourceFromString(_codeSnippets[CodeType.FactorialFunc], SourceCodeKind.Statements); MyErrorListener errorListen = new MyErrorListener(); // Check the values of in errorListen for specific error info CompiledCode compiled = source.Compile(errorListen); Assert.IsTrue(errorListen._message == null); ScriptScope scope = _testEng.CreateScope(); compiled.Execute(scope); Func<double, double> fact = scope.GetVariable<Func<double, double>>("fact"); int testLoops = 10; double result; for (int i = 0; i < testLoops; i++) { result = fact((double)i); Assert.IsTrue(result > 0); } }
public void Execute_ManyTimesUsingDelegate() { ScriptSource source = _testEng.CreateScriptSourceFromString(_codeSnippets[CodeType.FactorialFunc], SourceCodeKind.Statements); MyErrorListener errorListen = new MyErrorListener(); // Check the values of in errorListen for specific error info CompiledCode compiled = source.Compile(errorListen); Assert.IsTrue(errorListen._message == null); ScriptScope scope = _testEng.CreateScope(); compiled.Execute(scope); Func <double, double> fact = scope.GetVariable <Func <double, double> >("fact"); int testLoops = 10; double result; for (int i = 0; i < testLoops; i++) { result = fact((double)i); Assert.IsTrue(result > 0); } }