diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2022-11-06 14:40:33 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2022-11-16 18:25:35 +0200 |
commit | 4d8484382248d7bd9e86ccf0f3847b7240a13418 (patch) | |
tree | 319a4d23bf690845f1cf0860c78cecee2fac9cdd /tests/auto | |
parent | 4c975fd564e3b1f5c398f6ffe6b4b87ff6f95379 (diff) |
QString, QByteArray: add removeAt/First/Last() convenience methods
Requested in codereview.qt-project.org/c/qt/qtbase/+/441770
[ChangeLog][QtCore][Text] Add removeAt/First/Last() convenience methods to
QString and QByteArray
Change-Id: I48a803e456e70cc51d51726a5e3aa7c125aedb1c
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp | 17 | ||||
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 15 |
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp index 9794247965..34bee7bce8 100644 --- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp @@ -53,6 +53,7 @@ private slots: void insertExtended(); void remove_data(); void remove(); + void remove_extra(); void removeIf(); void erase(); void erase_single_arg(); @@ -1070,6 +1071,22 @@ void tst_QByteArray::remove() QCOMPARE(ba2.remove(position, length), expected); } +void tst_QByteArray::remove_extra() +{ + QByteArray ba = "Clock"; + ba.removeFirst(); + QCOMPARE(ba, "lock"); + ba.removeLast(); + QCOMPARE(ba, "loc"); + ba.removeAt(ba.indexOf('o')); + QCOMPARE(ba, "lc"); + ba.clear(); + // No crash on empty byte arrays + ba.removeFirst(); + ba.removeLast(); + ba.removeAt(2); +} + void tst_QByteArray::removeIf() { auto removeA = [](const char c) { return c == 'a' || c == 'A'; }; diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 230182889c..8b9e762d5d 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -3452,6 +3452,21 @@ void tst_QString::remove_extra() s1.remove(0, 1); QCOMPARE(s1, s); } + + { + QString s = "Clock"; + s.removeFirst(); + QCOMPARE(s, "lock"); + s.removeLast(); + QCOMPARE(s, "loc"); + s.removeAt(s.indexOf('o')); + QCOMPARE(s, "lc"); + s.clear(); + // No crash on empty strings + s.removeFirst(); + s.removeLast(); + s.removeAt(2); + } } void tst_QString::erase_single_arg() |