def test_post_process_node_many_children(): b = Builder() node = InternalNode([ LeafNode.build(Variable.build('a')), LeafNode.build(Variable.build('b')), LeafNode.build(Variable.build('c')) ]) as_list = node.to_list() result = b._post_process_node(node, False) assert result == [node] assert result[0].to_list() == as_list
def test_build_many_leaf_node_children(): b = Builder() children = [ LeafNode.build(Variable.build('a')), LeafNode.build(Variable.build('b')), LeafNode.build(Variable.build('c')) ] b.add_child(InternalNode.build(children)) result = b.build() assert type(result) is InternalNode assert len(result.get_children()) == len(children) for child in children: assert child in result.get_children()
def test_build_one_leaf_node_child(): b = Builder() child = LeafNode.build(Variable.build('a')) b.add_child(child) result = b.build() assert result is child
def test_simplify_node_with_many_children(): b = Builder() grandchildren = [ LeafNode.build(Variable.build('a')), LeafNode.build(Variable.build('b')), LeafNode.build(Variable.build('c')) ] for grandchild in grandchildren: b.add_child(InternalNode.build([grandchild])) result = b.build() assert type(result) is InternalNode assert len(result.get_children()) == len(grandchildren) for grandchild in grandchildren: assert grandchild in result.get_children()
def test_build_one_child_with_leaf_node_grandchild(): b = Builder() grandchild = LeafNode.build(Variable.build('a')) child = InternalNode.build([grandchild]) b.add_child(child) result = b.build() assert result is grandchild
def parse(self, token_list): if token_list != [] and token_list[0].matches(self): state = ParseState.build(LeafNode.build(token_list[0]), token_list[1:]) else: state = FAILURE return state
def test_simplify_acts_on_all_children(): b = Builder() grandchildren = [ LeafNode.build(Variable.build('a')), LeafNode.build(Variable.build('b')), LeafNode.build(Variable.build('c')) ] children = [] for grandchild in grandchildren: node = InternalNode.build([grandchild]) b.add_child(node) children.append(node) b.simplify() for grandchild in grandchildren: assert grandchild in b._children for child in children: assert child not in b._children
def test_post_process_node_one_child(): b = Builder() deep_leaf_node = LeafNode.build(Variable.build('a')) node = InternalNode.build([InternalNode.build([deep_leaf_node])]) assert b._post_process_node(node, False) == [deep_leaf_node]
def test_simplify_node_with_leaf_node(): b = Builder() child = LeafNode.build(Variable.build('a')) result = b._simplify_node(child) assert result == [child]