diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-08-17 17:01:10 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-08-17 17:01:10 +0000 |
commit | 2312f5f4df83f8f624765d9cb86fc8f0dc9c2659 (patch) | |
tree | 3c6b4f59392b5569926ea86cc232e585a4bfb2a7 /bindings/python/tests | |
parent | 9b10683a3f222d8dc6e139073ca96b97b439747b (diff) |
[python] Add test_type.py by Anders Waldenborg, which I forgot to commit in r137797.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137828 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/tests')
-rw-r--r-- | bindings/python/tests/cindex/test_type.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/bindings/python/tests/cindex/test_type.py b/bindings/python/tests/cindex/test_type.py new file mode 100644 index 0000000000..cd27a4cbb9 --- /dev/null +++ b/bindings/python/tests/cindex/test_type.py @@ -0,0 +1,76 @@ +from clang.cindex import Index, CursorKind, TypeKind + +kInput = """\ + +typedef int I; + +struct teststruct { + int a; + I b; + long c; + unsigned long d; + signed long e; + const int f; + int *g; + int ***h; +}; + +""" + +def test_a_struct(): + index = Index.create() + tu = index.parse('t.c', unsaved_files = [('t.c',kInput)]) + + for n in tu.cursor.get_children(): + if n.spelling == 'teststruct': + fields = list(n.get_children()) + + assert all(x.kind == CursorKind.FIELD_DECL for x in fields) + + assert fields[0].spelling == 'a' + assert not fields[0].type.is_const_qualified() + assert fields[0].type.kind == TypeKind.INT + assert fields[0].type.get_canonical().kind == TypeKind.INT + + assert fields[1].spelling == 'b' + assert not fields[1].type.is_const_qualified() + assert fields[1].type.kind == TypeKind.TYPEDEF + assert fields[1].type.get_canonical().kind == TypeKind.INT + assert fields[1].type.get_declaration().spelling == 'I' + + assert fields[2].spelling == 'c' + assert not fields[2].type.is_const_qualified() + assert fields[2].type.kind == TypeKind.LONG + assert fields[2].type.get_canonical().kind == TypeKind.LONG + + assert fields[3].spelling == 'd' + assert not fields[3].type.is_const_qualified() + assert fields[3].type.kind == TypeKind.ULONG + assert fields[3].type.get_canonical().kind == TypeKind.ULONG + + assert fields[4].spelling == 'e' + assert not fields[4].type.is_const_qualified() + assert fields[4].type.kind == TypeKind.LONG + assert fields[4].type.get_canonical().kind == TypeKind.LONG + + assert fields[5].spelling == 'f' + assert fields[5].type.is_const_qualified() + assert fields[5].type.kind == TypeKind.INT + assert fields[5].type.get_canonical().kind == TypeKind.INT + + assert fields[6].spelling == 'g' + assert not fields[6].type.is_const_qualified() + assert fields[6].type.kind == TypeKind.POINTER + assert fields[6].type.get_pointee().kind == TypeKind.INT + + assert fields[7].spelling == 'h' + assert not fields[7].type.is_const_qualified() + assert fields[7].type.kind == TypeKind.POINTER + assert fields[7].type.get_pointee().kind == TypeKind.POINTER + assert fields[7].type.get_pointee().get_pointee().kind == TypeKind.POINTER + assert fields[7].type.get_pointee().get_pointee().get_pointee().kind == TypeKind.INT + + break + + else: + assert False, "Didn't find teststruct??" |