diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-08-15 09:47:11 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-08-15 17:20:20 +0000 |
commit | 869513a49f7902b5942e439a972807583dab9bf9 (patch) | |
tree | 92939f210afaa42a4be95f67225ab766295c83a8 /tests/auto/corelib/tools | |
parent | 6e2af81daf927862da93316436c6510fa979fdfa (diff) |
tst_QRegularExpression: clean up
- port Q_FOREACH to C++11 range-for
(incl. one case of iterating over QHash::keys())
- port uses of inefficient QLists to QVector
- add Q_DECLARE_TYPEINFO for types held in Qt containers
Fixes errors pointed out by my tree's static checks.
Change-Id: I30eb432528fa3008240b5c217d5f2f9ddc3679be
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r-- | tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index 5825bdb6d6..2a93250ba5 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -61,6 +61,9 @@ struct Match QStringList captured; QHash<QString, QString> namedCaptured; }; +QT_BEGIN_NAMESPACE +Q_DECLARE_TYPEINFO(Match, Q_MOVABLE_TYPE); +QT_END_NAMESPACE Q_DECLARE_METATYPE(Match) @@ -85,9 +88,9 @@ bool operator==(const QRegularExpressionMatch &rem, const Match &m) } } - Q_FOREACH (const QString &name, m.namedCaptured.keys()) { - QString remCaptured = rem.captured(name); - QString mCaptured = m.namedCaptured.value(name); + for (auto it = m.namedCaptured.begin(), end = m.namedCaptured.end(); it != end; ++it) { + const QString remCaptured = rem.captured(it.key()); + const QString mCaptured = it.value(); if (remCaptured != mCaptured || remCaptured.isNull() != mCaptured.isNull() || remCaptured.isEmpty() != mCaptured.isEmpty()) { @@ -115,12 +118,11 @@ bool operator!=(const Match &m, const QRegularExpressionMatch &rem) } -bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList) +bool operator==(const QRegularExpressionMatchIterator &iterator, const QVector<Match> &expectedMatchList) { QRegularExpressionMatchIterator i = iterator; - foreach (const Match &expectedMatch, expectedMatchList) - { + for (const Match &expectedMatch : expectedMatchList) { if (!i.hasNext()) return false; @@ -135,17 +137,17 @@ bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Mat return true; } -bool operator==(const QList<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator) +bool operator==(const QVector<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator) { return operator==(iterator, expectedMatchList); } -bool operator!=(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList) +bool operator!=(const QRegularExpressionMatchIterator &iterator, const QVector<Match> &expectedMatchList) { return !operator==(iterator, expectedMatchList); } -bool operator!=(const QList<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator) +bool operator!=(const QVector<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator) { return !operator==(expectedMatchList, iterator); } @@ -1117,9 +1119,9 @@ void tst_QRegularExpression::globalMatch_data() QTest::addColumn<int>("offset"); QTest::addColumn<QRegularExpression::MatchType>("matchType"); QTest::addColumn<QRegularExpression::MatchOptions>("matchOptions"); - QTest::addColumn<QList<Match> >("matchList"); + QTest::addColumn<QVector<Match> >("matchList"); - QList<Match> matchList; + QVector<Match> matchList; Match m; matchList.clear(); @@ -1375,7 +1377,7 @@ void tst_QRegularExpression::globalMatch() QFETCH(int, offset); QFETCH(QRegularExpression::MatchType, matchType); QFETCH(QRegularExpression::MatchOptions, matchOptions); - QFETCH(QList<Match>, matchList); + QFETCH(QVector<Match>, matchList); testMatch<QRegularExpressionMatchIterator>(regexp, static_cast<QREGlobalMatchStringPMF>(&QRegularExpression::globalMatch), |