Index: bindings/python/clang/cindex.py =================================================================== --- bindings/python/clang/cindex.py +++ bindings/python/clang/cindex.py @@ -279,6 +279,10 @@ # same file, in between lines if self.start.line < other.line < self.end.line: return True + # same file, same line + elif self.start.line == other.line == self.end.line: + if self.start.column <= other.column <= self.end.column: + return True elif self.start.line == other.line: # same file first line if self.start.column <= other.column: Index: bindings/python/tests/cindex/test_location.py =================================================================== --- bindings/python/tests/cindex/test_location.py +++ bindings/python/tests/cindex/test_location.py @@ -93,3 +93,34 @@ location3 = SourceLocation.from_position(tu, file, 1, 6) range3 = SourceRange.from_locations(location1, location3) assert range1 != range3 + +def test_contains(): + tu = get_tu(baseInput) + one = get_cursor(tu, 'one') + two = get_cursor(tu, 'two') + + assert one.location in one.extent + assert two.location in two.extent + assert one.location not in two.extent + assert two.location not in one.extent + + # adding a new line that has two statements + tu = get_tu(baseInput + "int three; int four;\n") + three = get_cursor(tu, 'three'); + four = get_cursor(tu, 'four'); + + assert three.location in three.extent + assert four.location in four.extent + assert three.location not in four.extent + assert four.location not in three.extent + + file = File.from_name(tu, 't.c') + # last character ';' of 'int three;' + location1 = SourceLocation.from_position(tu, file, 3, 10) + # 'f' in "int four;" + location2 = SourceLocation.from_position(tu, file, 3, 16) + + assert location1 in three.extent + assert location1 not in four.extent + assert location2 in four.extent + assert location2 not in three.extent