[cfe-commits] r124953 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_diagnostics.py
Tobias Grosser
grosser at fim.uni-passau.de
Sat Feb 5 09:53:51 PST 2011
Author: grosser
Date: Sat Feb 5 11:53:51 2011
New Revision: 124953
URL: http://llvm.org/viewvc/llvm-project?rev=124953&view=rev
Log:
python bindings: fix Diagnostics.range iterator
The iterator did never throw an IndexError. It was therefore not possible
to use it in a normal foreach loop as that loop would never stop.
Modified:
cfe/trunk/bindings/python/clang/cindex.py
cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py
Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=124953&r1=124952&r2=124953&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sat Feb 5 11:53:51 2011
@@ -215,6 +215,8 @@
return int(_clang_getDiagnosticNumRanges(self.diag))
def __getitem__(self, key):
+ if (key >= len(self)):
+ raise IndexError
return _clang_getDiagnosticRange(self.diag, key)
return RangeIterator(self)
Modified: cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py?rev=124953&r1=124952&r2=124953&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py Sat Feb 5 11:53:51 2011
@@ -46,3 +46,26 @@
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
+
+
More information about the cfe-commits
mailing list