Refactor ConvertLangToSqlString and fix couple of bugs. Verify with unit tests.

This commit is contained in:
eelke 2026-10-18 15:58:13 +02:00
parent 5821c23439
commit 6206d02c20
2 changed files with 248 additions and 218 deletions

View file

@ -61,6 +61,96 @@ TEST(ConvertLangToSqlString, testSemiColon)
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