fix: type chooser [n] array modifier now works for primitive types

Array count defaults to 1 when clicking the [n] toggle.
This commit is contained in:
IChooseYou
2026-02-18 08:16:02 -07:00
parent bb466516ba
commit 57d55456a8
4 changed files with 131 additions and 9 deletions

View File

@@ -643,6 +643,36 @@ private slots:
QCOMPARE(vals.size(), ValueHistory::kCapacity);
QCOMPARE(vals.last(), vh.last());
}
// ── Test: inline edit "int32_t[4]" on primitive converts to array ──
void testInlineEditPrimitiveArray() {
// Find a primitive field to convert
int idx = -1;
for (int i = 0; i < m_doc->tree.nodes.size(); i++) {
if (m_doc->tree.nodes[i].name == "field_u32") { idx = i; break; }
}
QVERIFY(idx >= 0);
QCOMPARE(m_doc->tree.nodes[idx].kind, NodeKind::UInt32);
uint64_t nodeId = m_doc->tree.nodes[idx].id;
// Emit inlineEditCommitted with array syntax
emit m_editor->inlineEditCommitted(idx, 0, EditTarget::Type,
QStringLiteral("int32_t[4]"));
QApplication::processEvents();
// Node should now be an Array with elementKind=Int32, arrayLen=4
int newIdx = m_doc->tree.indexOfId(nodeId);
QVERIFY(newIdx >= 0);
QCOMPARE(m_doc->tree.nodes[newIdx].kind, NodeKind::Array);
QCOMPARE(m_doc->tree.nodes[newIdx].elementKind, NodeKind::Int32);
QCOMPARE(m_doc->tree.nodes[newIdx].arrayLen, 4);
// Undo should restore to UInt32
m_doc->undoStack.undo();
QApplication::processEvents();
newIdx = m_doc->tree.indexOfId(nodeId);
QVERIFY(newIdx >= 0);
QCOMPARE(m_doc->tree.nodes[newIdx].kind, NodeKind::UInt32);
}
};
QTEST_MAIN(TestController)

View File

@@ -736,6 +736,63 @@ private slots:
QVERIFY(listView);
QVERIFY(listView->model()->rowCount() > 2);
}
// ── FieldType popup: primitive with [n] creates an array ──
void testFieldTypePrimitiveArrayCreation() {
auto* doc = new RcxDocument();
buildTwoRootTree(doc->tree);
doc->provider = std::make_unique<BufferProvider>(makeBuffer());
auto* splitter = new QSplitter();
auto* ctrl = new RcxController(doc, nullptr);
ctrl->addSplitEditor(splitter);
splitter->resize(800, 600);
splitter->show();
QVERIFY(QTest::qWaitForWindowExposed(splitter));
ctrl->refresh();
QApplication::processEvents();
// Find the "x" field (Int32)
int xIdx = -1;
for (int i = 0; i < doc->tree.nodes.size(); i++) {
if (doc->tree.nodes[i].name == "x") { xIdx = i; break; }
}
QVERIFY(xIdx >= 0);
QCOMPARE(doc->tree.nodes[xIdx].kind, NodeKind::Int32);
uint64_t xNodeId = doc->tree.nodes[xIdx].id;
// Simulate the primitive-array path of applyTypePopupResult:
// beginMacro → changeNodeKind(Array) → ChangeArrayMeta → endMacro
doc->undoStack.beginMacro(QStringLiteral("Change to primitive array"));
ctrl->changeNodeKind(xIdx, NodeKind::Array);
xIdx = doc->tree.indexOfId(xNodeId);
QVERIFY(xIdx >= 0);
doc->undoStack.push(new RcxCommand(ctrl,
cmd::ChangeArrayMeta{xNodeId, doc->tree.nodes[xIdx].elementKind,
NodeKind::Int32,
doc->tree.nodes[xIdx].arrayLen, 4}));
doc->undoStack.endMacro();
QApplication::processEvents();
// Node should now be an Array
xIdx = doc->tree.indexOfId(xNodeId);
QVERIFY(xIdx >= 0);
QCOMPARE(doc->tree.nodes[xIdx].kind, NodeKind::Array);
QCOMPARE(doc->tree.nodes[xIdx].elementKind, NodeKind::Int32);
QCOMPARE(doc->tree.nodes[xIdx].arrayLen, 4);
// Single undo reverses the entire macro
doc->undoStack.undo();
QApplication::processEvents();
xIdx = doc->tree.indexOfId(xNodeId);
QVERIFY(xIdx >= 0);
QCOMPARE(doc->tree.nodes[xIdx].kind, NodeKind::Int32);
delete ctrl;
delete splitter;
delete doc;
}
};
QTEST_MAIN(TestTypeSelector)