Exemple #1
0
        public async Task TestTokenSequenceBlock()
        {
            var program =
                @"int main() {
                    printf(""Hello, world!\n"");
                }";
            var tu    = new TranslationUnit(new FileResolver(), "test.c");
            var lexer = Lexer.AsBlock(tu, false, false);

            await lexer.PostAllTextAsync(new StringReader(program));

            lexer.Complete();
            var tokens = (await lexer.ReceiveAllAsync().AsList());

            Assert.Empty(tu.Errors);
            Assert.Equal(new[] {
                Int, Identifier, LeftParen, RightParen, LeftBrace,
                Identifier, LeftParen, StringLiteral, RightParen, Semicolon,
                RightBrace,
                Eof
            }, tokens.Terminals());

            Assert.Equal(new[] {
                "int", "main", "(", ")", "{",
                "printf", "(", "Hello, world!\n", ")", ";",
                "}",
                "end-of-file"
            }, tokens.Select(t => t.ToString()));
        }