diff options
author | Tobias Grosser <grosser@fim.uni-passau.de> | 2012-02-05 11:40:59 +0000 |
---|---|---|
committer | Tobias Grosser <grosser@fim.uni-passau.de> | 2012-02-05 11:40:59 +0000 |
commit | fb7b4aa45a233e54711307f3d7c50a9848d5784f (patch) | |
tree | 3384daae565e1df75af60fe9503d3f4a27262a4f /clang/bindings/python/tests | |
parent | 4f4546b73abd417cb2fa3814d9c15461bb553b19 (diff) | |
download | bcm5719-llvm-fb7b4aa45a233e54711307f3d7c50a9848d5784f.tar.gz bcm5719-llvm-fb7b4aa45a233e54711307f3d7c50a9848d5784f.zip |
[clang.py] Implement __eq__ and __ne__ on SourceLocation and SourceRange
There is no type checking in __eq__, so ctypes will throw if the wrong
Python type is passed in to the C function. Personally, I feel garbage
in means garbage out and it isn't worth testing for this explicitly.
Contributed by: Gregory Szorc <gregory.szorc@gmail.com>
llvm-svn: 149824
Diffstat (limited to 'clang/bindings/python/tests')
-rw-r--r-- | clang/bindings/python/tests/cindex/test_location.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/clang/bindings/python/tests/cindex/test_location.py b/clang/bindings/python/tests/cindex/test_location.py index 300136f0cdc..1707f01aea9 100644 --- a/clang/bindings/python/tests/cindex/test_location.py +++ b/clang/bindings/python/tests/cindex/test_location.py @@ -1,4 +1,4 @@ -from clang.cindex import Index, File, SourceLocation, Cursor +from clang.cindex import Index, File, SourceLocation, SourceRange, Cursor baseInput="int one;\nint two;\n" @@ -47,6 +47,12 @@ def test_location(): if n.spelling == 'one': assert n == cursor + # Ensure locations referring to the same entity are equivalent. + location2 = SourceLocation.from_position(tu, file, 1, 5) + assert location == location2 + location3 = SourceLocation.from_position(tu, file, 1, 4) + assert location2 != location3 + def test_extent(): index = Index.create() tu = index.parse('t.c', unsaved_files = [('t.c',baseInput)]) @@ -60,3 +66,15 @@ def test_extent(): assert_location(n.extent.start,line=2,column=1,offset=9) assert_location(n.extent.end,line=2,column=8,offset=16) assert baseInput[n.extent.start.offset:n.extent.end.offset] == "int two" + + file = File.from_name(tu, 't.c') + location1 = SourceLocation.from_position(tu, file, 1, 1) + location2 = SourceLocation.from_position(tu, file, 1, 8) + + range1 = SourceRange.from_locations(location1, location2) + range2 = SourceRange.from_locations(location1, location2) + assert range1 == range2 + + location3 = SourceLocation.from_position(tu, file, 1, 6) + range3 = SourceRange.from_locations(location1, location3) + assert range1 != range3 |