Skip to content

Commit

Permalink
fix random visit in traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
kugesan1105 committed Oct 8, 2024
1 parent d9ceb07 commit 86ebb25
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
16 changes: 10 additions & 6 deletions jac/jaclang/plugin/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,19 +877,23 @@ def edge_ref(
if edges_only:
connected_edges: list[EdgeArchitype] = []
for node in node_obj:
connected_edges += Jac.get_edges(
edges = Jac.get_edges(
node.__jac__, dir, filter_func, target_obj=targ_obj_set
)
return list(set(connected_edges))
connected_edges.extend(
edge for edge in edges if edge not in connected_edges
)
return connected_edges
else:
connected_nodes: list[NodeArchitype] = []
for node in node_obj:
nodes = Jac.edges_to_nodes(
node.__jac__, dir, filter_func, target_obj=targ_obj_set
)
connected_nodes.extend(
Jac.edges_to_nodes(
node.__jac__, dir, filter_func, target_obj=targ_obj_set
)
node for node in nodes if node not in connected_nodes
)
return list(set(connected_nodes))
return connected_nodes

@staticmethod
@hookimpl
Expand Down
20 changes: 20 additions & 0 deletions jac/jaclang/tests/fixtures/visit_order.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
node MyNode{
has Name:str;
}

edge a{}

edge b{}

with entry{
Start = MyNode("Start");
End = MyNode("End");
mid = MyNode("Middle");
root <+:a:+ Start;
root +:a:+> End;
root +:b:+> mid;
root +:a:+> mid;

print([root-->]);

}
9 changes: 9 additions & 0 deletions jac/jaclang/tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,3 +1115,12 @@ def test_entry_exit(self) -> None:
self.assertIn(
"Exiting at the end of walker: test_node(value=", stdout_value[11]
)

def test_visit_order(self) -> None:
"""Test entry and exit behavior of walker."""
captured_output = io.StringIO()
sys.stdout = captured_output
jac_import("visit_order", base_path=self.fixture_abs_path("./"))
sys.stdout = sys.__stdout__
stdout_value = captured_output.getvalue()
self.assertEqual("[MyNode(Name='End'), MyNode(Name='Middle')]\n", stdout_value)

0 comments on commit 86ebb25

Please sign in to comment.