PrismLauncher/tests/ModrinthUrl_test.cpp
unnameduser5000 92315147d6 Add support for modrinth://modpack links
Assisted-by: OpenAI gpt-5
Signed-off-by: unnameduser5000 <daiwentao167@gmail.com>
2026-05-10 22:25:31 +08:00

49 lines
1.4 KiB
C++

#include <QTest>
#include <modplatform/modrinth/ModrinthUrl.h>
class ModrinthUrlTest : public QObject {
Q_OBJECT
private slots:
void parseModpackLink_data()
{
QTest::addColumn<QString>("link");
QTest::addColumn<QString>("slug");
QTest::newRow("official") << "modrinth://modpack/fabulously-optimized" << "fabulously-optimized";
QTest::newRow("trailing slash") << "modrinth://modpack/fabulously-optimized/" << "fabulously-optimized";
QTest::newRow("case insensitive host") << "modrinth://MODPACK/fo" << "fo";
}
void parseModpackLink()
{
QFETCH(QString, link);
QFETCH(QString, slug);
auto parsed = Modrinth::parseModpackLink(QUrl(link));
QVERIFY(parsed.has_value());
QCOMPARE(parsed->slug, slug);
}
void rejectInvalidLinks_data()
{
QTest::addColumn<QString>("link");
QTest::newRow("wrong scheme") << "https://modrinth.com/modpack/fabulously-optimized";
QTest::newRow("missing slug") << "modrinth://modpack/";
QTest::newRow("unsupported resource") << "modrinth://mod/sodium";
QTest::newRow("extra path") << "modrinth://modpack/fabulously-optimized/version/latest";
}
void rejectInvalidLinks()
{
QFETCH(QString, link);
QVERIFY(!Modrinth::parseModpackLink(QUrl(link)).has_value());
}
};
QTEST_GUILESS_MAIN(ModrinthUrlTest)
#include "ModrinthUrl_test.moc"