diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2011-02-20 13:06:31 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2011-02-20 13:06:31 +0000 |
commit | bca07a4524feb4edec581062d631a13116320a24 (patch) | |
tree | a9243275843fbeaa590afc07ee888e006b8d54ea /bindings/python/tests/cindex | |
parent | 998bc5802ecdd65ce3b270f6c69a8ae8557f0a10 (diff) |
Notes
Diffstat (limited to 'bindings/python/tests/cindex')
-rw-r--r-- | bindings/python/tests/cindex/test_diagnostics.py | 25 | ||||
-rw-r--r-- | bindings/python/tests/cindex/test_translation_unit.py | 16 |
2 files changed, 35 insertions, 6 deletions
diff --git a/bindings/python/tests/cindex/test_diagnostics.py b/bindings/python/tests/cindex/test_diagnostics.py index 85187652917b5..c1ff0e38baada 100644 --- a/bindings/python/tests/cindex/test_diagnostics.py +++ b/bindings/python/tests/cindex/test_diagnostics.py @@ -3,8 +3,6 @@ from clang.cindex import * def tu_from_source(source): index = Index.create() tu = index.parse('INPUT.c', unsaved_files = [('INPUT.c', source)]) - # FIXME: Remove the need for this. - tu.index = index return tu # FIXME: We need support for invalid translation units to test better. @@ -46,3 +44,26 @@ def test_diagnostic_fixit(): assert tu.diagnostics[0].fixits[0].range.end.line == 1 assert tu.diagnostics[0].fixits[0].range.end.column == 30 assert tu.diagnostics[0].fixits[0].value == '.f0 = ' + +def test_diagnostic_range(): + index = Index.create() + tu = tu_from_source("""void f() { int i = "a" + 1; }""") + assert len(tu.diagnostics) == 1 + assert tu.diagnostics[0].severity == Diagnostic.Warning + assert tu.diagnostics[0].location.line == 1 + assert tu.diagnostics[0].location.column == 16 + assert tu.diagnostics[0].spelling.startswith('incompatible pointer to') + assert len(tu.diagnostics[0].fixits) == 0 + assert len(tu.diagnostics[0].ranges) == 1 + assert tu.diagnostics[0].ranges[0].start.line == 1 + assert tu.diagnostics[0].ranges[0].start.column == 20 + assert tu.diagnostics[0].ranges[0].end.line == 1 + assert tu.diagnostics[0].ranges[0].end.column == 27 + try: + tu.diagnostics[0].ranges[1].start.line + except IndexError: + assert True + else: + assert False + + diff --git a/bindings/python/tests/cindex/test_translation_unit.py b/bindings/python/tests/cindex/test_translation_unit.py index 3c05c3f06af44..f130db6aeb068 100644 --- a/bindings/python/tests/cindex/test_translation_unit.py +++ b/bindings/python/tests/cindex/test_translation_unit.py @@ -25,16 +25,24 @@ def test_parse_arguments(): assert spellings[-2] == 'hello' assert spellings[-1] == 'hi' +def test_reparse_arguments(): + path = os.path.join(kInputsDir, 'parse_arguments.c') + index = Index.create() + tu = index.parse(path, ['-DDECL_ONE=hello', '-DDECL_TWO=hi']) + tu.reparse() + spellings = [c.spelling for c in tu.cursor.get_children()] + assert spellings[-2] == 'hello' + assert spellings[-1] == 'hi' + def test_unsaved_files(): index = Index.create() - # FIXME: Why can't we just use "fake.h" here (instead of /tmp/fake.h)? - tu = index.parse('fake.c', unsaved_files = [ + tu = index.parse('fake.c', ['-I./'], unsaved_files = [ ('fake.c', """ -#include "/tmp/fake.h" +#include "fake.h" int x; int SOME_DEFINE; """), - ('/tmp/fake.h', """ + ('./fake.h', """ #define SOME_DEFINE y """) ]) |