summaryrefslogtreecommitdiffstats
path: root/bindings/python/tests
diff options
context:
space:
mode:
authorGregory Szorc <gregory.szorc@gmail.com>2012-02-19 18:28:33 +0000
committerGregory Szorc <gregory.szorc@gmail.com>2012-02-19 18:28:33 +0000
commit31cc38cb76317bfe50aadbc625d6ff67f727607a (patch)
treea0a222436691c7ad339bb02879be60458ad86ae6 /bindings/python/tests
parent772291a67d483c1c2abf324eec5d8d6ca476bfdc (diff)
[clang.py] Implement Type.is_function_variadic
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150936 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/tests')
-rw-r--r--bindings/python/tests/cindex/test_type.py63
1 files changed, 45 insertions, 18 deletions
diff --git a/bindings/python/tests/cindex/test_type.py b/bindings/python/tests/cindex/test_type.py
index ba6af56e8b..c4869fdd5a 100644
--- a/bindings/python/tests/cindex/test_type.py
+++ b/bindings/python/tests/cindex/test_type.py
@@ -1,7 +1,6 @@
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 = """\
@@ -21,9 +20,18 @@ struct teststruct {
"""
-def test_a_struct():
+def get_tu(source=kInput, lang='c'):
+ name = 't.c'
+ if lang == 'cpp':
+ name = 't.cpp'
+
index = Index.create()
- tu = index.parse('t.c', unsaved_files = [('t.c',kInput)])
+ tu = index.parse(name, unsaved_files=[(name, source)])
+ assert tu is not None
+ return tu
+
+def test_a_struct():
+ tu = get_tu(kInput)
for n in tu.cursor.get_children():
if n.spelling == 'teststruct':
@@ -86,8 +94,7 @@ struct teststruct {
};
"""
def testConstantArray():
- index = Index.create()
- tu = index.parse('t.c', unsaved_files = [('t.c',constarrayInput)])
+ tu = get_tu(constarrayInput)
for n in tu.cursor.get_children():
if n.spelling == 'teststruct':
@@ -103,9 +110,7 @@ def testConstantArray():
assert False, "Didn't find teststruct??"
def test_is_pod():
- index = Index.create()
- tu = index.parse('t.c', unsaved_files=[('t.c', 'int i; void f();')])
- assert tu is not None
+ tu = get_tu('int i; void f();')
i, f = None, None
for cursor in tu.cursor.get_children():
@@ -120,24 +125,48 @@ 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
+def test_function_variadic():
+ """Ensure Type.is_function_variadic works."""
+
+ source ="""
+#include <stdarg.h>
+
+void foo(int a, ...);
+void bar(int a, int b);
+"""
+
+ tu = get_tu(source)
+ foo, bar = None, None
+ for cursor in tu.cursor.get_children():
+ if cursor.spelling == 'foo':
+ foo = cursor
+ elif cursor.spelling == 'bar':
+ bar = cursor
+
+ assert foo is not None
+ assert bar is not None
+ assert isinstance(foo.type.is_function_variadic(), bool)
+ assert foo.type.is_function_variadic()
+ assert not bar.type.is_function_variadic()
+
+def test_element_type():
+ tu = get_tu('int i[5];')
+ i = None
for cursor in tu.cursor.get_children():
if cursor.spelling == 'i':
i = cursor
break
+ assert i is not None
+
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;')])
+ tu = get_tu('int i;')
i = None
for cursor in tu.cursor.get_children():
@@ -145,13 +174,11 @@ def test_invalid_element_type():
i = cursor
break
- ok_(i is not None)
+ assert i is not None
i.element_type
def test_element_count():
- index = Index.create()
- tu = index.parse('t.c', unsaved_files=[('t.c', 'int i[5]; int j;')])
- assert tu is not None
+ tu = get_tu('int i[5]; int j;')
for cursor in tu.cursor.get_children():
if cursor.spelling == 'i':