Exemplo n.º 1
0
        public async Task TestWhitespaceAndNewlines()
        {
            var program = "   \t\r\t\r\n\t\n\n";
            var lexer   = new Lexer(
                new TranslationUnit(new FileResolver(), "test.c"),
                new CharacterStream(new StringReader(program)),
                false, true);

            var tokens = await lexer.AsList();

            Assert.Empty(lexer.TranslationUnit.Errors);
            Assert.Equal(new[] {
                Whitespace, Newline, Whitespace, Newline, Whitespace, Newline, Newline,
                Eof
            }, tokens.Terminals());
        }
Exemplo n.º 2
0
        public async Task TestUnterminatedComment2Fails()
        {
            var program = @"/**unterminated**";
            var lexer   = new Lexer(
                new TranslationUnit(new FileResolver(), "test.c"),
                new CharacterStream(new StringReader(program)),
                false, true);

            var tokens = await lexer.AsList();

            Assert.Collection(lexer.TranslationUnit.Errors, e => Assert.Contains("Unterminated", e.Message));
            Assert.Equal(new[] {
                Comment,
                Eof
            }, tokens.Terminals());
            Assert.Equal(new[] {
                "*unterminated**",
                "end-of-file"
            }, tokens.Select(t => t.ToString()));
        }
Exemplo n.º 3
0
        public async Task TestComments()
        {
            var program = @"// Hello,
                            /**** World! ****/";
            var lexer   = new Lexer(
                new TranslationUnit(new FileResolver(), "test.c"),
                new CharacterStream(new StringReader(program)),
                false, true);

            var tokens = await lexer.AsList();

            Assert.Empty(lexer.TranslationUnit.Errors);
            Assert.Equal(new[] {
                Comment, Newline, Whitespace, Comment,
                Eof
            }, tokens.Terminals());
            Assert.Equal(new[] {
                "Hello,", "*** World! ***"
            }, tokens.Where(t => t.Kind == Comment).Select(t => t.ToString()));
        }