diff options
| author | Gregory Szorc <gregory.szorc@gmail.com> | 2012-07-12 05:05:56 +0000 |
|---|---|---|
| committer | Gregory Szorc <gregory.szorc@gmail.com> | 2012-07-12 05:05:56 +0000 |
| commit | bdbb73d27699e5d46e5c6f585eb4bdfa10175344 (patch) | |
| tree | 9833df0771d24a31081cce8f0ea9db240f39e20f /clang/bindings/python/tests | |
| parent | f1b7e3c7ba0a76adf61aa931bee1c7a4b5c05bcc (diff) | |
| download | bcm5719-llvm-bdbb73d27699e5d46e5c6f585eb4bdfa10175344.tar.gz bcm5719-llvm-bdbb73d27699e5d46e5c6f585eb4bdfa10175344.zip | |
[clang.py] Add TranslationUnit.get_{file,source_location,source_range}
llvm-svn: 160107
Diffstat (limited to 'clang/bindings/python/tests')
| -rw-r--r-- | clang/bindings/python/tests/cindex/test_translation_unit.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/clang/bindings/python/tests/cindex/test_translation_unit.py b/clang/bindings/python/tests/cindex/test_translation_unit.py index 982a6089431..9de12ad462a 100644 --- a/clang/bindings/python/tests/cindex/test_translation_unit.py +++ b/clang/bindings/python/tests/cindex/test_translation_unit.py @@ -1,6 +1,9 @@ from clang.cindex import CursorKind from clang.cindex import Cursor +from clang.cindex import File from clang.cindex import Index +from clang.cindex import SourceLocation +from clang.cindex import SourceRange from clang.cindex import TranslationUnitSaveError from clang.cindex import TranslationUnit from .util import get_cursor @@ -151,3 +154,66 @@ def test_index_parse(): index = Index.create() tu = index.parse(path) assert isinstance(tu, TranslationUnit) + +def test_get_file(): + """Ensure tu.get_file() works appropriately.""" + + tu = get_tu('int foo();') + + f = tu.get_file('t.c') + assert isinstance(f, File) + assert f.name == 't.c' + + try: + f = tu.get_file('foobar.cpp') + except: + pass + else: + assert False + +def test_get_source_location(): + """Ensure tu.get_source_location() works.""" + + tu = get_tu('int foo();') + + location = tu.get_location('t.c', 2) + assert isinstance(location, SourceLocation) + assert location.offset == 2 + assert location.file.name == 't.c' + + location = tu.get_location('t.c', (1, 3)) + assert isinstance(location, SourceLocation) + assert location.line == 1 + assert location.column == 3 + assert location.file.name == 't.c' + +def test_get_source_range(): + """Ensure tu.get_source_range() works.""" + + tu = get_tu('int foo();') + + r = tu.get_extent('t.c', (1,4)) + assert isinstance(r, SourceRange) + assert r.start.offset == 1 + assert r.end.offset == 4 + assert r.start.file.name == 't.c' + assert r.end.file.name == 't.c' + + r = tu.get_extent('t.c', ((1,2), (1,3))) + assert isinstance(r, SourceRange) + assert r.start.line == 1 + assert r.start.column == 2 + assert r.end.line == 1 + assert r.end.column == 3 + assert r.start.file.name == 't.c' + assert r.end.file.name == 't.c' + + start = tu.get_location('t.c', 0) + end = tu.get_location('t.c', 5) + + r = tu.get_extent('t.c', (start, end)) + assert isinstance(r, SourceRange) + assert r.start.offset == 0 + assert r.end.offset == 5 + assert r.start.file.name == 't.c' + assert r.end.file.name == 't.c' |

