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);
|
|
|
|
|
|
|
2017-08-26 19:07:01 +02:00
|
|
|
|
ASSERT_EQ(startpos, 1);
|
|
|
|
|
|
ASSERT_EQ(length, 6);
|
|
|
|
|
|
ASSERT_EQ(tokentype, BasicTokenType::Symbol);
|
|
|
|
|
|
ASSERT_EQ( out, QString("SELECT") );
|
2017-02-11 08:08:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-26 19:29:50 +01:00
|
|
|
|
TEST(SqlLexer, lexer_quote_in_string)
|
2017-02-12 08:13:38 +01:00
|
|
|
|
{
|
2017-08-26 19:07:01 +02:00
|
|
|
|
QString input = " 'abc''def' ";
|
|
|
|
|
|
SqlLexer lexer(input, LexerState::Null);
|
|
|
|
|
|
|
|
|
|
|
|
int startpos, length;
|
|
|
|
|
|
BasicTokenType tokentype;
|
|
|
|
|
|
QString out;
|
|
|
|
|
|
lexer.nextBasicToken(startpos, length, tokentype, out);
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(startpos, 1);
|
|
|
|
|
|
ASSERT_EQ(length, 10);
|
|
|
|
|
|
ASSERT_EQ(tokentype, BasicTokenType::QuotedString);
|
2017-02-12 08:13:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|