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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user