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 <noreply@anthropic.com>
(cherry picked from commit 1b05d1593c)
This commit is contained in:
MalikHaroonKhokhar authored and safishamsi committed 2026-10-05 19:40:04 +01:00
1 parent e4c48bf97e
commit eb283ca58b
1 file changed
+34
+34
View File
@@ -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")