2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 0b21f870 authored by eckhart's avatar eckhart
Browse files

- syntaxtree.Node.select: Bugfix!!!

parent b2bc5810
...@@ -616,10 +616,9 @@ class Node(collections.abc.Sized): ...@@ -616,10 +616,9 @@ class Node(collections.abc.Sized):
""" """
if include_root and match_function(self): if include_root and match_function(self):
yield self yield self
else: for child in self.children:
for child in self.children: for node in child.select(match_function, True):
for node in child.select(match_function, True): yield node
yield node
def select_by_tag(self, tag_names: Union[str, AbstractSet[str]], def select_by_tag(self, tag_names: Union[str, AbstractSet[str]],
......
...@@ -75,6 +75,11 @@ class TestNode: ...@@ -75,6 +75,11 @@ class TestNode:
assert str(self.unique_tree) == "ceh" assert str(self.unique_tree) == "ceh"
assert str(self.recurr_tree) == "xey" assert str(self.recurr_tree) == "xey"
def test_select_subnodes(self):
tags = [node.tag_name
for node in self.unique_tree.select(lambda nd: True, include_root=True)]
assert ''.join(tags) == "abdfg", ''.join(tags)
def test_find(self): def test_find(self):
found = list(self.unique_tree.select(lambda nd: not nd.children and nd.result == "e")) found = list(self.unique_tree.select(lambda nd: not nd.children and nd.result == "e"))
assert len(found) == 1 assert len(found) == 1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment