File indexing completed on 2024-11-24 04:49:52

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "regexpconvertertest.h"
0008 #include <QRegularExpression>
0009 #include <QTest>
0010 
0011 RegExpConverterTest::RegExpConverterTest(QObject *parent)
0012     : QObject(parent)
0013 {
0014 }
0015 
0016 static inline QString stringReplaceRegularExpression(QString s)
0017 {
0018     static QRegularExpression reg(QStringLiteral("[\n\t]+"));
0019     s.replace(reg, QStringLiteral(" "));
0020     return s.replace(QLatin1Char('\"'), QStringLiteral("\\\""));
0021 }
0022 
0023 void RegExpConverterTest::convertRegExp_data()
0024 {
0025     QTest::addColumn<QString>("input");
0026     QTest::addColumn<QString>("output");
0027     QTest::newRow("empty") << QString() << QString();
0028     QTest::newRow("space") << QStringLiteral("foo foo foo") << QStringLiteral("foo foo foo");
0029     QTest::newRow("space2") << QStringLiteral("   foo foo foo  ") << QStringLiteral("   foo foo foo  ");
0030     QTest::newRow("newline") << QStringLiteral("\n   foo foo foo  ") << QStringLiteral("    foo foo foo  ");
0031     QTest::newRow("newline2") << QStringLiteral("\nfoo\n foo") << QStringLiteral(" foo  foo");
0032     QTest::newRow("newline3") << QStringLiteral("\n\t\tfoo\n") << QStringLiteral(" foo ");
0033     QTest::newRow("quote") << QStringLiteral("\n\t\tfoo\"\n") << QStringLiteral(" foo\\\" ");
0034 }
0035 
0036 void RegExpConverterTest::convertRegExp()
0037 {
0038     QFETCH(QString, input);
0039     QFETCH(QString, output);
0040 
0041     QCOMPARE(stringReplaceRegularExpression(input), output);
0042 }
0043 
0044 QTEST_MAIN(RegExpConverterTest)
0045 
0046 #include "moc_regexpconvertertest.cpp"