1 from clang.cindex import *
4 kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS')
7 path = os.path.join(kInputsDir, 'hello.cpp')
10 assert tu.spelling == path
13 path = os.path.join(kInputsDir, 'hello.cpp')
14 index = Index.create()
15 tu = index.parse(path)
17 assert isinstance(c, Cursor)
18 assert c.kind is CursorKind.TRANSLATION_UNIT
20 def test_parse_arguments():
21 path = os.path.join(kInputsDir, 'parse_arguments.c')
22 index = Index.create()
23 tu = index.parse(path, ['-DDECL_ONE=hello', '-DDECL_TWO=hi'])
24 spellings = [c.spelling for c in tu.cursor.get_children()]
25 assert spellings[-2] == 'hello'
26 assert spellings[-1] == 'hi'
28 def test_unsaved_files():
29 index = Index.create()
30 # FIXME: Why can't we just use "fake.h" here (instead of /tmp/fake.h)?
31 tu = index.parse('fake.c', unsaved_files = [
33 #include "/tmp/fake.h"
41 spellings = [c.spelling for c in tu.cursor.get_children()]
42 assert spellings[-2] == 'x'
43 assert spellings[-1] == 'y'
45 def test_unsaved_files_2():
47 index = Index.create()
48 tu = index.parse('fake.c', unsaved_files = [
49 ('fake.c', StringIO.StringIO('int x;'))])
50 spellings = [c.spelling for c in tu.cursor.get_children()]
51 assert spellings[-1] == 'x'
55 def eq(expected, actual):
56 if not actual.is_input_file:
57 return expected[0] == actual.source.name and \
58 expected[1] == actual.include.name
60 return expected[1] == actual.include.name
62 src = os.path.join(kInputsDir, 'include.cpp')
63 h1 = os.path.join(kInputsDir, "header1.h")
64 h2 = os.path.join(kInputsDir, "header2.h")
65 h3 = os.path.join(kInputsDir, "header3.h")
66 inc = [(None, src), (src, h1), (h1, h3), (src, h2), (h2, h3)]
68 index = Index.create()
70 for i in zip(inc, tu.get_includes()):