From 96e031edd74e8e1eaea79d95320637eb27e8e2ba Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sat, 7 Jan 2023 20:46:02 +0200 Subject: [PATCH] QDateTimeParser: add more unittests for the unquote() static helper Test documented behavior and serv as a baseline for future changes. Change-Id: I36a914694d5244c89f28f3e403e11d65492a5eef Reviewed-by: Edward Welbourne --- src/corelib/time/qdatetimeparser.cpp | 2 +- tests/auto/corelib/time/qdate/tst_qdate.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index b8fbb7e03aa..5c3574f3789 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -371,9 +371,9 @@ static qsizetype digitCount(QStringView str) not escaped and removes the escaping on those that are escaped */ - static QString unquote(QStringView str) { + // ### Align unquoting format strings for both from/toString(), QTBUG-110669 const QLatin1Char quote('\''); const QLatin1Char slash('\\'); const QLatin1Char zero('0'); diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index eb92337efb2..a462189b8e9 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -1354,11 +1354,23 @@ void tst_QDate::fromStringFormat_data() QTest::newRow("lateMarch") << QString("9999-03-06") << QString("yyyy-MM-dd") << QDate(9999, 3, 6); QTest::newRow("late") << QString("9999-12-31") << QString("yyyy-MM-dd") << QDate(9999, 12, 31); + QTest::newRow("quoted-dd") << QString("21dd-05-2006") << QString("dd'dd'-MM-yyyy") + << QDate(2006, 5, 21); + QTest::newRow("quoted-MM") << QString("21-MM05-2006") << QString("dd-'MM'MM-yyyy") + << QDate(2006, 5, 21); + QTest::newRow("quotes-empty") << QString("21-'05-2006") << QString("dd-MM-''yy") + << QDate(2006, 5, 21); + // Test unicode handling. QTest::newRow("Unicode in format string") << QString(u8"2020🤣09🤣21") << QString(u8"yyyy🤣MM🤣dd") << QDate(2020, 9, 21); - QTest::newRow("Unicode in quoted format string") + QTest::newRow("Unicode-in-format-string-quoted-emoji") << QString(u8"🤣🤣2020👍09🤣21") << QString(u8"'🤣🤣'yyyy👍MM🤣dd") << QDate(2020, 9, 21); + QTest::newRow("Unicode-in-quoted-dd-format-string") + << QString(u8"🤣🤣2020👍09🤣21dd") << QString(u8"🤣🤣yyyy👍MM🤣dd'dd'") << QDate(2020, 9, 21); + QTest::newRow("Unicode-in-all-formats-quoted-string") + << QString(u8"🤣🤣yyyy2020👍MM09🤣21dd") << QString(u8"🤣🤣'yyyy'yyyy👍'MM'MM🤣dd'dd'") + << QDate(2020, 9, 21); // QTBUG-84334 QTest::newRow("-ve year: front, nosep") @@ -1441,6 +1453,8 @@ void tst_QDate::fromStringFormat() QFETCH(QDate, expected); QDate dt = QDate::fromString(string, format); + QEXPECT_FAIL("quotes-empty", "QTBUG-110669: doubled single-quotes in format mishandled", + Continue); QCOMPARE(dt, expected); } #endif // datetimeparser