[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [trojita] tests/Utils: Transition test suite from QRegExp to QRegularExpression
From:       Erik Quaeghebeur <null () kde ! org>
Date:       2018-09-01 15:38:29
Message-ID: E1fw7yn-0007Mn-HC () code ! kde ! org
[Download RAW message or body]

Git commit 42d768d07a09bd976cb3a6dd6fc0930cd3ad6b2b by Erik Quaeghebeur.
Committed on 29/07/2018 at 21:20.
Pushed by gerrit into branch 'master'.

Transition test suite from QRegExp to QRegularExpression

Trojitá's main code has been ported transitioned from the
unmaintained QRegExp to the ‘new' QRegularExpression. At that
time, the test suite was not yet transitioned to make sure no
bugs entered there and made bugs in the changed code invisible.

This patch transitions the test suite. A literal translation
has been done. So the new functionality of QRegularExpression
has not been used (specifically, multi-line support). This is
left for future patches.

Change-Id: I36a0480349ff348c673d117d228326b83672d4ab

M  +10   -5    tests/Utils/LibMailboxSync.cpp
M  +1    -1    tests/Utils/LibMailboxSync.h

https://commits.kde.org/trojita/42d768d07a09bd976cb3a6dd6fc0930cd3ad6b2b

diff --git a/tests/Utils/LibMailboxSync.cpp b/tests/Utils/LibMailboxSync.cpp
index bfaa6be8..125999e2 100644
--- a/tests/Utils/LibMailboxSync.cpp
+++ b/tests/Utils/LibMailboxSync.cpp
@@ -21,6 +21,7 @@
 */
 
 #include <QTest>
+#include <QRegularExpression>
 #include "LibMailboxSync.h"
 #include "Utils/FakeCapabilitiesInjector.h"
 #include "Common/MetaTypes.h"
@@ -766,30 +767,34 @@ NetDataRegexp::NetDataRegexp(const QByteArray &raw, const \
QByteArray &pattern, c  }
 
 bool operator==(const NetDataRegexp &a, const NetDataRegexp &b)
+// This used to be a QRegExp based function and it still assumes QRegExp's \
limitations, even though these are removed by QRegularExpression +// TODO: Using \
QRegularExpression's functionality, multiline patterns and raw data can be \
accomodated; +// this may simplify some code (all the ifs below here could be \
removed, for starters), but this will require checking all patterns  {
     Q_ASSERT(!a.isPattern);
     Q_ASSERT(b.isPattern);
     QByteArray rawData = a.raw;
 
-    // QRegExp doesn't support multiline patterns
+    // QRegExp didn't support multiline patterns
     if (!rawData.endsWith("\r\n")) {
         // just a partial line
         return false;
     }
     rawData.chop(2);
     if (rawData.contains("\r\n")) {
-        // multiple lines, we definitely cannot handle that
+        // multiple lines, we definitely couldn't handle that
         return false;
     }
 
-    // ...but it would be a developer's mistake if the *pattern* included
+    // ...but it would've been a developer's mistake if the *pattern* included
     if (b.pattern.contains("\r\n")) {
-        // that's a developer's error -- multine patterns are not support by Qt's \
QRegExp, and there's nothing else in Qt4 +        // that's a developer's error -- \
multiline patterns were not support by Qt's QRegExp, and there was nothing else in \
Qt4  Q_ASSERT(!"CRLF in the regexp pattern, fix the test suite");
         return false;
     }
 
-    return QRegExp(QString::fromUtf8(b.pattern)).exactMatch(QString::fromUtf8(rawData));
 +    return QRegularExpression("\\A(?:" + QString::fromUtf8(b.pattern) + \
")\\z").match(QString::fromUtf8(rawData)).hasMatch(); +    // The pattern is \
surrounded by start and end anchors to ensure that the match is exact  }
 
 /** @short A string literal formatted according to RFC 3501 */
diff --git a/tests/Utils/LibMailboxSync.h b/tests/Utils/LibMailboxSync.h
index 7e19f77b..1b45a0ca 100644
--- a/tests/Utils/LibMailboxSync.h
+++ b/tests/Utils/LibMailboxSync.h
@@ -166,7 +166,7 @@ char *toString(const NetDataRegexp &x);
     QCOMPARE(QString::fromUtf8(SOCK->writtenStuff()), QString::fromUtf8(data));\
 }
 
-// Be careful with this; a QRegExp only supports single-line patterns.
+// Be careful with this; although we now use QRegularExpression, the underlying code \
is still based on QRegExp's limitation to single-line patterns.  #define \
cClientRegExp(pattern) \  { \
     TROJITA_CLIENT_LOOP \


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic