summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@digia.com>2014-05-14 16:56:10 +0200
committerJędrzej Nowacki <jedrzej.nowacki@digia.com>2014-08-06 14:04:40 +0200
commit1fceabe8c7b5e99509a67aec8303241b6ba4099a (patch)
tree246aec96493ff9995d756ee474c00027e2a89ef5 /tests
parentfc16dcce9df51d4d65065f8f9a8b9525856cb5ae (diff)
Implement QStringRef::split
[ChangeLog][QtCore] Added the QStringRef::split() function Change-Id: I28709c9761785dea7be4e7d621ecf4e1ae007a72 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qstringref/tst_qstringref.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
index 342abb7ea8..fe5fe92872 100644
--- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
+++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
@@ -93,6 +93,8 @@ private slots:
void left();
void right();
void mid();
+ void split_data();
+ void split();
};
static QStringRef emptyRef()
@@ -1984,6 +1986,79 @@ void tst_QStringRef::mid()
QVERIFY(emptyRef.mid(-10, 3).isEmpty());
}
+static bool operator ==(const QStringList &left, const QVector<QStringRef> &right)
+{
+ if (left.size() != right.size())
+ return false;
+
+ QStringList::const_iterator iLeft = left.constBegin();
+ QVector<QStringRef>::const_iterator iRight = right.constBegin();
+ for (; iLeft != left.end(); ++iLeft, ++iRight) {
+ if (*iLeft != *iRight)
+ return false;
+ }
+ return true;
+}
+static inline bool operator ==(const QVector<QStringRef> &left, const QStringList &right) { return right == left; }
+
+void tst_QStringRef::split_data()
+{
+ QTest::addColumn<QString>("str");
+ QTest::addColumn<QString>("sep");
+ QTest::addColumn<QStringList>("result");
+
+ QTest::newRow("a,b,c") << "a,b,c" << "," << (QStringList() << "a" << "b" << "c");
+ QTest::newRow("a,b,c,a,b,c") << "a,b,c,a,b,c" << "," << (QStringList() << "a" << "b" << "c" << "a" << "b" << "c");
+ QTest::newRow("a,b,c,,a,b,c") << "a,b,c,,a,b,c" << "," << (QStringList() << "a" << "b" << "c" << "" << "a" << "b" << "c");
+ QTest::newRow("2") << QString("-rw-r--r-- 1 0 0 519240 Jul 9 2002 bigfile")
+ << " "
+ << (QStringList() << "-rw-r--r--" << "" << "1" << "0" << "" << "0" << ""
+ << "519240" << "Jul" << "" << "9" << "" << "2002" << "bigfile");
+ QTest::newRow("one-empty") << "" << " " << (QStringList() << "");
+ QTest::newRow("two-empty") << " " << " " << (QStringList() << "" << "");
+ QTest::newRow("three-empty") << " " << " " << (QStringList() << "" << "" << "");
+
+ QTest::newRow("all-empty") << "" << "" << (QStringList() << "" << "");
+ QTest::newRow("all-null") << QString() << QString() << (QStringList() << QString() << QString());
+ QTest::newRow("sep-empty") << "abc" << "" << (QStringList() << "" << "a" << "b" << "c" << "");
+}
+
+void tst_QStringRef::split()
+{
+ QFETCH(QString, str);
+ QFETCH(QString, sep);
+ QFETCH(QStringList, result);
+
+ QVector<QStringRef> list;
+ // we construct a bigger valid string to check
+ // if ref.split is using the right size
+ QString source = str + str + str;
+ QStringRef ref = source.midRef(str.size(), str.size());
+ QCOMPARE(ref.size(), str.size());
+
+ list = ref.split(sep);
+ QVERIFY(list == result);
+ if (sep.size() == 1) {
+ list = ref.split(sep.at(0));
+ QVERIFY(list == result);
+ }
+
+ list = ref.split(sep, QString::KeepEmptyParts);
+ QVERIFY(list == result);
+ if (sep.size() == 1) {
+ list = ref.split(sep.at(0), QString::KeepEmptyParts);
+ QVERIFY(list == result);
+ }
+
+ result.removeAll("");
+ list = ref.split(sep, QString::SkipEmptyParts);
+ QVERIFY(list == result);
+ if (sep.size() == 1) {
+ list = ref.split(sep.at(0), QString::SkipEmptyParts);
+ QVERIFY(list == result);
+ }
+}
+
QTEST_APPLESS_MAIN(tst_QStringRef)
#include "tst_qstringref.moc"