QByteArray: add trimmed() unittest
Change-Id: Ib0e808ea45bb68fb0ec79da2f32959677eae988f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
c4b40f4503
commit
358e13a5e1
@ -122,6 +122,8 @@ private slots:
|
||||
void fill();
|
||||
void dataPointers();
|
||||
void truncate();
|
||||
void trimmed_data();
|
||||
void trimmed();
|
||||
void simplified();
|
||||
void simplified_data();
|
||||
void left();
|
||||
@ -2648,6 +2650,39 @@ void tst_QByteArray::truncate()
|
||||
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()
|
||||
{
|
||||
QFETCH(QByteArray, source);
|
||||
|
Loading…
Reference in New Issue
Block a user