diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-07-01 15:01:58 +0300 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2024-02-29 00:27:25 +0200 |
commit | 9bf68a47e1ba8790fca9d24bcb7b45cd56e79320 (patch) | |
tree | 7ce4b7644ce8e5e8d315e774d9bc37c8f19602e2 /tests/auto/corelib/text/qbytearray | |
parent | b2ec2e1137ceb0b83978a7fa35485b1b97c73648 (diff) |
QString/QByteArray: add slice() methods
[ChangeLog][QtCore][QString/QByteArray] Added slice() methods that work
like sliced(), but modify the string/byte-array they are called on.
Task-number: QTBUG-99218
Change-Id: I3075562983ef123d9aa022a2304c7e774cf2ea42
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 | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp index 1a947dfb4f..81d79da38b 100644 --- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp @@ -132,6 +132,7 @@ private slots: void mid(); void length(); void length_data(); + void slice() const; }; static const QByteArray::DataPointer staticStandard = { @@ -2890,5 +2891,31 @@ void tst_QByteArray::length_data() QTest::newRow("with '\\0' no size") << QByteArray("abc\0def") << qsizetype(3); } +void tst_QByteArray::slice() const +{ + QByteArray a; + + a.slice(0); + QVERIFY(a.isEmpty()); + QVERIFY(a.isNull()); + a.slice(0, 0); + QVERIFY(a.isEmpty()); + QVERIFY(a.isNull()); + + a = "Five pineapples"; + + a.slice(5); + QCOMPARE_EQ(a, "pineapples"); + + a.slice(4, 3); + QCOMPARE_EQ(a, "app"); + + a.slice(a.size()); + QVERIFY(a.isEmpty()); + + a.slice(0, 0); + QVERIFY(a.isEmpty()); +} + QTEST_MAIN(tst_QByteArray) #include "tst_qbytearray.moc" |