From d5b36aa609703e48e77714b5905b73d804b33332 Mon Sep 17 00:00:00 2001 From: Dennis Oberst Date: Wed, 23 Aug 2023 17:29:19 +0200 Subject: [PATCH] tst_QString: assign(it,it) add test-cases for empty range Change-Id: Iaf2ddb247aa279166110ad8793b1e37e66e8b11b Reviewed-by: Marc Mutz (cherry picked from commit c8be7c6a6c8bdefea523428163fe03186fd42ce5) Reviewed-by: Qt Cherry-pick Bot --- .../auto/corelib/text/qstring/tst_qstring.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 819335ca35e..e6e3d6eefdd 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -3434,6 +3434,11 @@ void tst_QString::assign() QCOMPARE(str.assign(tstr.begin(), tstr.end()), u"(ノಠ益ಠ)\0ノ彡┻━┻"); QCOMPARE(str.size(), 6); + auto oldCap = str.capacity(); + str.assign(tstr.begin(), tstr.begin()); // empty range + QCOMPARE_EQ(str.capacity(), oldCap); + QCOMPARE_EQ(str.size(), 0); + const char16_t c16[] = u"٩(⁎❛ᴗ❛⁎)۶ 🤷"; str.assign(std::begin(c16), std::end(c16) - 1); QCOMPARE(str, c16); @@ -3442,6 +3447,11 @@ void tst_QString::assign() str.assign(c16str.begin(), c16str.end()); QCOMPARE(str, c16); + oldCap = str.capacity(); + str.assign(c16str.begin(), c16str.begin()); // empty range + QCOMPARE_EQ(str.capacity(), oldCap); + QCOMPARE_EQ(str.size(), 0); + const char32_t c32[] = U"٩(⁎❛ᴗ❛⁎)۶ 🤷"; str.assign(std::begin(c32), std::end(c32) - 1); QCOMPARE(str, c16); @@ -3450,6 +3460,11 @@ void tst_QString::assign() str.assign(c32str.begin(), c32str.end()); QCOMPARE(str, c16); + oldCap = str.capacity(); + str.assign(c32str.begin(), c32str.begin()); // empty range + QCOMPARE_EQ(str.capacity(), oldCap); + QCOMPARE_EQ(str.size(), 0); + QVarLengthArray l1ch = {'F'_L1, 'G'_L1, 'H'_L1, 'I'_L1, 'J'_L1}; str.assign(l1ch.begin(), l1ch.end()); QCOMPARE(str, u"FGHIJ"); @@ -3468,6 +3483,11 @@ void tst_QString::assign() std::stringstream ss("50 51 52 53 54"); str.assign(std::istream_iterator{ss}, std::istream_iterator{}); QCOMPARE(str, u"23456"); + + oldCap = str.capacity(); + str.assign(std::istream_iterator{}, std::istream_iterator{}); // empty range + QCOMPARE_EQ(str.capacity(), oldCap); + QCOMPARE_EQ(str.size(), 0); } // Test chaining {