diff options
Diffstat (limited to 'tests/auto/corelib/tools/qstringref/tst_qstringref.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qstringref/tst_qstringref.cpp | 43 |
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~"; |