summaryrefslogtreecommitdiffstats
path: root/bindings/python/tests
diff options
context:
space:
mode:
authorTobias Grosser <grosser@fim.uni-passau.de>2011-10-31 00:31:32 +0000
committerTobias Grosser <grosser@fim.uni-passau.de>2011-10-31 00:31:32 +0000
commit58ba8c9f182c94553c8871086bf68e336a14a527 (patch)
tree7fd13ec6fc9555b77bafeb6ad2ba70b96d64757d /bindings/python/tests
parenta9ea5df14abb807eb0173e2737c5a1d61e86975b (diff)
cindex.py: Allow to create a cursor from file/row/column
We add a constructor to create a SourceLocation from a position in a file and we use this SourceLocation to retrieve a cursor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143322 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/tests')
-rw-r--r--bindings/python/tests/cindex/test_location.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/bindings/python/tests/cindex/test_location.py b/bindings/python/tests/cindex/test_location.py
index 47c1c6021f..300136f0cd 100644
--- a/bindings/python/tests/cindex/test_location.py
+++ b/bindings/python/tests/cindex/test_location.py
@@ -1,4 +1,4 @@
-from clang.cindex import Index
+from clang.cindex import Index, File, SourceLocation, Cursor
baseInput="int one;\nint two;\n"
@@ -35,6 +35,18 @@ def test_location():
if n.spelling == 'two':
assert_location(n.location,line=2,column=5,offset=14)
+ # define the expected location ourselves and see if it matches
+ # the returned location
+ tu = index.parse('t.c', unsaved_files = [('t.c',baseInput)])
+
+ file = File.from_name(tu, 't.c')
+ location = SourceLocation.from_position(tu, file, 1, 5)
+ cursor = Cursor.from_location(tu, location)
+
+ for n in tu.cursor.get_children():
+ if n.spelling == 'one':
+ assert n == cursor
+
def test_extent():
index = Index.create()
tu = index.parse('t.c', unsaved_files = [('t.c',baseInput)])