mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
test: re-made test for URL highlighting
Also one test was removed. Answering sudden6's question, this test will not pass after merging current pull request (if it will)
This commit is contained in:
parent
40c4f431dd
commit
5a569ea467
|
@ -153,46 +153,31 @@ static const QVector<StringPair> MIXED_FORMATTING_SPECIAL_CASES {
|
||||||
PAIR_FORMAT("aaa *aaa /aaa* aaa/", "aaa *aaa <i>aaa* aaa</i>"),
|
PAIR_FORMAT("aaa *aaa /aaa* aaa/", "aaa *aaa <i>aaa* aaa</i>"),
|
||||||
};
|
};
|
||||||
|
|
||||||
static const StringToString urlCases{
|
#define MAKE_LINK(url) "<a href=\"" url "\">" url "</a>"
|
||||||
{QStringLiteral("https://github.com/qTox/qTox/issues/4233"),
|
|
||||||
QStringLiteral("<a href=\"https://github.com/qTox/qTox/issues/4233\">"
|
static const QVector<QPair<QString, QString>> URL_CASES {
|
||||||
"https://github.com/qTox/qTox/issues/4233</a>")},
|
PAIR_FORMAT("https://github.com/qTox/qTox/issues/4233",
|
||||||
{QStringLiteral("No conflicts with /italic https://github.com/qTox/qTox/issues/4233 font/"),
|
MAKE_LINK("https://github.com/qTox/qTox/issues/4233")),
|
||||||
QStringLiteral("No conflicts with <i>italic "
|
PAIR_FORMAT("www.youtube.com", MAKE_LINK("www.youtube.com")),
|
||||||
"<a href=\"https://github.com/qTox/qTox/issues/4233\">"
|
PAIR_FORMAT("https://url.com/some*url/some*more*url/",
|
||||||
"https://github.com/qTox/qTox/issues/4233</a> font</i>")},
|
MAKE_LINK("https://url.com/some*url/some*more*url/")),
|
||||||
{QStringLiteral("www.youtube.com"),
|
PAIR_FORMAT("https://url.com/some_url/some_more_url/",
|
||||||
QStringLiteral("<a href=\"http://www.youtube.com\">www.youtube.com</a>")},
|
MAKE_LINK("https://url.com/some_url/some_more_url/")),
|
||||||
{QStringLiteral("https://url.com/some*url/some*more*url/"),
|
PAIR_FORMAT("https://url.com/some~url/some~more~url/",
|
||||||
QStringLiteral("<a href=\"https://url.com/some*url/some*more*url/\">"
|
MAKE_LINK("https://url.com/some~url/some~more~url/")),
|
||||||
"https://url.com/some*url/some*more*url/</a>")},
|
|
||||||
{QStringLiteral("https://url.com/some_url/some_more_url/"),
|
|
||||||
QStringLiteral("<a href=\"https://url.com/some_url/some_more_url/\">"
|
|
||||||
"https://url.com/some_url/some_more_url/</a>")},
|
|
||||||
{QStringLiteral("https://url.com/some~url/some~more~url/"),
|
|
||||||
QStringLiteral("<a href=\"https://url.com/some~url/some~more~url/\">"
|
|
||||||
"https://url.com/some~url/some~more~url/</a>")},
|
|
||||||
{QStringLiteral("https://url.com/some`url/some`more`url/"),
|
|
||||||
QStringLiteral("<a href=\"https://url.com/some`url/some`more`url/\">"
|
|
||||||
"https://url.com/some`url/some`more`url/</a>")},
|
|
||||||
// Test case from issue #4275
|
// Test case from issue #4275
|
||||||
{QStringLiteral("http://www.metacritic.com/game/pc/mass-effect-andromeda\n"
|
PAIR_FORMAT("http://www.metacritic.com/game/pc/mass-effect-andromeda\n"
|
||||||
"http://www.metacritic.com/game/playstation-4/mass-effect-andromeda\n"
|
"http://www.metacritic.com/game/playstation-4/mass-effect-andromeda\n"
|
||||||
"http://www.metacritic.com/game/xbox-one/mass-effect-andromeda"),
|
"http://www.metacritic.com/game/xbox-one/mass-effect-andromeda",
|
||||||
QStringLiteral("<a href=\"http://www.metacritic.com/game/pc/mass-effect-andromeda\">"
|
MAKE_LINK("http://www.metacritic.com/game/pc/mass-effect-andromeda") "\n"
|
||||||
"http://www.metacritic.com/game/pc/mass-effect-andromeda</a>\n"
|
MAKE_LINK("http://www.metacritic.com/game/playstation-4/mass-effect-andromeda") "\n"
|
||||||
"<a href=\"http://www.metacritic.com/game/playstation-4/mass-effect-andromeda\""
|
MAKE_LINK("http://www.metacritic.com/game/xbox-one/mass-effect-andromeda")),
|
||||||
">http://www.metacritic.com/game/playstation-4/mass-effect-andromeda</a>\n"
|
PAIR_FORMAT("http://site.com/part1/part2 "
|
||||||
"<a href=\"http://www.metacritic.com/game/xbox-one/mass-effect-andromeda\">"
|
"http://site.com/part3 and one more time "
|
||||||
"http://www.metacritic.com/game/xbox-one/mass-effect-andromeda</a>")},
|
"www.site.com/part1/part2",
|
||||||
{QStringLiteral("http://site.com/part1/part2 "
|
MAKE_LINK("http://site.com/part1/part2") " "
|
||||||
"http://site.com/part3 "
|
MAKE_LINK("http://site.com/part3") " and one more time "
|
||||||
"and one more time "
|
MAKE_LINK("www.site.com/part1/part2")),
|
||||||
"www.site.com/part1/part2"),
|
|
||||||
QStringLiteral("<a href=\"http://site.com/part1/part2\">http://site.com/part1/part2</a> "
|
|
||||||
"<a href=\"http://site.com/part3\">http://site.com/part3</a> "
|
|
||||||
"and one more time "
|
|
||||||
"<a href=\"http://www.site.com/part1/part2\">www.site.com/part1/part2</a>")},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef PAIR_FORMAT
|
#undef PAIR_FORMAT
|
||||||
|
@ -276,6 +261,23 @@ static void specialCasesTest(MarkdownFunction applyMarkdown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using UrlHighlightFunction = QString(*)(const QString&);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Function for testing URL highlighting
|
||||||
|
* @param data Test data - map of "URL - HTML-wrapped URL"
|
||||||
|
*/
|
||||||
|
static void urlHighlightTest(UrlHighlightFunction function, const QVector<QPair<QString, QString>>& data)
|
||||||
|
{
|
||||||
|
for (const QPair<QString, QString>& p : data) {
|
||||||
|
qDebug() << "Input:" << p.first;
|
||||||
|
qDebug() << "Output:" << p.second;
|
||||||
|
QString result = function(p.first);
|
||||||
|
qDebug() << "Observed output:" << result;
|
||||||
|
QVERIFY(p.second == result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class TestTextFormatter : public QObject
|
class TestTextFormatter : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -293,8 +295,10 @@ private slots:
|
||||||
void singleAndDoubleMarkdownExceptionsShowSymbols();
|
void singleAndDoubleMarkdownExceptionsShowSymbols();
|
||||||
void singleAndDoubleMarkdownExceptionsHideSymbols();
|
void singleAndDoubleMarkdownExceptionsHideSymbols();
|
||||||
void mixedFormattingSpecialCases();
|
void mixedFormattingSpecialCases();
|
||||||
|
void urlTest();
|
||||||
private:
|
private:
|
||||||
MarkdownFunction markdownFunction;
|
const MarkdownFunction markdownFunction = applyMarkdown;
|
||||||
|
UrlHighlightFunction urlHighlightFunction = highlightURL;
|
||||||
};
|
};
|
||||||
|
|
||||||
static QString commonWorkCasesProcessInput(const QString& str, const MarkdownToTags& mtt)
|
static QString commonWorkCasesProcessInput(const QString& str, const MarkdownToTags& mtt)
|
||||||
|
@ -443,6 +447,11 @@ void TestTextFormatter::mixedFormattingSpecialCases()
|
||||||
specialCasesTest(markdownFunction, MIXED_FORMATTING_SPECIAL_CASES);
|
specialCasesTest(markdownFunction, MIXED_FORMATTING_SPECIAL_CASES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestTextFormatter::urlTest()
|
||||||
|
{
|
||||||
|
urlHighlightTest(urlHighlightFunction, URL_CASES);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(TestTextFormatter)
|
QTEST_GUILESS_MAIN(TestTextFormatter)
|
||||||
#include "textformatter_test.moc"
|
#include "textformatter_test.moc"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user