diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-07-16 20:15:31 +0300 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-07-22 20:48:00 +0300 |
commit | c4b40f45032cbe14fbdf6fba4d25fb793b2ea857 (patch) | |
tree | 2b8d7b43fdd7126090286592fe2084202f90f196 /tests/auto/corelib/text/qstring/tst_qstring.cpp | |
parent | 19c70f40d257d528df65fac44eb847676425d03f (diff) |
QString: use _data based testing for trimmed
The same _data() will be re-used with trim().
Change-Id: Ie9b794b7e8d40552d9cacb71df0f8a151d4348a5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/text/qstring/tst_qstring.cpp')
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 010216e787..53ae89d41e 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -536,6 +536,7 @@ private slots: void simplified_data(); void simplified(); + void trimmed_data(); void trimmed(); void unicodeTableAccess_data(); void unicodeTableAccess(); @@ -2802,30 +2803,37 @@ void tst_QString::toCaseFolded() } } -void tst_QString::trimmed() +void tst_QString::trimmed_data() { - QString a; + QTest::addColumn<QString>("full" ); + QTest::addColumn<QString>("trimmed" ); - QVERIFY(a.trimmed().isNull()); // lvalue - QVERIFY(QString().trimmed().isNull()); // rvalue - QVERIFY(!a.isDetached()); + QTest::addRow("null") << QString() << QString(); + QTest::addRow("simple") << u"Text"_s << u"Text"_s; + QTest::addRow("single-space") << u" "_s << u""_s; + QTest::addRow("single-char") << u" a "_s << u"a"_s; + QTest::addRow("mixed") << u" a \t\n\v b "_s << u"a \t\n\v b"_s; +} - a = u"Text"_s; - QCOMPARE(a, QLatin1String("Text")); - QCOMPARE(a.trimmed(), QLatin1String("Text")); - QCOMPARE(a, QLatin1String("Text")); - a= u" "_s; - QCOMPARE(a.trimmed(), QLatin1String("")); - QCOMPARE(a, QLatin1String(" ")); - a = u" a "_s; - QCOMPARE(a.trimmed(), QLatin1String("a")); - - a = u"Text"_s; - QCOMPARE(std::move(a).trimmed(), QLatin1String("Text")); - a = u" "_s; - QCOMPARE(std::move(a).trimmed(), QLatin1String("")); - a = u" a "_s; - QCOMPARE(std::move(a).trimmed(), QLatin1String("a")); +void tst_QString::trimmed() +{ + QFETCH(QString, full); + QFETCH(QString, trimmed); + + // Shared + if (!full.isNull()) + QVERIFY(!full.isDetached()); + QCOMPARE(full.trimmed(), trimmed); // lvalue + QCOMPARE(QString(full).trimmed(), trimmed); // rvalue + QCOMPARE(full.isNull(), trimmed.isNull()); + + // Not shared + full = QStringView(full).toString(); + if (!full.isNull()) + QVERIFY(full.isDetached()); + QCOMPARE(full.trimmed(), trimmed); // lvalue + QCOMPARE(QString(full).trimmed(), trimmed); // rvalue + QCOMPARE(full.isNull(), trimmed.isNull()); } void tst_QString::simplified_data() |