QRegularExpression: improve operator==, add dedicated autotest
Trivial change: compare dpointers first, then the data. Added test function for operator==. Change-Id: I33ac64a59db4ccad56c30be17622187e42415f38 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
aea65cbaa4
commit
bd30234b59
@ -1395,7 +1395,8 @@ QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QString &s
|
||||
*/
|
||||
bool QRegularExpression::operator==(const QRegularExpression &re) const
|
||||
{
|
||||
return (pattern() == re.pattern() && patternOptions() == re.patternOptions());
|
||||
return (d == re.d) ||
|
||||
(d->pattern == re.d->pattern && d->patternOptions == re.d->patternOptions);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -71,6 +71,8 @@ private slots:
|
||||
void globalMatch();
|
||||
void serialize_data();
|
||||
void serialize();
|
||||
void operatoreq_data();
|
||||
void operatoreq();
|
||||
|
||||
private:
|
||||
void provideRegularExpressions();
|
||||
@ -348,11 +350,6 @@ void tst_QRegularExpression::gettersSetters()
|
||||
QCOMPARE(re.pattern(), pattern);
|
||||
QCOMPARE(re.patternOptions(), patternOptions);
|
||||
}
|
||||
{
|
||||
QRegularExpression re(pattern, patternOptions);
|
||||
QRegularExpression re2(pattern, patternOptions);
|
||||
QVERIFY(re == re2);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QRegularExpression::escape_data()
|
||||
@ -1144,6 +1141,63 @@ void tst_QRegularExpression::serialize()
|
||||
QCOMPARE(inRe, outRe);
|
||||
}
|
||||
|
||||
static void verifyEquality(const QRegularExpression &re1, const QRegularExpression &re2)
|
||||
{
|
||||
QVERIFY(re1 == re2);
|
||||
QVERIFY(re2 == re1);
|
||||
QVERIFY(!(re1 != re2));
|
||||
QVERIFY(!(re2 != re1));
|
||||
|
||||
QRegularExpression re3(re1);
|
||||
|
||||
QVERIFY(re1 == re3);
|
||||
QVERIFY(re3 == re1);
|
||||
QVERIFY(!(re1 != re3));
|
||||
QVERIFY(!(re3 != re1));
|
||||
|
||||
QVERIFY(re2 == re3);
|
||||
QVERIFY(re3 == re2);
|
||||
QVERIFY(!(re2 != re3));
|
||||
QVERIFY(!(re3 != re2));
|
||||
|
||||
re3 = re2;
|
||||
QVERIFY(re1 == re3);
|
||||
QVERIFY(re3 == re1);
|
||||
QVERIFY(!(re1 != re3));
|
||||
QVERIFY(!(re3 != re1));
|
||||
|
||||
QVERIFY(re2 == re3);
|
||||
QVERIFY(re3 == re2);
|
||||
QVERIFY(!(re2 != re3));
|
||||
QVERIFY(!(re3 != re2));
|
||||
}
|
||||
|
||||
void tst_QRegularExpression::operatoreq_data()
|
||||
{
|
||||
provideRegularExpressions();
|
||||
}
|
||||
|
||||
void tst_QRegularExpression::operatoreq()
|
||||
{
|
||||
QFETCH(QString, pattern);
|
||||
QFETCH(QRegularExpression::PatternOptions, patternOptions);
|
||||
{
|
||||
QRegularExpression re1(pattern);
|
||||
QRegularExpression re2(pattern);
|
||||
verifyEquality(re1, re2);
|
||||
}
|
||||
{
|
||||
QRegularExpression re1(QString(), patternOptions);
|
||||
QRegularExpression re2(QString(), patternOptions);
|
||||
verifyEquality(re1, re2);
|
||||
}
|
||||
{
|
||||
QRegularExpression re1(pattern, patternOptions);
|
||||
QRegularExpression re2(pattern, patternOptions);
|
||||
verifyEquality(re1, re2);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_QRegularExpression)
|
||||
|
||||
#include "tst_qregularexpression.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user