Ejemplo n.º 1
0
        public void FunctionWithoutArguments()
        {
            // Create the token stream.
            TokenStream stream = new TokenStream(new Token[]
            {
                // Program starting point token.
                new Token {
                    Type = TokenType.Unknown
                },

                new Token {
                    Type  = TokenType.TypeInt,
                    Value = "int"
                },

                new Token {
                    Type  = TokenType.Identifier,
                    Value = "test"
                },

                new Token {
                    Type  = TokenType.SymbolParenthesesL,
                    Value = "("
                },

                new Token {
                    Type  = TokenType.SymbolParenthesesR,
                    Value = ")"
                },

                new Token {
                    Type  = TokenType.SymbolBlockL,
                    Value = "{"
                },

                new Token {
                    Type  = TokenType.SymbolBlockR,
                    Value = "}"
                }
            });

            // Read the expected output IR code.
            string expected = TestUtil.ReadOutputDataFile("FunctionWithoutArguments");

            // Invoke the function parser.
            Function function = new FunctionParser().Parse(stream);

            // Emit the function.
            function.Emit(this.module.Source);

            // Emit the module.
            string output = this.module.ToString();

            System.Console.WriteLine(output);

            // Compare stored IR code with the actual, emitted output.
            Assert.AreEqual(expected, output);
        }