Skip to content

Commit d1fb773

Browse files
Add test method for getHyperlinkUrlText
1 parent a85a1a6 commit d1fb773

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tests/TestTools.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,16 @@ void TestTools::testIsBase64()
6464
QVERIFY(not Tools::isBase64(QByteArray("abc_")));
6565
QVERIFY(not Tools::isBase64(QByteArray("123")));
6666
}
67+
68+
void TestTools::testGetHyperlinkUrlText()
69+
{
70+
// valid links wrapped with <a> tag
71+
QCOMPARE(Tools::getHyperlinkUrlText("http://example.com"), QString("<a href=\"http://example.com\">http://example.com</a>"));
72+
QCOMPARE(Tools::getHyperlinkUrlText("test https://www.example.com/test foobar"), QString("test <a href=\"https://www.example.com/test\">https://www.example.com/test</a> foobar"));
73+
QCOMPARE(Tools::getHyperlinkUrlText("ftp://example.com"), QString("<a href=\"ftp://example.com\">ftp://example.com</a>"));
74+
75+
// other text not wrapped
76+
QCOMPARE(Tools::getHyperlinkUrlText("not a url"), QString("not a url"));
77+
QCOMPARE(Tools::getHyperlinkUrlText(""), QString(""));
78+
QCOMPARE(Tools::getHyperlinkUrlText(" "), QString(" "));
79+
}

tests/TestTools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ private slots:
2727
void testHumanReadableFileSize();
2828
void testIsHex();
2929
void testIsBase64();
30+
void testGetHyperlinkUrlText();
3031
};
3132

3233
#endif // KEEPASSX_TESTTOOLS_H

0 commit comments

Comments
 (0)