From 105ad398b6ffb3e93ca0084e096c881a93d426cb Mon Sep 17 00:00:00 2001 From: batallion caputa Date: Sun, 8 Feb 2026 05:59:50 -0700 Subject: [PATCH] minorfixes --- src/core.h | 6 +++--- src/format.cpp | 19 +++++------------- tests/test_compose.cpp | 25 +++++++----------------- tests/test_core.cpp | 6 +++--- tests/test_format.cpp | 19 +++++++++--------- tests/test_new_features.cpp | 39 +++++++++++++++++++++++++++++++++++++ 6 files changed, 67 insertions(+), 47 deletions(-) diff --git a/src/core.h b/src/core.h index 2f10a1a..16db5d4 100644 --- a/src/core.h +++ b/src/core.h @@ -72,9 +72,9 @@ inline constexpr KindMeta kKindMeta[] = { {NodeKind::Bool, "Bool", "bool", 1, 1, 1, KF_None}, {NodeKind::Pointer32, "Pointer32", "ptr32", 4, 1, 4, KF_None}, {NodeKind::Pointer64, "Pointer64", "ptr64", 8, 1, 8, KF_None}, - {NodeKind::Vec2, "Vec2", "Vec2", 8, 2, 4, KF_Vector}, - {NodeKind::Vec3, "Vec3", "Vec3", 12, 3, 4, KF_Vector}, - {NodeKind::Vec4, "Vec4", "Vec4", 16, 4, 4, KF_Vector}, + {NodeKind::Vec2, "Vec2", "Vec2", 8, 1, 4, KF_Vector}, + {NodeKind::Vec3, "Vec3", "Vec3", 12, 1, 4, KF_Vector}, + {NodeKind::Vec4, "Vec4", "Vec4", 16, 1, 4, KF_Vector}, {NodeKind::Mat4x4, "Mat4x4", "Mat4x4", 64, 4, 4, KF_None}, {NodeKind::UTF8, "UTF8", "char[]", 1, 1, 1, KF_String}, {NodeKind::UTF16, "UTF16", "wchar_t[]", 2, 1, 2, KF_String}, diff --git a/src/format.cpp b/src/format.cpp index af6aa1a..963ba2e 100644 --- a/src/format.cpp +++ b/src/format.cpp @@ -245,12 +245,11 @@ static QString readValueImpl(const Node& node, const Provider& prov, case NodeKind::Vec2: case NodeKind::Vec3: case NodeKind::Vec4: { - int maxSub = linesForKind(node.kind); - if (subLine < 0 || subLine >= maxSub) return QStringLiteral("?"); - float component = prov.readF32(addr + subLine * 4); - if (!display) return fmtFloat(component).trimmed(); - static const char* labels[] = {"x", "y", "z", "w"}; - return QString(labels[subLine]) + QStringLiteral(" = ") + fmtFloat(component); + int count = sizeForKind(node.kind) / 4; + QStringList parts; + for (int i = 0; i < count; i++) + parts << fmtFloat(prov.readF32(addr + i * 4)).trimmed(); + return parts.join(QStringLiteral(", ")); } case NodeKind::Mat4x4: { if (!display) return {}; // not editable as single value @@ -314,14 +313,6 @@ QString fmtNodeLine(const Node& node, const Provider& prov, return ind + QString(prefixW, ' ') + val + cmtSuffix; } - // For vector types, subLine selects component - if (subLine > 0 && (node.kind == NodeKind::Vec2 || - node.kind == NodeKind::Vec3 || - node.kind == NodeKind::Vec4)) { - QString val = fit(readValue(node, prov, addr, subLine), COL_VALUE); - return ind + QString(prefixW, ' ') + val + cmtSuffix; - } - // Hex nodes and Padding: hex byte preview if (isHexPreview(node.kind)) { if (node.kind == NodeKind::Padding) { diff --git a/tests/test_compose.cpp b/tests/test_compose.cpp index 2bfc67c..f730b2a 100644 --- a/tests/test_compose.cpp +++ b/tests/test_compose.cpp @@ -58,7 +58,7 @@ private slots: QCOMPARE(result.meta[4].lineKind, LineKind::Footer); } - void testVec3Continuation() { + void testVec3SingleLine() { NodeTree tree; tree.baseAddress = 0; @@ -79,28 +79,17 @@ private slots: NullProvider prov; ComposeResult result = compose(tree, prov); - // CommandRow + CommandRow2 + 3 Vec3 lines + root footer = 6 - QCOMPARE(result.meta.size(), 6); + // CommandRow + CommandRow2 + 1 Vec3 line + root footer = 4 + QCOMPARE(result.meta.size(), 4); - // Line 2 (first Vec3 component): not continuation, depth 1 + // Line 2: single Vec3 line, not continuation, depth 1 QVERIFY(!result.meta[2].isContinuation); QCOMPARE(result.meta[2].offsetText, QString("0")); QCOMPARE(result.meta[2].depth, 1); + QCOMPARE(result.meta[2].nodeKind, NodeKind::Vec3); - // Lines 3-4: continuation, depth 1 - QVERIFY(result.meta[3].isContinuation); - QCOMPARE(result.meta[3].offsetText, QString(" \u00B7")); - QCOMPARE(result.meta[3].depth, 1); - QVERIFY(result.meta[4].isContinuation); - QCOMPARE(result.meta[4].offsetText, QString(" \u00B7")); - QCOMPARE(result.meta[4].depth, 1); - - // Continuation marker - QVERIFY(result.meta[3].markerMask & (1u << M_CONT)); - QVERIFY(result.meta[4].markerMask & (1u << M_CONT)); - - // Line 5 is root footer - QCOMPARE(result.meta[5].lineKind, LineKind::Footer); + // Line 3 is root footer + QCOMPARE(result.meta[3].lineKind, LineKind::Footer); } void testPaddingMarker() { diff --git a/tests/test_core.cpp b/tests/test_core.cpp index 1e9389c..c956cf6 100644 --- a/tests/test_core.cpp +++ b/tests/test_core.cpp @@ -18,9 +18,9 @@ private slots: void testLinesForKind() { QCOMPARE(rcx::linesForKind(rcx::NodeKind::Hex32), 1); - QCOMPARE(rcx::linesForKind(rcx::NodeKind::Vec2), 2); - QCOMPARE(rcx::linesForKind(rcx::NodeKind::Vec3), 3); - QCOMPARE(rcx::linesForKind(rcx::NodeKind::Vec4), 4); + QCOMPARE(rcx::linesForKind(rcx::NodeKind::Vec2), 1); + QCOMPARE(rcx::linesForKind(rcx::NodeKind::Vec3), 1); + QCOMPARE(rcx::linesForKind(rcx::NodeKind::Vec4), 1); QCOMPARE(rcx::linesForKind(rcx::NodeKind::Mat4x4), 4); } diff --git a/tests/test_format.cpp b/tests/test_format.cpp index 3fcae7a..ad870b6 100644 --- a/tests/test_format.cpp +++ b/tests/test_format.cpp @@ -222,21 +222,21 @@ private slots: } void testReadValueBoundsCheck() { - // Vec2 subLine=2 (out of bounds) should return "?" + // Vec2 single-line: subLine=0 returns all components QByteArray data(16, '\0'); BufferProvider prov(data); Node n; n.kind = NodeKind::Vec2; n.name = "v"; - QCOMPARE(fmt::readValue(n, prov, 0, 2), QString("?")); - QCOMPARE(fmt::readValue(n, prov, 0, -1), QString("?")); + QVERIFY(fmt::readValue(n, prov, 0, 0).contains(",")); - // Vec3 subLine=3 (out of bounds) + // Vec3 single-line: subLine=0 returns 3 comma-separated values n.kind = NodeKind::Vec3; - QCOMPARE(fmt::readValue(n, prov, 0, 3), QString("?")); + QCOMPARE(fmt::readValue(n, prov, 0, 0).count(','), 2); - // Vec3 subLine=2 (valid) - QVERIFY(fmt::readValue(n, prov, 0, 2) != QString("?")); + // Vec4 single-line: subLine=0 returns 4 comma-separated values + n.kind = NodeKind::Vec4; + QCOMPARE(fmt::readValue(n, prov, 0, 0).count(','), 3); } void testEditableValueBasic() { @@ -252,9 +252,10 @@ private slots: QString s = fmt::editableValue(n, prov, 0, 0); QVERIFY(s.contains("3.14")); - // Vec2 out of bounds → "?" + // Vec2 single-line: returns comma-separated values n.kind = NodeKind::Vec2; - QCOMPARE(fmt::editableValue(n, prov, 0, 2), QString("?")); + QString vec2 = fmt::editableValue(n, prov, 0, 0); + QVERIFY(vec2.contains(",")); } void testParseValueEmptyString() { diff --git a/tests/test_new_features.cpp b/tests/test_new_features.cpp index c09a39c..5ba71c2 100644 --- a/tests/test_new_features.cpp +++ b/tests/test_new_features.cpp @@ -860,6 +860,45 @@ private slots: QVERIFY(cpp.contains("my_float speed;")); } } + void testVec4SingleLineValue() { + NodeTree tree; + tree.baseAddress = 0; + + Node root; + root.kind = NodeKind::Struct; + root.name = "Obj"; + root.parentId = 0; + int ri = tree.addNode(root); + uint64_t rootId = tree.nodes[ri].id; + + Node v; + v.kind = NodeKind::Vec4; + v.name = "position"; + v.parentId = rootId; + v.offset = 0; + tree.addNode(v); + + NullProvider prov; + ComposeResult result = compose(tree, prov); + + // CommandRow + CommandRow2 + 1 Vec4 line + footer = 4 + QCOMPARE(result.meta.size(), 4); + + // The Vec4 line (index 2) is a single field line, not continuation + QCOMPARE(result.meta[2].lineKind, LineKind::Field); + QCOMPARE(result.meta[2].nodeKind, NodeKind::Vec4); + QVERIFY(!result.meta[2].isContinuation); + + // Copy text (equivalent to editor's "Copy All as Text") + QString text = result.text; + // NullProvider reads 0 for all floats, so values are "0, 0, 0, 0" + QVERIFY(text.contains("0, 0, 0, 0")); + // Confirm type, name, and values all on the same line + QStringList lines = text.split('\n'); + QVERIFY(lines[2].contains("Vec4")); + QVERIFY(lines[2].contains("position")); + QVERIFY(lines[2].contains("0, 0, 0, 0")); + } }; QTEST_MAIN(TestNewFeatures)