From b18265951973dfb1e8ba236e8a80c6f3ee51345f Mon Sep 17 00:00:00 2001 From: Huanyi Xie <74809554+xiehuanyi@users.noreply.github.com> Date: Mon, 5 Oct 2026 17:40:36 +0300 Subject: [PATCH] test(cpp): distinguish union methods from data fields Assisted-by: OpenAI Codex (GPT-6) (cherry picked from commit 0a7c77cb6339b099dc3fe7312a4e2e46c20e23a7) --- tests/test_cpp_nested_and_cli.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_cpp_nested_and_cli.py b/tests/test_cpp_nested_and_cli.py index 300e5a589..1f5ddcc8c 100644 --- a/tests/test_cpp_nested_and_cli.py +++ b/tests/test_cpp_nested_and_cli.py @@ -123,6 +123,21 @@ def test_cpp_union_specifier_is_extracted(tmp_path): assert "Anon" not in labels +def test_cpp_union_member_function_is_a_method(tmp_path): + """A union's method declaration must not become a data field.""" + source = tmp_path / "value.hpp" + source.write_text("union Value { int i; int get() const; };\n", encoding="utf-8") + result = extract_cpp(source) + assert result.get("parse_errors") is None + labels = {n["id"]: n["label"] for n in result["nodes"]} + relationships = {(labels.get(e["source"]), labels.get(e["target"]), e["relation"]) + for e in result["edges"]} + assert ("Value", ".get()", "method") in relationships + assert ("Value", "i", "defines") in relationships + assert ("Value", "get", "defines") not in relationships + assert "get" not in labels.values() + + def test_nested_cpp_class_is_extracted(tmp_path): # A nested type is a field_declaration whose `type` field IS the # class_specifier; the member-variable branch used to consume it and return