Exemple #1
0
            public void ShouldBeAppliedIfFunctionDoesNotEndWithReturn()
            {
                var block     = new AstBlock(null);
                var lambdaAst = new AstParameterlessLambda(block, null);

                block.Expressions.Add(
                    new AstFunctionCall("println", new List <AstExpression>
                {
                    new AstBinaryMathOperation(BinaryMath.Plus,
                                               new AstIntegerConstant(5, null),
                                               new AstIntegerConstant(5, null),
                                               null)
                }, null));
                block.Expressions.Add(
                    new AstFunctionCall("println", new List <AstExpression>
                {
                    new AstStringConstant("hello world", null)
                }, null)
                    );

                var env = new ScriptEnvironment(new OperationCodeFactory(), new ValueFactory());

                Compiler.Compile(env,
                                 new AstRoot(new Position(0, 0))
                {
                    Expressions = { lambdaAst }
                });
                Assert.Equal(typeof(Return),
                             env.Functions[GetGlobalName(Compiler.GetAnonymousFunctionName(1))].Code.Last().Op.GetType());
            }
Exemple #2
0
            public void ShouldBeAppliedIfFunctionIsEmpty()
            {
                var lambdaAst = new AstParameterlessLambda(new AstBlock(null), null);
                var env       = new ScriptEnvironment(new OperationCodeFactory(), new ValueFactory());

                Compiler.Compile(env,
                                 new AstRoot(new Position(0, 0))
                {
                    Expressions = { lambdaAst }
                });
                Assert.Equal(typeof(Return),
                             env.Functions[GetGlobalName(Compiler.GetAnonymousFunctionName(1))].Code.Last().Op.GetType());
            }