Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 59a617b6 authored by Laurent Montel's avatar Laurent Montel 😁

Add autotest

parent 99f06f80
......@@ -18,6 +18,7 @@
*/
#include "regexpconvertertest.h"
#include <QRegularExpression>
#include <QTest>
RegExpConverterTest::RegExpConverterTest(QObject *parent)
......@@ -26,4 +27,38 @@ RegExpConverterTest::RegExpConverterTest(QObject *parent)
}
static inline QString stringReplaceRegExp(QString s)
{
s = s.replace(QRegExp(QLatin1String("[\n\t]+")), QStringLiteral(" "));
return s.replace(QLatin1Char('\"'), QStringLiteral("\\\""));
}
static inline QString stringReplaceRegularExpression(QString s)
{
s = s.replace(QRegularExpression(QStringLiteral("[\n\t]+")), QStringLiteral(" "));
return s.replace(QLatin1Char('\"'), QStringLiteral("\\\""));
}
void RegExpConverterTest::convertRegExp_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("output");
QTest::newRow("empty") << QString() << QString();
QTest::newRow("space") << QStringLiteral("foo foo foo") << QStringLiteral("foo foo foo");
QTest::newRow("space2") << QStringLiteral(" foo foo foo ") << QStringLiteral(" foo foo foo ");
QTest::newRow("newline") << QStringLiteral("\n foo foo foo ") << QStringLiteral(" foo foo foo ");
QTest::newRow("newline2") << QStringLiteral("\nfoo\n foo") << QStringLiteral(" foo foo");
QTest::newRow("newline3") << QStringLiteral("\n\t\tfoo\n") << QStringLiteral(" foo ");
}
void RegExpConverterTest::convertRegExp()
{
QFETCH(QString, input);
QFETCH(QString, output);
QCOMPARE(stringReplaceRegExp(input), output);
QCOMPARE(stringReplaceRegularExpression(input), output);
}
QTEST_MAIN(RegExpConverterTest)
......@@ -28,6 +28,9 @@ class RegExpConverterTest : public QObject
public:
explicit RegExpConverterTest(QObject *parent = nullptr);
~RegExpConverterTest() = default;
private Q_SLOTS:
void convertRegExp_data();
void convertRegExp();
};
#endif // REGEXPCONVERTERTEST_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment