Exemplo n.º 1
0
        public void IfBindingTest()
        {
            const string Code =
                @"
            Var x = 4;
            If x == 4
            {
                Output(""*sigh* everything alright"");
            }
            Else
            {
                Output(""Help, 4 != 4 ;-;"");
            }
            ";

            Compilation tree = MyAssert.NoError(Code);

            Assert.AreEqual(2, tree.Program.TopLevelStatementNodes.Count);

            Assert.IsTrue(tree.Program.TopLevelStatementNodes[1] is IfStatementNode
            {
                ConditionNode: BinaryOperationExpressionNode
                {
                    LeftOperandNode: IdentifierExpressionNode
                    {
                        IdentifierNode: BoundIdentifierNode
                        {
                            Symbol: VariableSymbolNode
                            {
                                Identifier: "x"
                            }
                        }
                    }
                }
            });
Exemplo n.º 2
0
        private void AssertCorrectOutput(string code, string expectedOutput)
        {
            var         comp        = MyAssert.NoError(code);
            RunProvider runProvider = new(comp, template);
            string      output      = runProvider.RunAndGetOutputAsync().GetAwaiter().GetResult().Trim();

            Assert.AreEqual(output, expectedOutput);
        }
Exemplo n.º 3
0
        public void ForTest()
        {
            const string Code = @"
            For Var i = 0 While True { }
            ";

            var c = MyAssert.NoError(Code);
            var o = CodeGenerator.GenerateCode(c, template: "", CodeGenerationMode.ToFile);

            MyAssert.EmittedCorrectTopLevelStatement("for(let i=0;true;i++){}", o);
        }
Exemplo n.º 4
0
        public void ImplicitStringConversionTest()
        {
            string[] literals = { @"""string""", "4", "'y'", "3.14", "4i", "True" };

            foreach (string l in literals)
            {
                string code = $@"
                Output({l});
                ";

                MyAssert.NoError(code);
            }
        }
Exemplo n.º 5
0
        public void ReturnNoExpressionTest()
        {
            const string Code = @"
            Return;
            ";

            ProgramNode program = MyAssert.NoError(() =>
            {
                var lexemes = new Lexer(Code).LexAll();
                var parser  = new ProgramParser(lexemes, Code);
                return(parser.ParseWholeProgram());
            });

            Assert.NotNull(program);
            Assert.AreEqual(1, program !.TopLevelStatementNodes.Count);
            Assert.IsTrue(program.TopLevelStatementNodes[0] is ReturnStatementNode
            {
                ReturnExpressionNode: null
            });
Exemplo n.º 6
0
        public void FunctionDeclarationNoParametersWithReturnTest()
        {
            const string Code = @"
            Func HelloWorld() As Int
            {
                Output(""Hello "" + x);
            }
            ";

            FunctionDeclarationNode func = MyAssert.NoError(() =>
            {
                var lexemes = new Lexer(Code).LexAll();
                var parser  = new ProgramParser(lexemes, Code);
                return(parser.ParseFunctionDeclaration());
            });

            Assert.NotNull(func);
            Assert.AreEqual("HelloWorld", func !.Identifier);
            Assert.AreEqual(0, func.ParameterNodes.Count);
            Assert.NotNull(func.ReturnTypeNode);
            Assert.AreEqual(1, func.BodyNode.Count);
        }