Commit 3f8d9f69 authored by Ahmad Samir's avatar Ahmad Samir

MessageCore::StringUtil::replacePrefixes: add unit tests

Should help with the upcoming port of QRegExp to QRegularExpression.
parent 0beaf2e2
Pipeline #30621 passed with stage
in 99 minutes and 7 seconds
......@@ -549,6 +549,92 @@ void StringUtilTest::test_stripOffMessagePrefix()
QCOMPARE(subjectAfterStrip, result);
}
void StringUtilTest::test_replaceMessagePrefix_data()
{
QTest::addColumn<QString>("subject");
QTest::addColumn<bool>("shouldReplace");
QTest::addColumn<QString>("newPrefix");
QTest::addColumn<QString>("expectedResult");
QTest::newRow("no previous prefix") << QStringLiteral("Hello World Subject")
<< true << QStringLiteral("New_Prefix:")
<< QStringLiteral("New_Prefix: Hello World Subject");
QTest::newRow("no previous prefix, no replace") << QStringLiteral("Hello World Subject")
<< false << QStringLiteral("New_Prefix:")
<< QStringLiteral("New_Prefix: Hello World Subject");
QTest::newRow("No default reply forward") << QStringLiteral("AA: Hello World Subject")
<< true << QStringLiteral("New_Prefix:")
<< QStringLiteral("New_Prefix: AA: Hello World Subject");
QTest::newRow("No default reply forward, no replace") << QStringLiteral("AA: Hello World Subject")
<< false << QStringLiteral("New_Prefix:")
<< QStringLiteral("New_Prefix: AA: Hello World Subject");
QTest::newRow("Default Reply Re:") << QStringLiteral("Re: Hello World Subject")
<< true << QStringLiteral("New_Prefix:")
<< QStringLiteral("New_Prefix: Hello World Subject");
QTest::newRow("Default Reply Re:, no replace") << QStringLiteral("Re: Hello World Subject")
<< false << QStringLiteral("New_Prefix:")
<< QStringLiteral("Re: Hello World Subject");
QTest::newRow("Default Reply FW:") << QStringLiteral("FW: Hello World Subject")
<< true << QStringLiteral("New_Prefix:")
<< QStringLiteral("New_Prefix: Hello World Subject");
QTest::newRow("Default Reply FW:, no replace") << QStringLiteral("FW: Hello World Subject")
<< false << QStringLiteral("New_Prefix:")
<< QStringLiteral("FW: Hello World Subject");
QTest::newRow("Default Reply FWD:") << QStringLiteral("FWD: Hello World Subject")
<< true << QStringLiteral("New_Prefix:")
<< QStringLiteral("New_Prefix: Hello World Subject");
QTest::newRow("Default Reply FWD:, no replace") << QStringLiteral("FWD: Hello World Subject")
<< false << QStringLiteral("New_Prefix:")
<< QStringLiteral("FWD: Hello World Subject");
QTest::newRow("Default Reply Re :") << QStringLiteral("Re : Hello World Subject")
<< true << QStringLiteral("New_Prefix:")
<< QStringLiteral("New_Prefix: Hello World Subject");
QTest::newRow("Default Reply Re :, no replace") << QStringLiteral("Re : Hello World Subject")
<< false << QStringLiteral("New_Prefix:")
<< QStringLiteral("Re : Hello World Subject");
QTest::newRow("Default Reply Re1:") << QStringLiteral("Re1: Hello World Subject")
<< true << QStringLiteral("New_Prefix:")
<< QStringLiteral("New_Prefix: Hello World Subject");
QTest::newRow("Default Reply Re1:, no replace") << QStringLiteral("Re1: Hello World Subject")
<< false << QStringLiteral("New_Prefix:")
<< QStringLiteral("Re1: Hello World Subject");
QTest::newRow("Default Reply Re[2]:") << QStringLiteral("Re[2]: Hello World Subject")
<< true << QStringLiteral("New_Prefix:")
<< QStringLiteral("New_Prefix: Hello World Subject");
QTest::newRow("Default Reply Re[2]:, no replace") << QStringLiteral("Re[2]: Hello World Subject")
<< false << QStringLiteral("New_Prefix:")
<< QStringLiteral("Re[2]: Hello World Subject");
}
void StringUtilTest::test_replaceMessagePrefix()
{
QFETCH(QString, subject);
QFETCH(bool, shouldReplace);
QFETCH(QString, newPrefix);
QFETCH(QString, expectedResult);
const QStringList regexPattern = {QStringLiteral("Re\\s*:"), QStringLiteral("Re\\[\\d+\\]:"),
QStringLiteral("Re\\d+:"), QStringLiteral("Fwd:"), QStringLiteral("FW:")};
const QString str = StringUtil::replacePrefixes(subject, regexPattern, shouldReplace, newPrefix);
QCOMPARE(str, expectedResult);
}
void StringUtilTest::test_formatQuotePrefix_data()
{
QTest::addColumn<QString>("quotePattern");
......
......@@ -20,6 +20,8 @@ private Q_SLOTS:
void test_parseMailtoUrl_data();
void test_parseMailtoUrl();
void test_parseMailtoUrlExtra();
void test_replaceMessagePrefix_data();
void test_replaceMessagePrefix();
void test_stripOffMessagePrefix_data();
void test_stripOffMessagePrefix();
void test_formatQuotePrefix_data();
......
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