Skip to content

Commit 0a7c77c

Browse files
committed
test(cpp): distinguish union methods from data fields
Assisted-by: OpenAI Codex (GPT-6)
1 parent 35adf43 commit 0a7c77c

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎tests/test_cpp_nested_and_cli.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ def test_cpp_union_specifier_is_extracted(tmp_path):
123123
assert "Anon" not in labels
124124

125125

126+
def test_cpp_union_member_function_is_a_method(tmp_path):
127+
"""A union's method declaration must not become a data field."""
128+
source = tmp_path / "value.hpp"
129+
source.write_text("union Value { int i; int get() const; };\n", encoding="utf-8")
130+
result = extract_cpp(source)
131+
assert result.get("parse_errors") is None
132+
labels = {n["id"]: n["label"] for n in result["nodes"]}
133+
relationships = {(labels.get(e["source"]), labels.get(e["target"]), e["relation"])
134+
for e in result["edges"]}
135+
assert ("Value", ".get()", "method") in relationships
136+
assert ("Value", "i", "defines") in relationships
137+
assert ("Value", "get", "defines") not in relationships
138+
assert "get" not in labels.values()
139+
140+
126141
def test_nested_cpp_class_is_extracted(tmp_path):
127142
# A nested type is a field_declaration whose `type` field IS the
128143
# class_specifier; the member-variable branch used to consume it and return

0 commit comments

Comments
 (0)