pgLab/tests/pglabtests/tst_ConvertLangToSqlString.cpp
eelke 48ac8c6bab Improved generation of c/cpp string from query
Extra lines before and after query are removed. Whitespace at end of line
is removed. SQL comments are converted to cpp style comments and are outside
the string literal.

To achieve this the function now uses the SQLLexer to know what is comment.
This also required the additional capability in the lexer to also return whitespace and newline tokens.
Also a few bugs in the lexer were fixed.
2019-08-19 13:52:23 +02:00

62 lines
1.3 KiB
C++

#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>
#include "util.h"
#include "PrintTo_Qt.h"
using namespace testing;
TEST(ConvertLangToSqlString, simple)
{
QString in(R"__( "SELECT" )__");
QString expected(R"__(SELECT)__");
auto output = ConvertLangToSqlString(in);
ASSERT_EQ(output, expected);
}
TEST(ConvertLangToSqlString, testEscapedQuote)
{
QString in(R"__( "SELECT\"" )__");
QString expected(R"__(SELECT")__");
auto output = ConvertLangToSqlString(in);
ASSERT_EQ(output, expected);
}
TEST(ConvertLangToSqlString, testEscapedNewLine)
{
QString in(R"__( "SELECT\nFROM" )__");
QString expected(R"__(SELECT
FROM)__");
auto output = ConvertLangToSqlString(in);
ASSERT_EQ(output, expected);
}
TEST(ConvertLangToSqlString, testConcatPlus)
{
QString in(R"__( "SELECT" + " FROM" )__");
QString expected(R"__(SELECT FROM)__");
auto output = ConvertLangToSqlString(in);
ASSERT_EQ(output, expected);
}
TEST(ConvertLangToSqlString, testConcatDot)
{
QString in(R"__( "SELECT"." FROM" )__");
QString expected(R"__(SELECT FROM)__");
auto output = ConvertLangToSqlString(in);
ASSERT_EQ(output, expected);
}
TEST(ConvertLangToSqlString, testSemiColon)
{
QString in(R"__( "SELECT"." FROM"; )__");
QString expected(R"__(SELECT FROM)__");
auto output = ConvertLangToSqlString(in);
ASSERT_EQ(output, expected);
}