elementTerminals(): keep a "%3" or "%4" in a terminal's name as written

Review of the previous commit: the line was built with chained arg()
calls, so a "%3" in a terminal's name was replaced by the conductor
count -- as before -- and now a "%4" by the uuid as well. One
multi-argument arg() substitutes each placeholder of the pattern once.

percentInNameKept renames a terminal of perceuse.qet "x%3y%4": listed as
"x1y{uuid}" before, "x%3y%4" now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-29 10:49:24 +13:00
parent 9fdd6ac333
commit 3112727ee7
3 changed files with 43 additions and 5 deletions
+6 -4
View File
@@ -773,11 +773,13 @@ QStringList QetScriptApi::elementTerminals(int folioIndex, const QString &elemen
for (int i = 0 ; i < terminals.count() ; ++i)
{
Terminal *t = terminals.at(i);
//One multi-argument arg(): chained ones would also replace a
//"%3" or "%4" inside the terminal's name
list << QStringLiteral("%1: %2 (%3 conductor(s)) %4")
.arg(i)
.arg(t->name().isEmpty() ? QStringLiteral("-") : t->name())
.arg(t->conductorsCount())
.arg(t->stableUuid().toString());
.arg(QString::number(i),
t->name().isEmpty() ? QStringLiteral("-") : t->name(),
QString::number(t->conductorsCount()),
t->stableUuid().toString());
}
return list;
}
+1 -1
View File
@@ -352,7 +352,7 @@ if(QET_HAS_SCRIPTING)
tst_scriptterminaluuid.cpp)
add_test(NAME tst_scriptterminaluuid COMMAND tst_scriptterminaluuid)
add_dependencies(tst_scriptterminaluuid qelectrotech)
target_link_libraries(tst_scriptterminaluuid PRIVATE Qt::Test)
target_link_libraries(tst_scriptterminaluuid PRIVATE Qt::Test Qt::Xml)
target_compile_definitions(tst_scriptterminaluuid PRIVATE
"QET_TEST_BINARY_PATH=\"$<TARGET_FILE:qelectrotech>\""
"QET_EXAMPLES_DIR=\"${QET_DIR}/examples\"")
+36
View File
@@ -2,6 +2,7 @@
#include <QtTest>
#include <QFile>
#include <QDomDocument>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
@@ -114,6 +115,41 @@ private slots:
QCOMPARE(r.value(QStringLiteral("noElement")).toInt(), -1);
QCOMPARE(r.value(QStringLiteral("badFolio")).toInt(), -1);
}
// A "%3" or "%4" in a terminal's name is listed as written, not
// replaced by the conductor count or the uuid.
void percentInNameKept()
{
QFile in(QStringLiteral(QET_EXAMPLES_DIR "/perceuse.qet"));
QVERIFY(in.open(QIODevice::ReadOnly));
QDomDocument doc;
QVERIFY(bool(doc.setContent(&in)));
const QDomNodeList terminals = doc.documentElement()
.firstChildElement(QStringLiteral("collection"))
.elementsByTagName(QStringLiteral("terminal"));
QVERIFY(!terminals.isEmpty());
terminals.at(0).toElement().setAttribute(QStringLiteral("name"),
QStringLiteral("x%3y%4"));
const QString project = m_dir.filePath(QStringLiteral("percent.qet"));
QFile out(project);
QVERIFY(out.open(QIODevice::WriteOnly));
out.write(doc.toByteArray());
out.close();
const QJsonObject r = run(QStringLiteral(
"var hits = [];\n"
"for (var f = 0; f < qet.folioCount(); f++) {\n"
" var els = qet.elementUuids(f);\n"
" for (var e = 0; e < els.length; e++)\n"
" qet.elementTerminals(f, els[e]).forEach(function (l) {\n"
" if (/: x.*y.* \\(/.test(l)) hits.push(l); });\n"
"}\n"
"qet.log('PROBE ' + JSON.stringify({hits: hits}));\n"), project);
const QJsonArray hits = r.value(QStringLiteral("hits")).toArray();
QVERIFY2(!hits.isEmpty(), "the renamed terminal was not listed");
for (const QJsonValue &h : hits)
QVERIFY2(h.toString().contains(QStringLiteral(": x%3y%4 (")), qPrintable(h.toString()));
}
};
QTEST_APPLESS_MAIN(tst_scriptterminaluuid)