aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorChristian Stenger <christian.stenger@qt.io>2020-07-17 10:38:55 +0200
committerChristian Stenger <christian.stenger@qt.io>2020-07-20 10:22:56 +0000
commiteb52982c9d7f13f725f97b44132052b056af9c89 (patch)
tree83bd37a3020568d431c6574b8cb1411774d46d24 /tests/auto
parent3b14051db50f65f0e6c1319adad2224bfa6e3871 (diff)
Tests: Replace QRegExp by QRegularExpression
Task-number: QTCREATORBUG-24098 Change-Id: I8649423fc69faadad324bc3bb51004633fa7cc4d Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/debugger/tst_dumpers.cpp28
-rw-r--r--tests/auto/debugger/tst_gdb.cpp39
-rw-r--r--tests/auto/qml/codemodel/check/tst_check.cpp14
3 files changed, 44 insertions, 37 deletions
diff --git a/tests/auto/debugger/tst_dumpers.cpp b/tests/auto/debugger/tst_dumpers.cpp
index 2406730a2c..072d5f7489 100644
--- a/tests/auto/debugger/tst_dumpers.cpp
+++ b/tests/auto/debugger/tst_dumpers.cpp
@@ -134,12 +134,13 @@ static bool generateEnvironmentSettings(Utils::Environment &env,
if (!varsFile.open(QIODevice::ReadOnly))
return false;
- QRegExp regexp("(\\w*)=(.*)");
+ const QRegularExpression regexp("^(\\w*)=(.*)$");
while (!varsFile.atEnd()) {
const QString line = QString::fromLocal8Bit(varsFile.readLine()).trimmed();
- if (regexp.exactMatch(line)) {
- const QString varName = regexp.cap(1);
- const QString varValue = regexp.cap(2);
+ const QRegularExpressionMatch match = regexp.match(line);
+ if (match.hasMatch()) {
+ const QString varName = match.captured(1);
+ const QString varValue = match.captured(2);
if (!varValue.isEmpty())
envPairs.insert(varName, varValue);
@@ -336,9 +337,10 @@ struct Value
expectedValue.replace(")", "!");
actualValue.replace("(", "!");
actualValue.replace(")", "!");
+ const QString anchoredPattern = QRegularExpression::anchoredPattern(expectedValue);
//QWARN(qPrintable("MATCH EXP: " + expectedValue + " ACT: " + actualValue));
- //QWARN(QRegExp(expectedValue).exactMatch(actualValue) ? "OK" : "NOT OK");
- return QRegExp(expectedValue).exactMatch(actualValue);
+ //QWARN(QRegularExpression(anchoredPattern).match(actualValue).hasMatch() ? "OK" : "NOT OK");
+ return QRegularExpression(anchoredPattern).match(actualValue).hasMatch();
}
if (hasPtrSuffix)
@@ -435,9 +437,10 @@ struct Type
expectedType.replace("const", "");
expectedType.replace('@', context.nameSpace);
- if (isPattern)
- return QRegExp(expectedType).exactMatch(actualType);
-
+ if (isPattern) {
+ return QRegularExpression(QRegularExpression::anchoredPattern(expectedType))
+ .match(actualType).hasMatch();
+ }
if (fullNamespaceMatch)
expectedType.replace('?', context.nameSpace);
else
@@ -626,7 +629,7 @@ struct CheckType : public Check
};
const QtVersion Qt4 = QtVersion(0, 0x4ffff);
-const QtVersion Qt5 = QtVersion(0x50000);
+const QtVersion Qt5 = QtVersion(0x50000, 0x5ffff);
struct Check4 : Check
{
@@ -3159,6 +3162,7 @@ void tst_Dumpers::dumper_data()
"&pos1, &pos2, &caps")
+ + Qt5
+ CoreProfile()
+ Check("re", "\"a(.*)b(.*)c\"", "@QRegExp")
@@ -4025,7 +4029,9 @@ void tst_Dumpers::dumper_data()
"QVariant var24 = QLineF(); unused(&var24); // 24 QLineF\n"
"QVariant var25 = QPoint(); unused(&var25); // 25 QPoint\n"
"QVariant var26 = QPointF(); unused(&var26); // 26 QPointF\n"
+ "#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)\n"
"QVariant var27 = QRegExp(); unused(&var27); // 27 QRegExp\n"
+ "#endif"
"QVariant var28 = QVariantHash(); unused(&var28); // 28 QVariantHash\n"
"QVariant var31 = QVariant::fromValue<void *>(&r); unused(&var31); // 31 void *\n"
"QVariant var32 = QVariant::fromValue<long>(32); unused(&var32); // 32 long\n"
@@ -4095,7 +4101,7 @@ void tst_Dumpers::dumper_data()
+ Check("var24", "", "@QVariant (QLineF)")
+ Check("var25", "(0, 0)", "@QVariant (QPoint)")
+ Check("var26", "(0.0, 0.0)", "@QVariant (QPointF)")
- + Check("var27", "\"\"", "@QVariant (QRegExp)")
+ + Check("var27", "\"\"", "@QVariant (QRegExp)") % Qt5
+ Check("var28", "<0 items>", "@QVariant (QVariantHash)")
+ CheckType("var31", "@QVariant (void *)")
+ Check("var32", "32", "@QVariant (long)")
diff --git a/tests/auto/debugger/tst_gdb.cpp b/tests/auto/debugger/tst_gdb.cpp
index 1c1c6f7338..6de43aa3da 100644
--- a/tests/auto/debugger/tst_gdb.cpp
+++ b/tests/auto/debugger/tst_gdb.cpp
@@ -187,22 +187,23 @@ QString niceType(QString type)
"std::allocator<wchar_t> >"), QLatin1String("wstring"));
// std::vector, std::deque, std::list
- QRegExp re1(QString("(vector|list|deque)<%1, %2\\s*>").arg(inner, alloc));
- if (re1.indexIn(type) != -1)
- type.replace(re1.cap(0), QString("%1<%2>").arg(re1.cap(1), inner));
+ const QRegularExpression re1(QString("(vector|list|deque)<%1, %2\\s*?>").arg(inner, alloc));
+ QRegularExpressionMatch match = re1.match(type);
+ if (match.hasMatch())
+ type.replace(match.captured(), QString("%1<%2>").arg(match.captured(1), inner));
// std::stack
- QRegExp re6(QString("stack<%1, std::deque<%2> >").arg(inner, inner));
- re6.setMinimal(true);
- if (re6.indexIn(type) != -1)
- type.replace(re6.cap(0), QString("stack<%1>").arg(inner));
+ const QRegularExpression re6(QString("stack<%1, std::deque<%2> >").arg(inner, inner));
+ match = re6.match(type);
+ if (match.hasMatch())
+ type.replace(match.captured(), QString("stack<%1>").arg(inner));
// std::set
- QRegExp re4(QString("set<%1, std::less<%2>, %3\\s*>").arg(inner, inner, alloc));
- re4.setMinimal(true);
- if (re4.indexIn(type) != -1)
- type.replace(re4.cap(0), QString("set<%1>").arg(inner));
+ const QRegularExpression re4(QString("set<%1, std::less<%2>, %3\\s*?>").arg(inner, inner, alloc));
+ match = re4.match(type);
+ if (match.hasMatch())
+ type.replace(match.captured(), QString("set<%1>").arg(inner));
// std::map
@@ -223,17 +224,17 @@ QString niceType(QString type)
QString key = chopConst(ckey);
QString value = inner.mid(pos + 2, inner.size() - 3 - pos);
- QRegExp re5(QString("map<%1, %2, std::less<%3>, %4\\s*>")
+ const QRegularExpression re5(QString("map<%1, %2, std::less<%3>, %4\\s*?>")
.arg(key, value, key, alloc));
- re5.setMinimal(true);
- if (re5.indexIn(type) != -1) {
- type.replace(re5.cap(0), QString("map<%1, %2>").arg(key, value));
+ match = re5.match(type);
+ if (match.hasMatch()) {
+ type.replace(match.captured(), QString("map<%1, %2>").arg(key, value));
} else {
- QRegExp re7(QString("map<const %1, %2, std::less<const %3>, %4\\s*>")
+ const QRegularExpression re7(QString("map<const %1, %2, std::less<const %3>, %4\\s*?>")
.arg(key, value, key, alloc));
- re7.setMinimal(true);
- if (re7.indexIn(type) != -1)
- type.replace(re7.cap(0), QString("map<const %1, %2>").arg(key, value));
+ match = re7.match(type);
+ if (match.hasMatch())
+ type.replace(match.captured(), QString("map<const %1, %2>").arg(key, value));
}
}
}
diff --git a/tests/auto/qml/codemodel/check/tst_check.cpp b/tests/auto/qml/codemodel/check/tst_check.cpp
index 8a52fd0ced..36e95999dd 100644
--- a/tests/auto/qml/codemodel/check/tst_check.cpp
+++ b/tests/auto/qml/codemodel/check/tst_check.cpp
@@ -131,17 +131,17 @@ void tst_Check::test()
QList<Message> messages = checker();
std::sort(messages.begin(), messages.end(), &offsetComparator);
- const QRegExp messagePattern(" (\\d+) (\\d+) (\\d+)");
+ const QRegularExpression messagePattern(" (\\d+) (\\d+) (\\d+)");
QList<Message> expectedMessages;
- foreach (const SourceLocation &comment, doc->engine()->comments()) {
+ for (const SourceLocation &comment : doc->engine()->comments()) {
const QString text = doc->source().mid(comment.begin(), comment.end() - comment.begin());
-
- if (messagePattern.indexIn(text) == -1)
+ const QRegularExpressionMatch match = messagePattern.match(text);
+ if (match.hasMatch())
continue;
- const int type = messagePattern.cap(1).toInt();
- const int columnStart = messagePattern.cap(2).toInt();
- const int columnEnd = messagePattern.cap(3).toInt() + 1;
+ const int type = match.captured(1).toInt();
+ const int columnStart = match.captured(2).toInt();
+ const int columnEnd = match.captured(3).toInt() + 1;
Message message;
message.location = SourceLocation(