From eb283ca58b503043dd0919a89c4a1b1bbcfcdd83 Mon Sep 17 00:00:00 2001 From: MalikHaroonKhokhar Date: Mon, 5 Oct 2026 14:09:39 +0500 Subject: [PATCH] test(pascal): cover the valued enumerated form (#4071) Enum extraction (#4056) is only tested with the plain form, `TColor = (clRed, clGreen, clBlue)`. The valued form nests an explicit ordinal under declEnumValue -> defaultValue, beside the value's identifier, so a change to how the value's name is read could leak the literal into the label, or emit it as a node, without any test noticing. Add a test for `TColor = (clRed = 1, clGreen = 2)` asserting the type node, a `case_of` edge to each bare value name and to nothing else, and that neither literal becomes a node. Co-Authored-By: Claude Fable 5.1 (cherry picked from commit 1b05d1593c536f8bcadb4a77f6819167194dc29c) --- tests/test_pascal.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_pascal.py b/tests/test_pascal.py index 609360990..89c87f6a6 100644 --- a/tests/test_pascal.py +++ b/tests/test_pascal.py @@ -131,6 +131,40 @@ def test_pascal_enum_type_and_values_are_extracted(tmp_path): assert ("TColor", "clBlue") in case_of +@_needs_pascal +def test_pascal_valued_enum_literals_are_not_nodes(tmp_path): + """The valued form (`clRed = 1`) yields the same graph as the plain form. + + An explicit ordinal nests under declEnumValue -> defaultValue, beside the + value's identifier. Only the identifier names the case: the literal must not + leak into the value's label or become a node of its own (#4071). + """ + from graphify.extract import extract_pascal + p = tmp_path / "colors.pas" + p.write_text( + "unit Colors;\n" + "interface\n" + "type\n" + " TColor = (clRed = 1, clGreen = 2);\n" + "implementation\n" + "end.\n", + encoding="utf-8", + ) + r = extract_pascal(p) + assert "error" not in r + labels = {n["label"] for n in r["nodes"]} + assert {"TColor", "clRed", "clGreen"} <= labels + assert not {"1", "2"} & labels + ids = {n["id"]: n["label"] for n in r["nodes"]} + cases = { + ids.get(e["target"]) + for e in r["edges"] + if e["relation"] == "case_of" and ids.get(e["source"]) == "TColor" + } + # Exactly the two bare names: not `clRed = 1`, and no edge to a literal. + assert cases == {"clRed", "clGreen"} + + def test_pascal_finds_calls(): from graphify.extract import extract_pascal r = extract_pascal(FIXTURES / "sample.pas")