Reject more template mistakes

Empty keys, duplicate layer names and section ids, repeat on non-keysym
keys and stretch on letters/keys placeholders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-15 10:13:56 +02:00
co-authored by Claude Opus 5.5
parent 990d62ffcf
commit cfea9ece99
2 changed files with 49 additions and 0 deletions
+28
View File
@@ -40,6 +40,34 @@ private Q_SLOTS:
QVERIFY(error.contains(u"warp"));
}
void rejectsInvalidTemplates_data()
{
QTest::addColumn<QByteArray>("json");
QTest::addColumn<QString>("why");
const auto row = [](const char *key) {
return QByteArray(R"({"id": "t", "layers": [{"name": "l", "rows": [[)") + key + "]]}]}";
};
QTest::newRow("empty key") << row(R"("")") << u"empty"_s;
QTest::newRow("repeat") << row(R"({"type": "backspace", "repeat": true})") << u"repeat"_s;
QTest::newRow("stretch") << row(R"({"type": "letters", "row": 0, "stretch": true})") << u"stretch"_s;
QTest::newRow("layer twice")
<< QByteArray(R"({"id": "t", "layers": [{"name": "l", "rows": [["a"]]}, {"name": "l", "rows": [["b"]]}]})")
<< u"duplicate layer"_s;
QTest::newRow("section twice")
<< QByteArray(R"({"id": "t", "layers": [{"name": "l", "rows": [["a"]]}], "sections": [)"
R"({"id": "s", "rows": [["b"]]}, {"id": "s", "rows": [["c"]]}]})")
<< u"duplicate section"_s;
}
void rejectsInvalidTemplates()
{
QFETCH(QByteArray, json);
QFETCH(QString, why);
QString error;
QVERIFY(!LayoutLoader::parse(json, &error));
QVERIFY2(error.contains(why), qPrintable(error));
}
void rejectsMissingId()
{
QString error;