summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-07-06 17:58:13 +0300
committerAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-07-07 15:12:27 +0000
commite91c41239166beb4b68a3f5523351e8dc3796857 (patch)
tree70112c72fd2adccf775c53ebb862ecfba12d586c /tests/auto/corelib
parenta13398d0f060bbfa482cfe411061ece6e07d2b7e (diff)
QStringRef: add chop()
chop() was missing in the API. Change-Id: I15af86c8f218cf159b8ce19bbeb2ffa6201f98cf Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/tools/qstringref/tst_qstringref.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
index 25b97ceaa8..d2374fe0ae 100644
--- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
+++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
@@ -81,6 +81,7 @@ private slots:
void integer_conversion();
void trimmed();
void truncate();
+ void chop();
void left();
void right();
void mid();
@@ -1904,6 +1905,48 @@ void tst_QStringRef::truncate()
}
}
+void tst_QStringRef::chop()
+{
+ const QString originalString = QStringLiteral("OriginalString~");
+ const QStringRef cref(&originalString);
+ {
+ const int n = 1;
+ QStringRef ref = cref;
+ QString str = originalString;
+ ref.chop(n);
+ str.chop(n);
+ QCOMPARE(ref.toString(), QLatin1String("OriginalString"));
+ QCOMPARE(ref.toString(), str);
+ }
+ {
+ const int n = -1;
+ QStringRef ref = cref;
+ QString str = originalString;
+ ref.chop(n);
+ str.chop(n);
+ QCOMPARE(ref.toString(), originalString);
+ QCOMPARE(ref.toString(), str);
+ }
+ {
+ const int n = 0;
+ QStringRef ref = cref;
+ QString str = originalString;
+ ref.chop(n);
+ str.chop(n);
+ QCOMPARE(ref.toString(), originalString);
+ QCOMPARE(ref.toString(), str);
+ }
+ {
+ const int n = 1000;
+ QStringRef ref = cref;
+ QString str = originalString;
+ ref.chop(n);
+ str.chop(n);
+ QCOMPARE(ref.toString(), str);
+ QVERIFY(ref.isEmpty());
+ }
+}
+
void tst_QStringRef::left()
{
QString originalString = "OrginalString~";