Add tests for inherited/inline form component nesting
Covers both extract_lazarus_form and extract_delphi_form with a shared
fixture containing an inherited block, an inline frame, and a plain
object sibling after both. Asserts the sibling still nests under the
right parent and that an event handler declared inside the inherited
block binds to that block, not to an ancestor.
(cherry picked from commit b1a37a8ed1)
This commit is contained in:
1 parent
d64b0be4c5
commit
fc2c354919
3 files changed
+98
No files matched your search
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
object ChildForm: TChildForm
|
||||
Caption = 'Child'
|
||||
inherited InheritedPanel: TPanel
|
||||
Left = 0
|
||||
OnClick = InheritedPanelClick
|
||||
end
|
||||
inline FrameHost: TFrameWidget
|
||||
Top = 10
|
||||
end
|
||||
object NativePanel: TPanel
|
||||
Top = 20
|
||||
end
|
||||
end
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
object ChildForm: TChildForm
|
||||
Caption = 'Child'
|
||||
inherited InheritedPanel: TPanel
|
||||
Left = 0
|
||||
OnClick = InheritedPanelClick
|
||||
end
|
||||
inline FrameHost: TFrameWidget
|
||||
Top = 10
|
||||
end
|
||||
object NativePanel: TPanel
|
||||
Top = 20
|
||||
end
|
||||
end
|
||||
@@ -25,6 +25,13 @@ def _edges_with_relation(r, *relations):
|
||||
return [e for e in r["edges"] if e["relation"] in relations]
|
||||
|
||||
|
||||
def _node_id_by_label(r, label):
|
||||
for n in r["nodes"]:
|
||||
if n["label"] == label:
|
||||
return n["id"]
|
||||
return None
|
||||
|
||||
|
||||
def test_pascal_no_error():
|
||||
from graphify.extract import extract_pascal
|
||||
r = extract_pascal(FIXTURES / "sample.pas")
|
||||
@@ -276,6 +283,39 @@ def test_lfm_no_dangling_edges():
|
||||
assert e["source"] in node_ids, f"Dangling source: {e}"
|
||||
|
||||
|
||||
def test_lfm_inherited_and_inline_blocks_nest_like_object():
|
||||
# "inherited" (ancestor-overridden component) and "inline" (embedded
|
||||
# frame) are declared with the same "Name: Class ... end" shape as
|
||||
# "object", but previously only "object" opened a nesting level. That
|
||||
# left the inherited block's own "end" popping a level it never pushed,
|
||||
# so the next sibling attached to the grandparent instead of its real
|
||||
# parent.
|
||||
from graphify.extract import extract_lazarus_form
|
||||
r = extract_lazarus_form(FIXTURES / "sample_inherited.lfm")
|
||||
child_form_nid = _node_id_by_label(r, "TChildForm")
|
||||
panel_nid = _node_id_by_label(r, "TPanel")
|
||||
assert child_form_nid is not None
|
||||
assert panel_nid is not None
|
||||
contains_edges = _edges_with_relation(r, "contains")
|
||||
assert any(
|
||||
e["source"] == child_form_nid and e["target"] == panel_nid
|
||||
for e in contains_edges
|
||||
), "NativePanel (declared after the inherited/inline blocks) should still nest under TChildForm"
|
||||
|
||||
|
||||
def test_lfm_event_inside_inherited_block_scoped_to_it():
|
||||
from graphify.extract import extract_lazarus_form
|
||||
r = extract_lazarus_form(FIXTURES / "sample_inherited.lfm")
|
||||
panel_nid = _node_id_by_label(r, "TPanel")
|
||||
handler_nid = _node_id_by_label(r, "InheritedPanelClick()")
|
||||
assert handler_nid is not None
|
||||
ref_edges = _edges_with_relation(r, "references")
|
||||
assert any(
|
||||
e["source"] == panel_nid and e["target"] == handler_nid
|
||||
for e in ref_edges
|
||||
), "OnClick inside the inherited block should reference the inherited panel, not an ancestor"
|
||||
|
||||
|
||||
# ── Lazarus Package (.lpk) ───────────────────────────────────────────────────
|
||||
|
||||
def test_lpk_no_error():
|
||||
@@ -376,6 +416,38 @@ def test_dfm_no_dangling_edges():
|
||||
assert e["source"] in node_ids, f"Dangling source: {e}"
|
||||
|
||||
|
||||
def test_dfm_inherited_and_inline_blocks_nest_like_object():
|
||||
# Same gap as the .lfm case: "inherited" (ancestor-overridden component)
|
||||
# and "inline" (embedded frame) open a nesting level just like "object"
|
||||
# does. Previously only "object" was recognized, so the inherited
|
||||
# block's "end" popped a level it never pushed and the next sibling
|
||||
# ended up attached to the grandparent instead of its real parent.
|
||||
from graphify.extract import extract_delphi_form
|
||||
r = extract_delphi_form(FIXTURES / "sample_inherited.dfm")
|
||||
child_form_nid = _node_id_by_label(r, "TChildForm")
|
||||
panel_nid = _node_id_by_label(r, "TPanel")
|
||||
assert child_form_nid is not None
|
||||
assert panel_nid is not None
|
||||
contains_edges = _edges_with_relation(r, "contains")
|
||||
assert any(
|
||||
e["source"] == child_form_nid and e["target"] == panel_nid
|
||||
for e in contains_edges
|
||||
), "NativePanel (declared after the inherited/inline blocks) should still nest under TChildForm"
|
||||
|
||||
|
||||
def test_dfm_event_inside_inherited_block_scoped_to_it():
|
||||
from graphify.extract import extract_delphi_form
|
||||
r = extract_delphi_form(FIXTURES / "sample_inherited.dfm")
|
||||
panel_nid = _node_id_by_label(r, "TPanel")
|
||||
handler_nid = _node_id_by_label(r, "InheritedPanelClick()")
|
||||
assert handler_nid is not None
|
||||
ref_edges = _edges_with_relation(r, "references")
|
||||
assert any(
|
||||
e["source"] == panel_nid and e["target"] == handler_nid
|
||||
for e in ref_edges
|
||||
), "OnClick inside the inherited block should reference the inherited panel, not an ancestor"
|
||||
|
||||
|
||||
def test_dfm_binary_returns_empty_not_crash():
|
||||
from graphify.extract import extract_delphi_form
|
||||
import tempfile, pathlib
|
||||
|
||||
Reference in new issue
Block a user