1 from clang.cindex import Index, CursorKind, TypeKind
4 // FIXME: Find nicer way to drop builtins and other cruft.
14 void f0(int a0, int a1) {
26 def test_get_children():
27 index = Index.create()
28 tu = index.parse('t.c', unsaved_files = [('t.c',kInput)])
30 # Skip until past start_decl.
31 it = tu.cursor.get_children()
32 while it.next().spelling != 'start_decl':
37 assert len(tu_nodes) == 3
39 assert tu_nodes[0].kind == CursorKind.STRUCT_DECL
40 assert tu_nodes[0].spelling == 's0'
41 assert tu_nodes[0].is_definition() == True
42 assert tu_nodes[0].location.file.name == 't.c'
43 assert tu_nodes[0].location.line == 4
44 assert tu_nodes[0].location.column == 8
46 s0_nodes = list(tu_nodes[0].get_children())
47 assert len(s0_nodes) == 2
48 assert s0_nodes[0].kind == CursorKind.FIELD_DECL
49 assert s0_nodes[0].spelling == 'a'
50 assert s0_nodes[0].type.kind == TypeKind.INT
51 assert s0_nodes[1].kind == CursorKind.FIELD_DECL
52 assert s0_nodes[1].spelling == 'b'
53 assert s0_nodes[1].type.kind == TypeKind.INT
55 assert tu_nodes[1].kind == CursorKind.STRUCT_DECL
56 assert tu_nodes[1].spelling == 's1'
57 assert tu_nodes[1].displayname == 's1'
58 assert tu_nodes[1].is_definition() == False
60 assert tu_nodes[2].kind == CursorKind.FUNCTION_DECL
61 assert tu_nodes[2].spelling == 'f0'
62 assert tu_nodes[2].displayname == 'f0(int, int)'
63 assert tu_nodes[2].is_definition() == True