2017-02-11 08:08:50 +01:00
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
#include <gmock/gmock-matchers.h>
|
2017-02-26 19:29:50 +01:00
|
|
|
|
#include "SqlLexer.h"
|
2017-02-11 08:08:50 +01:00
|
|
|
|
|
|
|
|
|
|
using namespace testing;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-26 19:29:50 +01:00
|
|
|
|
TEST(SqlLexer, lexer)
|
2017-02-11 08:08:50 +01:00
|
|
|
|
{
|
|
|
|
|
|
QString input = " SELECT ";
|
|
|
|
|
|
SqlLexer lexer(input, LexerState::Null);
|
|
|
|
|
|
|
|
|
|
|
|
int startpos, length;
|
|
|
|
|
|
BasicTokenType tokentype;
|
|
|
|
|
|
QString out;
|
|
|
|
|
|
lexer.nextBasicToken(startpos, length, tokentype, out);
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(startpos, Eq(1));
|
|
|
|
|
|
ASSERT_THAT(length, Eq(6));
|
|
|
|
|
|
ASSERT_THAT(tokentype, Eq(BasicTokenType::Symbol));
|
|
|
|
|
|
ASSERT_THAT( out, Eq(QString("SELECT")) );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-26 19:29:50 +01:00
|
|
|
|
TEST(SqlLexer, lexer_quote_in_string)
|
2017-02-12 08:13:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
QString input = " 'abc''def' ";
|
|
|
|
|
|
SqlLexer lexer(input, LexerState::Null);
|
|
|
|
|
|
|
|
|
|
|
|
int startpos, length;
|
|
|
|
|
|
BasicTokenType tokentype;
|
|
|
|
|
|
QString out;
|
|
|
|
|
|
lexer.nextBasicToken(startpos, length, tokentype, out);
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(startpos, Eq(1));
|
|
|
|
|
|
ASSERT_THAT(length, Eq(10));
|
|
|
|
|
|
ASSERT_THAT(tokentype, Eq(BasicTokenType::QuotedString));
|
|
|
|
|
|
}
|
|
|
|
|
|
|