diff --git a/autotests/texthandlertest.cpp b/autotests/texthandlertest.cpp index a4cef2231..d19b5aef5 100644 --- a/autotests/texthandlertest.cpp +++ b/autotests/texthandlertest.cpp @@ -61,6 +61,7 @@ private Q_SLOTS: void receiveRichStrikethrough(); void receiveRichtextIn(); void receiveRichMxcUrl(); + void receiveRichPlainUrl_data(); void receiveRichPlainUrl(); void receiveRichEdited_data(); void receiveRichEdited(); @@ -450,6 +451,32 @@ void TextHandlerTest::receiveRichMxcUrl() QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText, room, room->messageEvents().at(0).get()), testOutputString); } +void TextHandlerTest::receiveRichPlainUrl_data() +{ + QTest::addColumn("input"); + QTest::addColumn("output"); + + // This is an actual link that caused trouble which is why it's so long. Keeping + // so we can confirm consistent behaviour for complex urls. + QTest::addRow("link 1") + << u"https://matrix.to/#/!RvzunyTWZGfNxJVQqv:matrix.org/$-9TJVTh5PvW6MvIhFDwteiyLBVGriinueO5eeIazQS8?via=libera.chat&via=matrix.org&via=fedora.im Link already rich"_s + << u"https://matrix.to/#/!RvzunyTWZGfNxJVQqv:matrix.org/$-9TJVTh5PvW6MvIhFDwteiyLBVGriinueO5eeIazQS8?via=libera.chat&via=matrix.org&via=fedora.im Link already rich"_s; + + // Another real case. The linkification wasn't handling it when a single link + // contains what looks like and email. It was broken into 3 but needs to + // be just single link. + QTest::addRow("link 2") + << u"https://lore.kernel.org/lkml/CAHk-=wio46vC4t6xXD-sFqjoPwFm_u515jm3suzmkGxQTeA1_A@mail.gmail.com/"_s + << u"https://lore.kernel.org/lkml/CAHk-=wio46vC4t6xXD-sFqjoPwFm_u515jm3suzmkGxQTeA1_A@mail.gmail.com/"_s; + + QTest::addRow("email") << uR"(email@example.com Link already rich)"_s + << uR"(email@example.com Link already rich)"_s; + QTest::addRow("mxid") + << u"@user:kde.org Link already rich"_s + << u"@user:kde.org Link already rich"_s; + QTest::addRow("mxid with prefix") << u"a @user:kde.org b"_s << u"a @user:kde.org b"_s; +} + /** * For when your rich input string has a plain text url left in. * @@ -458,46 +485,13 @@ void TextHandlerTest::receiveRichMxcUrl() */ void TextHandlerTest::receiveRichPlainUrl() { - // This is an actual link that caused trouble which is why it's so long. Keeping - // so we can confirm consistent behaviour for complex urls. - const QString testInputStringLink1 = - u"https://matrix.to/#/!RvzunyTWZGfNxJVQqv:matrix.org/$-9TJVTh5PvW6MvIhFDwteiyLBVGriinueO5eeIazQS8?via=libera.chat&via=matrix.org&via=fedora.im Link already rich"_s; - const QString testOutputStringLink1 = - u"https://matrix.to/#/!RvzunyTWZGfNxJVQqv:matrix.org/$-9TJVTh5PvW6MvIhFDwteiyLBVGriinueO5eeIazQS8?via=libera.chat&via=matrix.org&via=fedora.im Link already rich"_s; - - // Another real case. The linkification wasn't handling it when a single link - // contains what looks like and email. It was been broken into 3 but needs to - // be just single link. - const QString testInputStringLink2 = u"https://lore.kernel.org/lkml/CAHk-=wio46vC4t6xXD-sFqjoPwFm_u515jm3suzmkGxQTeA1_A@mail.gmail.com/"_s; - const QString testOutputStringLink2 = - u"https://lore.kernel.org/lkml/CAHk-=wio46vC4t6xXD-sFqjoPwFm_u515jm3suzmkGxQTeA1_A@mail.gmail.com/"_s; - - QString testInputStringEmail = uR"(email@example.com Link already rich)"_s; - QString testOutputStringEmail = uR"(email@example.com Link already rich)"_s; - - QString testInputStringMxId = u"@user:kde.org Link already rich"_s; - QString testOutputStringMxId = - u"@user:kde.org Link already rich"_s; - - QString testInputStringMxIdWithPrefix = u"a @user:kde.org b"_s; - QString testOutputStringMxIdWithPrefix = u"a @user:kde.org b"_s; + QFETCH(QString, input); + QFETCH(QString, output); TextHandler testTextHandler; - testTextHandler.setData(testInputStringLink1); + testTextHandler.setData(input); - QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText), testOutputStringLink1); - - testTextHandler.setData(testInputStringLink2); - QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText), testOutputStringLink2); - - testTextHandler.setData(testInputStringEmail); - QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText), testOutputStringEmail); - - testTextHandler.setData(testInputStringMxId); - QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText), testOutputStringMxId); - - testTextHandler.setData(testInputStringMxIdWithPrefix); - QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText), testOutputStringMxIdWithPrefix); + QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText), output); } void TextHandlerTest::receiveRichEdited_data()