test_translation_unit.py revision 1f8d7f94c7c61c7bb45ebb07e6ce5461bf2a80d5
1from clang.cindex import *
2import os
3
4kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS')
5
6def test_spelling():
7    path = os.path.join(kInputsDir, 'hello.cpp')
8    index = Index.create()
9    tu = index.parse(path)
10    assert tu.spelling == path
11
12def test_cursor():
13    path = os.path.join(kInputsDir, 'hello.cpp')
14    index = Index.create()
15    tu = index.parse(path)
16    c = tu.cursor
17    assert isinstance(c, Cursor)
18    assert c.kind is CursorKind.TRANSLATION_UNIT
19
20def 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'
27