From 7000e2dd5c594dfbb9f67a9accfff14880ab537f Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Fri, 21 Oct 2022 22:22:51 +0200 Subject: [PATCH] QByteArray: add erase() unittests Basic unitttest and one to verify erase returns iterator, not const_iterator. Change-Id: I44c3b82b4686ff3809648063376f5e36fb7e181d Reviewed-by: Thiago Macieira --- .../text/qbytearray/tst_qbytearray.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp index e72d21ed0a..7e14894114 100644 --- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp @@ -68,6 +68,7 @@ private slots: void remove_data(); void remove(); void removeIf(); + void erase(); void erase_single_arg(); void replace_data(); void replace(); @@ -1280,6 +1281,33 @@ void tst_QByteArray::removeIf() QCOMPARE(a.removeIf(removeA), QByteArray("BcbC")); } +void tst_QByteArray::erase() +{ + { + QByteArray ba = "kittens"; + auto it = ba.erase(ba.cbegin(), ba.cbegin() + 2); + QCOMPARE(ba, "ttens"); + QCOMPARE(it, ba.cbegin()); + } + + { + QByteArray ba = "kittens"; + auto it = ba.erase(ba.cbegin(), ba.cend()); + QCOMPARE(ba, ""); + QCOMPARE(it, ba.cbegin()); + QCOMPARE(ba.cbegin(), ba.cend()); + } + + { + QByteArray ba = "kite"; + auto it = ba.erase(ba.cbegin(), ba.cbegin()); + // erase() should return an iterator (not const_iterator) + *it = 'Z'; + QCOMPARE(ba, "Zite"); + QCOMPARE(it, ba.cbegin()); + } +} + void tst_QByteArray::erase_single_arg() { QByteArray ba = "abcdefg";