QByteArray: add trimmed() unittest

Change-Id: Ib0e808ea45bb68fb0ec79da2f32959677eae988f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2023-07-16 23:40:40 +03:00
parent c4b40f4503
commit 358e13a5e1

View File

@ -122,6 +122,8 @@ private slots:
void fill(); void fill();
void dataPointers(); void dataPointers();
void truncate(); void truncate();
void trimmed_data();
void trimmed();
void simplified(); void simplified();
void simplified_data(); void simplified_data();
void left(); void left();
@ -2648,6 +2650,39 @@ void tst_QByteArray::truncate()
QVERIFY(a.isEmpty()); QVERIFY(a.isEmpty());
} }
void tst_QByteArray::trimmed_data()
{
QTest::addColumn<QByteArray>("full" );
QTest::addColumn<QByteArray>("trimmed" );
QTest::addRow("null") << QByteArray() << QByteArray();
QTest::addRow("simple") << "Text"_ba << "Text"_ba;
QTest::addRow("single-space") << " "_ba << ""_ba;
QTest::addRow("single-char") << " a "_ba << "a"_ba;
QTest::addRow("mixed") << " a \n\t\v b "_ba << "a \n\t\v b"_ba;
}
void tst_QByteArray::trimmed()
{
QFETCH(QByteArray, full);
QFETCH(QByteArray, trimmed);
// Shared
if (!full.isNull())
QVERIFY(!full.isDetached());
QCOMPARE(full.trimmed(), trimmed); // lvalue
QCOMPARE(QByteArray(full).trimmed(), trimmed); // rvalue
QCOMPARE(full.isNull(), trimmed.isNull());
// Not shared
full = QByteArrayView(full).toByteArray();
if (!full.isNull())
QVERIFY(full.isDetached());
QCOMPARE(full.trimmed(), trimmed); // lvalue
QCOMPARE(QByteArray(full).trimmed(), trimmed); // rvalue
QCOMPARE(full.isNull(), trimmed.isNull());
}
void tst_QByteArray::simplified() void tst_QByteArray::simplified()
{ {
QFETCH(QByteArray, source); QFETCH(QByteArray, source);