Created
September 13, 2020 08:07
-
-
Save gaufung/10634531011cb336d75debbf2546b276 to your computer and use it in GitHub Desktop.
Lexer Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Test] | |
| public void TestLexerNextToken() | |
| { | |
| string input = @"1 + 2 * (12 - 6) / 3 + 2 ^ 3 | |
| + ((4+3) * 4) | |
| / 4 | |
| "; | |
| var tests = new[] | |
| { | |
| new Token {Type = TokenType.INT, Literal="1"}, | |
| new Token {Type = TokenType.PLUS, Literal="+"}, | |
| new Token {Type = TokenType.INT, Literal="2"}, | |
| new Token {Type = TokenType.MULTIPLY, Literal="*"}, | |
| new Token {Type = TokenType.LPAREN, Literal="("}, | |
| //.... | |
| }; | |
| Lexer lexer = new Lexer(input); | |
| foreach (var tt in tests) | |
| { | |
| var actualToken = lexer.NextToken(); | |
| Assert.AreEqual(tt.Type, actualToken.Type, $"expect TokenType {tt.Type}, got {actualToken.Type}"); | |
| Assert.AreEqual(tt.Literal, actualToken.Literal, $"expect Token's Literal {tt.Literal}, got {actualToken.Literal}"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment