Skip to content

Commit df86e54

Browse files
committed
[test_parse.py] changes coming from using the new tree
- New tree has uuids as identifiers (internal), as opposed to the Node (now ParsedInfo) objects
1 parent 7badb64 commit df86e54

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

tests/test_parse.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22
from clang_bind.parse import Parse
33

44
FILE = "file.cpp"
5-
ARGS = ["c++14"]
65

76

87
def parse(tmp_path, file_contents):
98
source_path = tmp_path / FILE
109
with open(source_path, "w") as f:
1110
f.write(str(file_contents))
1211

13-
tree = Parse(source_path, ARGS).get_tree() # parse the file into an AST
14-
tree_paths = (
15-
tree.paths_to_leaves()
16-
) # a list of list of nodes, representing paths from the root node to each leaf
17-
18-
return tree, tree_paths
12+
parser = Parse(source_path)
13+
tree = parser.get_tree() # parse the file into an AST
14+
tree_paths = [
15+
parser.get_parsed_infos_from_node_ids(path) for path in tree.paths_to_leaves()
16+
] # a list of list of parsed infos, representing paths from the root node to each leaf
17+
return parser, tree_paths
1918

2019

2120
def debug_print(tree, tree_paths):
@@ -126,16 +125,18 @@ def test_function_decl_with_parameters(tmp_path):
126125
file_contents = """
127126
int aFunction(int firstParam, double secondParam);
128127
"""
129-
tree, tree_paths = parse(tmp_path=tmp_path, file_contents=file_contents)
128+
parser, tree_paths = parse(tmp_path=tmp_path, file_contents=file_contents)
130129

131130
function_decl = tree_paths[0][1]
132131
assert function_decl.cursor.kind == clang.CursorKind.FUNCTION_DECL
133132
assert function_decl.cursor.spelling == "aFunction"
134133
assert function_decl.cursor.result_type.kind == clang.TypeKind.INT
135134

136-
function_decl_children = [
137-
child.identifier for child in tree.children(function_decl)
138-
]
135+
function_decl_children = parser.get_parsed_infos_from_node_ids(
136+
parser.get_node_ids_from_nodes(
137+
parser.get_children_nodes_from_parent_parsed_info(function_decl)
138+
)
139+
)
139140

140141
first_param = function_decl_children[0]
141142
assert first_param.cursor.spelling == "firstParam"

0 commit comments

Comments
 (0)