163 lines
3.6 KiB
C++
163 lines
3.6 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);
|
|
}
|
|
|
|
TEST(ConvertLangToSqlString, testWideLiteralL)
|
|
{
|
|
QString in(R"__( L"SELECT" )__");
|
|
QString expected(R"__(SELECT)__");
|
|
|
|
auto output = ConvertLangToSqlString(in);
|
|
ASSERT_EQ(output, expected);
|
|
}
|
|
|
|
TEST(ConvertLangToSqlString, testWideLiteralU)
|
|
{
|
|
QString in(R"__( U"SELECT" )__");
|
|
QString expected(R"__(SELECT)__");
|
|
|
|
auto output = ConvertLangToSqlString(in);
|
|
ASSERT_EQ(output, expected);
|
|
}
|
|
|
|
TEST(ConvertLangToSqlString, testUtf16Literal)
|
|
{
|
|
QString in(R"__( u"SELECT" )__");
|
|
QString expected(R"__(SELECT)__");
|
|
|
|
auto output = ConvertLangToSqlString(in);
|
|
ASSERT_EQ(output, expected);
|
|
}
|
|
|
|
TEST(ConvertLangToSqlString, testUtf8Literal)
|
|
{
|
|
QString in(R"__( u8"SELECT" )__");
|
|
QString expected(R"__(SELECT)__");
|
|
|
|
auto output = ConvertLangToSqlString(in);
|
|
ASSERT_EQ(output, expected);
|
|
}
|
|
|
|
TEST(ConvertLangToSqlString, testPrefixedLiteralConcat)
|
|
{
|
|
QString in(R"__( L"A" + "B" )__");
|
|
QString expected(R"__(AB)__");
|
|
|
|
auto output = ConvertLangToSqlString(in);
|
|
ASSERT_EQ(output, expected);
|
|
}
|
|
|
|
TEST(ConvertLangToSqlString, testUnicodeEscapeBmp)
|
|
{
|
|
QString in(R"__( "\U00000041" )__");
|
|
QString expected(R"__(A)__");
|
|
|
|
auto output = ConvertLangToSqlString(in);
|
|
ASSERT_EQ(output, expected);
|
|
}
|
|
|
|
TEST(ConvertLangToSqlString, testUnicodeEscapeSurrogatePair)
|
|
{
|
|
QString in(R"__( "\U0001F600" )__");
|
|
QString expected = QString::fromUcs4(U"\U0001F600");
|
|
|
|
auto output = ConvertLangToSqlString(in);
|
|
ASSERT_EQ(output, expected);
|
|
}
|
|
|
|
TEST(ConvertLangToSqlString, testUnicodeEscapeOutOfRange)
|
|
{
|
|
QString in(R"__( "AB\U00110000CD" )__");
|
|
QString expected(R"__(AB)__");
|
|
|
|
auto output = ConvertLangToSqlString(in);
|
|
ASSERT_EQ(output, expected);
|
|
}
|
|
|
|
TEST(ConvertLangToSqlString, testUnicodeEscapeSurrogateCodePoint)
|
|
{
|
|
QString in(R"__( "AB\U0000D800CD" )__");
|
|
QString expected(R"__(AB)__");
|
|
|
|
auto output = ConvertLangToSqlString(in);
|
|
ASSERT_EQ(output, expected);
|
|
}
|
|
|
|
TEST(ConvertLangToSqlString, testHexEscapeInvalidDigit)
|
|
{
|
|
QString in(R"__( "AB\x4GCD" )__");
|
|
QString expected(R"__(AB)__");
|
|
|
|
auto output = ConvertLangToSqlString(in);
|
|
ASSERT_EQ(output, expected);
|
|
}
|
|
|
|
//TEST(ConvertLangToSqlString, testComment)
|
|
//{
|
|
// QString in(R"__( "SELECT * " // comment
|
|
// "FROM t"; )__");
|
|
// QString expected(R"__(SELECT *
|
|
//FROM t)__");
|
|
|
|
// auto output = ConvertLangToSqlString(in);
|
|
// ASSERT_EQ(output, expected);
|
|
//}
|