summaryrefslogtreecommitdiffstats
path: root/bindings/python/tests
diff options
context:
space:
mode:
authorGregory Szorc <gregory.szorc@gmail.com>2012-02-17 07:44:46 +0000
committerGregory Szorc <gregory.szorc@gmail.com>2012-02-17 07:44:46 +0000
commit860576050b4d163a2f182cfdd67d8c5a48e32c08 (patch)
tree690c036f509b2ac366136f53fbacedbfc0426934 /bindings/python/tests
parentabb943284cabd9131586c2758a4f02baba668ace (diff)
[clang.py] Implement Type.element_type
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150799 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/tests')
-rw-r--r--bindings/python/tests/cindex/test_type.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/bindings/python/tests/cindex/test_type.py b/bindings/python/tests/cindex/test_type.py
index 26ed79553e..3eca780d04 100644
--- a/bindings/python/tests/cindex/test_type.py
+++ b/bindings/python/tests/cindex/test_type.py
@@ -1,4 +1,8 @@
-from clang.cindex import Index, CursorKind, TypeKind
+from clang.cindex import CursorKind
+from clang.cindex import Index
+from clang.cindex import TypeKind
+from nose.tools import ok_
+from nose.tools import raises
kInput = """\
@@ -115,3 +119,31 @@ def test_is_pod():
assert i.type.is_pod()
assert not f.type.is_pod()
+
+def test_element_type():
+ index = Index.create()
+ tu = index.parse('t.c', unsaved_files=[('t.c', 'int i[5];')])
+ assert tu is not None
+
+ for cursor in tu.cursor.get_children():
+ if cursor.spelling == 'i':
+ i = cursor
+ break
+
+ assert i.type.kind == TypeKind.CONSTANTARRAY
+ assert i.type.element_type.kind == TypeKind.INT
+
+@raises(Exception)
+def test_invalid_element_type():
+ """Ensure Type.element_type raises if type doesn't have elements."""
+ index = Index.create()
+ tu = index.parse('t.c', unsaved_files=[('t.c', 'int i;')])
+
+ i = None
+ for cursor in tu.cursor.get_children():
+ if cursor.spelling == 'i':
+ i = cursor
+ break
+
+ ok_(i is not None)
+ i.element_type