add autotest for ProString
also adds documentation, which is kind of a sanity test. ehm. Change-Id: I6b520e8b505a2bfbb1e376fa72be0f140227a3a4 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
parent
a3fac53864
commit
f37381e292
@ -159,6 +159,18 @@ QString &ProString::toQString(QString &tmp) const
|
||||
return tmp.setRawData(m_string.constData() + m_offset, m_length);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief ProString::prepareExtend
|
||||
* \param extraLen number of new characters to be added
|
||||
* \param thisTarget offset to which current contents should be moved
|
||||
* \param extraTarget offset at which new characters will be added
|
||||
* \return pointer to storage location for new characters
|
||||
*
|
||||
* Prepares the string for adding new characters.
|
||||
* If the string is detached and has enough space, it will be changed in place.
|
||||
* Otherwise, it will be replaced with a new string object, thus detaching.
|
||||
* In either case, the hash will be reset.
|
||||
*/
|
||||
QChar *ProString::prepareExtend(int extraLen, int thisTarget, int extraTarget)
|
||||
{
|
||||
if (m_string.isDetached() && m_length + extraLen <= m_string.capacity()) {
|
||||
|
@ -57,12 +57,93 @@ private slots:
|
||||
void quoteArgWin();
|
||||
void pathUtils();
|
||||
|
||||
void proString();
|
||||
void proStringList();
|
||||
|
||||
void proParser_data();
|
||||
void proParser();
|
||||
};
|
||||
|
||||
void tst_qmakelib::proString()
|
||||
{
|
||||
QString qs1(QStringLiteral("this is a string"));
|
||||
|
||||
ProString s1(qs1);
|
||||
QCOMPARE(s1.toQString(), QStringLiteral("this is a string"));
|
||||
|
||||
ProString s2(qs1, 5, 8);
|
||||
QCOMPARE(s2.toQString(), QStringLiteral("is a str"));
|
||||
|
||||
QCOMPARE(s2.hash(), 0x80000000);
|
||||
qHash(s2);
|
||||
QCOMPARE(s2.hash(), 90404018U);
|
||||
|
||||
QCOMPARE(s2.mid(0, 10).toQString(), QStringLiteral("is a str"));
|
||||
QCOMPARE(s2.mid(1, 5).toQString(), QStringLiteral("s a s"));
|
||||
QCOMPARE(s2.mid(10, 3).toQString(), QStringLiteral(""));
|
||||
|
||||
QString qs2(QStringLiteral(" spacy string "));
|
||||
QCOMPARE(ProString(qs2, 3, 13).trimmed().toQString(), QStringLiteral("spacy string"));
|
||||
QCOMPARE(ProString(qs2, 1, 17).trimmed().toQString(), QStringLiteral("spacy string"));
|
||||
|
||||
QVERIFY(s2.toQStringRef().string()->isSharedWith(qs1));
|
||||
s2.prepend(ProString("there "));
|
||||
QCOMPARE(s2.toQString(), QStringLiteral("there is a str"));
|
||||
QVERIFY(!s2.toQStringRef().string()->isSharedWith(qs1));
|
||||
|
||||
ProString s3("this is a longish string with bells and whistles");
|
||||
s3 = s3.mid(18, 17);
|
||||
// Prepend to detached string with lots of spare space in it.
|
||||
s3.prepend(ProString("another "));
|
||||
QCOMPARE(s3.toQString(), QStringLiteral("another string with bells"));
|
||||
|
||||
// Note: The string still has plenty of spare space.
|
||||
s3.append(QLatin1Char('.'));
|
||||
QCOMPARE(s3.toQString(), QStringLiteral("another string with bells."));
|
||||
s3.append(QLatin1String(" eh?"));
|
||||
QCOMPARE(s3.toQString(), QStringLiteral("another string with bells. eh?"));
|
||||
|
||||
s3.append(ProString(" yeah!"));
|
||||
QCOMPARE(s3.toQString(), QStringLiteral("another string with bells. eh? yeah!"));
|
||||
|
||||
bool pending = false; // Not in string, but joining => add space
|
||||
s3.append(ProString("..."), &pending);
|
||||
QCOMPARE(s3.toQString(), QStringLiteral("another string with bells. eh? yeah! ..."));
|
||||
QVERIFY(pending);
|
||||
|
||||
ProStringList sl1;
|
||||
sl1 << ProString("") << ProString("foo") << ProString("barbaz");
|
||||
ProString s4a("hallo");
|
||||
s4a.append(sl1);
|
||||
QCOMPARE(s4a.toQString(), QStringLiteral("hallo foo barbaz"));
|
||||
ProString s4b("hallo");
|
||||
pending = false;
|
||||
s4b.append(sl1, &pending);
|
||||
QCOMPARE(s4b.toQString(), QStringLiteral("hallo foo barbaz"));
|
||||
ProString s4c;
|
||||
pending = false;
|
||||
s4c.append(sl1, &pending);
|
||||
QCOMPARE(s4c.toQString(), QStringLiteral(" foo barbaz"));
|
||||
// bizarreness
|
||||
ProString s4d("hallo");
|
||||
pending = false;
|
||||
s4d.append(sl1, &pending, true);
|
||||
QCOMPARE(s4d.toQString(), QStringLiteral("hallo foo barbaz"));
|
||||
ProString s4e;
|
||||
pending = false;
|
||||
s4e.append(sl1, &pending, true);
|
||||
QCOMPARE(s4e.toQString(), QStringLiteral("foo barbaz"));
|
||||
|
||||
ProStringList sl2;
|
||||
sl2 << ProString("foo");
|
||||
ProString s5;
|
||||
s5.append(sl2);
|
||||
QCOMPARE(s5.toQString(), QStringLiteral("foo"));
|
||||
QVERIFY(s5.toQStringRef().string()->isSharedWith(*sl2.first().toQStringRef().string()));
|
||||
|
||||
QCOMPARE(ProString("one") + ProString(" more"), QStringLiteral("one more"));
|
||||
}
|
||||
|
||||
void tst_qmakelib::proStringList()
|
||||
{
|
||||
ProStringList sl1;
|
||||
|
Loading…
Reference in New Issue
Block a user