forked from qt-creator/qt-creator
Tests: Replace QRegExp by QRegularExpression
Task-number: QTCREATORBUG-24098 Change-Id: I8649423fc69faadad324bc3bb51004633fa7cc4d Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -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)")
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -158,7 +158,9 @@ void dummyStatement(...) {}
|
||||
#include <QMap>
|
||||
#include <QPointer>
|
||||
#include <QProcess>
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QRegExp>
|
||||
#endif
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QSettings>
|
||||
@@ -1991,7 +1993,7 @@ namespace qobject {
|
||||
} // namespace qobject
|
||||
|
||||
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
namespace qregexp {
|
||||
|
||||
void testQRegExp()
|
||||
@@ -2017,6 +2019,7 @@ namespace qregexp {
|
||||
}
|
||||
|
||||
} // namespace qregexp
|
||||
#endif
|
||||
|
||||
namespace qrect {
|
||||
|
||||
@@ -7189,7 +7192,9 @@ int main(int argc, char *argv[])
|
||||
qmap::testQMap();
|
||||
qobject::testQObject();
|
||||
qrect::testGeometry();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
qregexp::testQRegExp();
|
||||
#endif
|
||||
qregion::testQRegion();
|
||||
qscript::testQScript();
|
||||
qjson::testQJson();
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QPainter>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QRegularExpression>
|
||||
#include <QStatusBar>
|
||||
#include <QTextEdit>
|
||||
|
||||
@@ -61,7 +62,7 @@ public:
|
||||
|
||||
if ( TextEdit::overwriteMode() ) {
|
||||
QFontMetrics fm(TextEdit::font());
|
||||
rect.setWidth(fm.width('m'));
|
||||
rect.setWidth(fm.horizontalAdvance('m'));
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(TextEdit::palette().color(QPalette::Base));
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Difference);
|
||||
@@ -89,7 +90,7 @@ static void highlightMatches(QWidget *widget, const QString &pattern)
|
||||
|
||||
// Highlight matches.
|
||||
QTextDocument *doc = ed->document();
|
||||
QRegExp re(pattern);
|
||||
const QRegularExpression re(pattern);
|
||||
cur = doc->find(re);
|
||||
|
||||
int a = cur.position();
|
||||
|
||||
Reference in New Issue
Block a user