tst_QString: assign(it,it) add test-cases for empty range

Pick-to: 6.6
Change-Id: Iaf2ddb247aa279166110ad8793b1e37e66e8b11b
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Dennis Oberst 2023-08-23 17:29:19 +02:00
parent 1c1d7ab486
commit c8be7c6a6c

View File

@ -3461,6 +3461,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);
@ -3469,6 +3474,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);
@ -3477,6 +3487,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<QLatin1Char, 5> l1ch = {'F'_L1, 'G'_L1, 'H'_L1, 'I'_L1, 'J'_L1};
str.assign(l1ch.begin(), l1ch.end());
QCOMPARE(str, u"FGHIJ");
@ -3495,6 +3510,11 @@ void tst_QString::assign()
std::stringstream ss("50 51 52 53 54");
str.assign(std::istream_iterator<ushort>{ss}, std::istream_iterator<ushort>{});
QCOMPARE(str, u"23456");
oldCap = str.capacity();
str.assign(std::istream_iterator<ushort>{}, std::istream_iterator<ushort>{}); // empty range
QCOMPARE_EQ(str.capacity(), oldCap);
QCOMPARE_EQ(str.size(), 0);
}
// Test chaining
{