Fix lexer calculing hex number length 1 too long

This commit is contained in:
Jan 2021-02-14 10:24:23 +01:00
parent e40f1ec0b7
commit e277de4517
2 changed files with 20 additions and 1 deletions

View File

@ -177,7 +177,7 @@ protected:
if (numberLength == 0 || isalnum(*end) || *end == '_')
throw ParsingException(GetPreviousCharacterPos(), "Invalid hex number");
m_current_line_offset += numberLength;
m_current_line_offset += numberLength - 1;
}
_NODISCARD bool IsIntegerNumber() const

View File

@ -92,6 +92,25 @@ namespace test::parsing::header::impl::header_lexer
REQUIRE(lexer.GetToken(0).m_type == HeaderParserValueType::END_OF_FILE);
}
TEST_CASE("HeaderLexer: Ensure can parse simple hex numbers surrounded by symbols", "[parsing][header]")
{
const std::vector<std::string> lines
{
"0x25:0xABC,0x1a4",
};
MockParserLineStream mockStream(lines);
HeaderLexer lexer(&mockStream);
ExpectIntegerToken(lexer, 0x25);
ExpectCharacterToken(lexer, ':');
ExpectIntegerToken(lexer, 0xABC);
ExpectCharacterToken(lexer, ',');
ExpectIntegerToken(lexer, 0x1a4);
REQUIRE(lexer.GetToken(0).m_type == HeaderParserValueType::END_OF_FILE);
}
TEST_CASE("HeaderLexer: Ensure throws exception when parsing incomplete hex number", "[parsing][header]")
{
const std::vector<std::string> lines