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/corelib/text/qbytearray | |
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/corelib/text/qbytearray')
-rw-r--r-- | tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp | 17 |
1 files changed, 17 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'; }; |