Files
graphify/tests/test_rust_anonymous_const.py
T
Huanyi Xie 28675a191c fix(rust): omit anonymous constants from graph symbol identity
Assisted-by: OpenAI Codex (GPT-6)
(cherry picked from commit 99159f362c)
2026-10-05 20:11:30 +01:00

25 lines
963 B
Python

"""Anonymous Rust constants must not replace their owning file node."""
from graphify.build import build_from_json
from graphify.extract import extract
def test_anonymous_constants_preserve_file_identity(tmp_path):
source = tmp_path / "codec.rs"
source.write_text(
"pub const WIDTH: usize = 8;\n"
"const _: () = assert!(WIDTH == 8);\n"
"const _: () = ();\n"
"static READY: bool = true;\n"
"pub fn encode() {}\n",
encoding="utf-8",
)
extracted = extract([source], root=tmp_path, cache_root=tmp_path / "cache")
graph = build_from_json(extracted, root=tmp_path, directed=False)
assert len({node["id"] for node in extracted["nodes"]}) == len(extracted["nodes"])
labels = {data["label"] for _, data in graph.nodes(data=True)}
assert {"codec.rs", "WIDTH", "READY", "encode()"} <= labels
assert "_" not in labels
assert all(source != target for source, target in graph.edges())