public void ShouldBeAppliedIfFunctionDoesNotEndWithReturn() { const string name = "test"; var funcAst = new AstMemberFunction(name, new List <Parameter>(), new Position(0, 0)); funcAst.Expressions.Add( new AstFunctionCall("println", new List <AstExpression> { new AstBinaryMathOperation(BinaryMath.Plus, new AstIntegerConstant(5, null), new AstIntegerConstant(5, null), null) }, null)); funcAst.Expressions.Add( new AstFunctionCall("println", new List <AstExpression> { new AstStringConstant("hello world", null) }, null) ); var klass = new AstClass(name, null); klass.Functions.Add(funcAst); var env = new ScriptEnvironment(new OperationCodeFactory(), new ValueFactory()); Compiler.Compile(env, new AstRoot(new Position(0, 0)) { Classes = { klass } }); Assert.Equal(typeof(Return), env.Classes[GetGlobalName(name)].Functions[name].Code.Last().Op.GetType()); }
public void ShouldBeAppliedIfFunctionIsEmpty() { const string name = "test"; var funcAst = new AstMemberFunction(name, new List <Parameter>(), new Position(0, 0)); var klass = new AstClass(name, null); klass.Functions.Add(funcAst); var env = new ScriptEnvironment(new OperationCodeFactory(), new ValueFactory()); Compiler.Compile(env, new AstRoot(new Position(0, 0)) { Classes = { klass } }); Assert.Equal(typeof(Return), env.Classes[GetGlobalName(name)].Functions[name].Code.Last().Op.GetType()); }