From 3b482c1c73ae806cd79e04e9f7dd01ddcaede458 Mon Sep 17 00:00:00 2001 From: eelke Date: Mon, 28 Jan 2019 20:52:39 +0100 Subject: [PATCH] Fix lexer for empty input. --- core/SqlLexer.cpp | 4 +++- core/SqlLexer.h | 2 +- tests/pglabtests/tst_SqlLexer.cpp | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/SqlLexer.cpp b/core/SqlLexer.cpp index 62e3036..b6b7986 100644 --- a/core/SqlLexer.cpp +++ b/core/SqlLexer.cpp @@ -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); diff --git a/core/SqlLexer.h b/core/SqlLexer.h index 61e551c..b9db567 100644 --- a/core/SqlLexer.h +++ b/core/SqlLexer.h @@ -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; } diff --git a/tests/pglabtests/tst_SqlLexer.cpp b/tests/pglabtests/tst_SqlLexer.cpp index d466d62..72a1474 100644 --- a/tests/pglabtests/tst_SqlLexer.cpp +++ b/tests/pglabtests/tst_SqlLexer.cpp @@ -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) {