From 3112727ee737363c612d52298872b4256e2d17a9 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Tue, 29 Sep 2026 10:49:24 +1300 Subject: [PATCH] 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 --- sources/scripting/qetscriptapi.cpp | 10 ++++--- tests/qttest/CMakeLists.txt | 2 +- tests/qttest/tst_scriptterminaluuid.cpp | 36 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/sources/scripting/qetscriptapi.cpp b/sources/scripting/qetscriptapi.cpp index c7344678a..53f3a41aa 100644 --- a/sources/scripting/qetscriptapi.cpp +++ b/sources/scripting/qetscriptapi.cpp @@ -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; } diff --git a/tests/qttest/CMakeLists.txt b/tests/qttest/CMakeLists.txt index f3726de04..e10e2ad16 100644 --- a/tests/qttest/CMakeLists.txt +++ b/tests/qttest/CMakeLists.txt @@ -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=\"$\"" "QET_EXAMPLES_DIR=\"${QET_DIR}/examples\"") diff --git a/tests/qttest/tst_scriptterminaluuid.cpp b/tests/qttest/tst_scriptterminaluuid.cpp index ff8bece9c..316282493 100644 --- a/tests/qttest/tst_scriptterminaluuid.cpp +++ b/tests/qttest/tst_scriptterminaluuid.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -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)