mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-15 16:39:43 +00:00
fix(pascal): extract enumerated types and their values
This commit is contained in:
1 parent
48d7c0e832
commit
8cf55d37be
2 files changed
+78
No files matched your search
@@ -1,9 +1,17 @@
|
||||
"""Tests for the Pascal/Delphi extractor."""
|
||||
from __future__ import annotations
|
||||
import importlib.util as _ilu
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures"
|
||||
|
||||
_needs_pascal = pytest.mark.skipif(
|
||||
_ilu.find_spec("tree_sitter_pascal") is None,
|
||||
reason="tree-sitter-pascal not installed (enum types need the AST path)",
|
||||
)
|
||||
|
||||
|
||||
def _labels(r):
|
||||
return [n["label"] for n in r["nodes"]]
|
||||
@@ -85,6 +93,44 @@ def test_pascal_inherits_from_base():
|
||||
assert found, "TDataProcessor should have at least one inherits edge"
|
||||
|
||||
|
||||
@_needs_pascal
|
||||
def test_pascal_enum_type_and_values_are_extracted(tmp_path):
|
||||
"""A Pascal enumerated type becomes a node with a `case_of` edge per value.
|
||||
|
||||
`declType` matched only class/interface/helper kinds, so an enumerated type
|
||||
(`TColor = (clRed, clGreen, clBlue);`) and all of its values fell through and
|
||||
were dropped — the whole type vanished. An enum's values are its cases, so
|
||||
each becomes a node with a `case_of` edge to the type, matching every other
|
||||
language with enums (Java #1719 / C# / Swift / Scala).
|
||||
"""
|
||||
from graphify.extract import extract_pascal
|
||||
p = tmp_path / "colors.pas"
|
||||
p.write_text(
|
||||
"unit Colors;\n"
|
||||
"interface\n"
|
||||
"type\n"
|
||||
" TColor = (clRed, clGreen, clBlue);\n"
|
||||
" TNum = Integer;\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"]}
|
||||
# Pre-fix the whole `TColor = (...)` declaration vanished.
|
||||
assert {"TColor", "clRed", "clGreen", "clBlue"} <= labels
|
||||
ids = {n["id"]: n["label"] for n in r["nodes"]}
|
||||
case_of = {
|
||||
(ids.get(e["source"]), ids.get(e["target"]))
|
||||
for e in r["edges"]
|
||||
if e["relation"] == "case_of"
|
||||
}
|
||||
assert ("TColor", "clRed") in case_of
|
||||
assert ("TColor", "clGreen") in case_of
|
||||
assert ("TColor", "clBlue") in case_of
|
||||
|
||||
|
||||
def test_pascal_finds_calls():
|
||||
from graphify.extract import extract_pascal
|
||||
r = extract_pascal(FIXTURES / "sample.pas")
|
||||
|
||||
Reference in new issue
Block a user