Exemplo n.º 1
0
        public void Should_Parse_Function()
        {
            // Arrange
            var expected = new[]
            {
                TokenType.Function,
                TokenType.Int,
                TokenType.Identifier,
                TokenType.ParenOpen,
                TokenType.Char,
                TokenType.Identifier,
                TokenType.Comma,
                TokenType.Boolean,
                TokenType.Identifier,
                TokenType.ParenClose,
                TokenType.CurlyOpen,
                TokenType.CurlyClose,
                TokenType.Eof,
            };

            var code = "function int parseInt(char a, boolean b) {}";
            IEnumerable <Token> tokenSource = new Core.Lexer.Lexer(code);

            // Act
            var result = tokenSource.Select(t => t.Type).ToArray();

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 2
0
        public void Should_Skip_OneLineComments()
        {
            // Arrange
            var expected = new[]
            {
                TokenType.Eof,
            };

            var code = @"   // some comments    ";
            IEnumerable <Token> tokenSource = new Core.Lexer.Lexer(code);

            // Act
            var result = tokenSource.Select(t => t.Type).ToArray();

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 3
0
        public void Should_Parse_StringLiterals_DoubleQuotes()
        {
            // Arrange
            var expected = new[]
            {
                TokenType.Var,
                TokenType.Identifier,
                TokenType.Assign,
                TokenType.String,
                TokenType.Eof,
            };

            var code = " var a = \"text\"";
            IEnumerable <Token> tokenSource = new Core.Lexer.Lexer(code);

            // Act
            var result = tokenSource.Select(t => t.Type).ToArray();

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 4
0
        public void Should_Parse_Let()
        {
            // Arrange
            var expected = new[]
            {
                TokenType.Let,
                TokenType.Identifier,
                TokenType.Assign,
                TokenType.Number,
                TokenType.Eof
            };

            var code = "let a = 1";
            IEnumerable <Token> tokenSource = new Core.Lexer.Lexer(code);

            // Act
            var result = tokenSource.Select(t => t.Type).ToArray();

            // Assert
            Assert.AreEqual(expected, result);
        }