diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-01-25 00:44:21 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-01-25 00:44:21 +0000 |
commit | 90859ae3b6acbdc48113cddb95984e3472a51772 (patch) | |
tree | 8bee1d76ea272f66ea40b7c79f10c444b9b51fe5 /bindings/python/tests | |
parent | 5b534f67946eeb2cb29076288bfee9707f055f82 (diff) |
cindex/Python: Add Cursor test.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94397 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/tests')
-rw-r--r-- | bindings/python/tests/cindex/test_cursor.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/bindings/python/tests/cindex/test_cursor.py b/bindings/python/tests/cindex/test_cursor.py new file mode 100644 index 0000000000..c0f778f0b8 --- /dev/null +++ b/bindings/python/tests/cindex/test_cursor.py @@ -0,0 +1,59 @@ +from clang.cindex import Index, CursorKind + +kInput = """\ +// FIXME: Find nicer way to drop builtins and other cruft. +int start_decl; + +struct s0 { + int a; + int b; +}; + +struct s1; + +void f0(int a0, int a1) { + int l0, l1; + + if (a0) + return; + + for (;;) { + break; + } +} +""" + +def test_get_children(): + index = Index.create(1, 1) + tu = index.parse('t.c', unsaved_files = [('t.c',kInput)]) + + # Skip until past start_decl. + it = tu.cursor.get_children() + while it.next().spelling != 'start_decl': + pass + + tu_nodes = list(it) + + assert len(tu_nodes) == 3 + + assert tu_nodes[0].kind == CursorKind.STRUCT_DECL + assert tu_nodes[0].spelling == 's0' + assert tu_nodes[0].is_definition() == True + assert tu_nodes[0].location.file.name == 't.c' + assert tu_nodes[0].location.line == 4 + assert tu_nodes[0].location.column == 8 + + s0_nodes = list(tu_nodes[0].get_children()) + assert len(s0_nodes) == 2 + assert s0_nodes[0].kind == CursorKind.FIELD_DECL + assert s0_nodes[0].spelling == 'a' + assert s0_nodes[1].kind == CursorKind.FIELD_DECL + assert s0_nodes[1].spelling == 'b' + + assert tu_nodes[1].kind == CursorKind.STRUCT_DECL + assert tu_nodes[1].spelling == 's1' + assert tu_nodes[1].is_definition() == False + + assert tu_nodes[2].kind == CursorKind.FUNCTION_DECL + assert tu_nodes[2].spelling == 'f0' + assert tu_nodes[2].is_definition() == True |