Fix lexer for empty input.

This commit is contained in:
eelke 2019-01-28 20:52:39 +01:00
parent 077fae50af
commit 3b482c1c73
3 changed files with 17 additions and 2 deletions

View file

@ -148,7 +148,9 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent
// m_state = LexerState::InBlockComment;
// }
else if (c == QChar::Null) {
break;
length = 0;
tokentype = BasicTokenType::End;
return true;
}
else if (c == '$') {
return parseDollarQuote(startpos, length, tokentype, out);

View file

@ -52,7 +52,7 @@ public:
SqlToken nextBasicToken()
{
SqlToken token;
token.ok = !nextBasicToken(token.startPos, token.length, token.tokenType, token.out);
token.ok = nextBasicToken(token.startPos, token.length, token.tokenType, token.out);
return token;
}

View file

@ -5,6 +5,19 @@
using namespace testing;
TEST(SqlLexer, emptyInput)
{
QString input;
SqlLexer lexer(input, LexerState::Null);
int startpos, length;
BasicTokenType tokentype;
QString out;
lexer.nextBasicToken(startpos, length, tokentype, out);
ASSERT_THAT(startpos, Eq(0));
ASSERT_THAT(tokentype, Eq(BasicTokenType::End));
}
TEST(SqlLexer, lexer)
{