Save position and length of tokens
This commit is contained in:
@@ -73,7 +73,7 @@ TEST_CASE( "Lex Whitespace", "[lexer]" ) {
|
||||
CHECK(lexer.LexNext('\f') -> GetKind() == TokenKind::WhiteSpace);
|
||||
}
|
||||
|
||||
TEST_CASE( "Lex Basic Integers", "[lexer]" ) {
|
||||
TEST_CASE( "Lex Basic Digits", "[lexer]" ) {
|
||||
Lexer lexer = Lexer("");
|
||||
CHECK(lexer.LexNext('0') -> GetKind() == TokenKind::Integer);
|
||||
CHECK(lexer.LexNext('1') -> GetKind() == TokenKind::Integer);
|
||||
@@ -255,4 +255,32 @@ TEST_CASE( "Lex identifier", "[lexer]" ) {
|
||||
REQUIRE(firstToken -> GetKind() == TokenKind::Identifier);
|
||||
REQUIRE(((IdentifierToken*)firstToken) -> Value == "foo");
|
||||
}
|
||||
|
||||
TEST_CASE( "Lex Start Position", "[lexer]" ) {
|
||||
Lexer lexer = Lexer("+ - bar 1234");
|
||||
auto tokens = lexer.Lex();
|
||||
REQUIRE(tokens.size() == 8);
|
||||
CHECK(((IdentifierToken*)tokens[0]) -> GetStartPosition() == 0);
|
||||
CHECK(((IdentifierToken*)tokens[1]) -> GetStartPosition() == 1);
|
||||
CHECK(((IdentifierToken*)tokens[2]) -> GetStartPosition() == 2);
|
||||
CHECK(((IdentifierToken*)tokens[3]) -> GetStartPosition() == 3);
|
||||
CHECK(((IdentifierToken*)tokens[4]) -> GetStartPosition() == 4);
|
||||
CHECK(((IdentifierToken*)tokens[5]) -> GetStartPosition() == 7);
|
||||
CHECK(((IdentifierToken*)tokens[6]) -> GetStartPosition() == 8);
|
||||
CHECK(((IdentifierToken*)tokens[7]) -> GetStartPosition() == 12);
|
||||
}
|
||||
|
||||
TEST_CASE( "Lex End Position", "[lexer]" ) {
|
||||
Lexer lexer = Lexer("+ - bar 1234");
|
||||
auto tokens = lexer.Lex();
|
||||
REQUIRE(tokens.size() == 8);
|
||||
CHECK(((IdentifierToken*)tokens[0]) -> GetEndPosition() == 0);
|
||||
CHECK(((IdentifierToken*)tokens[1]) -> GetEndPosition() == 1);
|
||||
CHECK(((IdentifierToken*)tokens[2]) -> GetEndPosition() == 2);
|
||||
CHECK(((IdentifierToken*)tokens[3]) -> GetEndPosition() == 3);
|
||||
CHECK(((IdentifierToken*)tokens[4]) -> GetEndPosition() == 6);
|
||||
CHECK(((IdentifierToken*)tokens[5]) -> GetEndPosition() == 7);
|
||||
CHECK(((IdentifierToken*)tokens[6]) -> GetEndPosition() == 11);
|
||||
CHECK(((IdentifierToken*)tokens[7]) -> GetEndPosition() == 12);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user