summaryrefslogtreecommitdiff
path: root/bindings
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-08-17 17:20:24 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-08-17 17:20:24 +0000
commit6b04623bcc64a5091a47fb18cd40af5e93b773ad (patch)
treefe68552cd580a308493b7a54f398e4b6c2795751 /bindings
parent2312f5f4df83f8f624765d9cb86fc8f0dc9c2659 (diff)
downloadclang-6b04623bcc64a5091a47fb18cd40af5e93b773ad.tar.gz
clang-6b04623bcc64a5091a47fb18cd40af5e93b773ad.tar.bz2
clang-6b04623bcc64a5091a47fb18cd40af5e93b773ad.tar.xz
[python] Fix bug of the SourceLocation binding.
Patch by Anders Waldenborg! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137829 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/clang/cindex.py2
-rw-r--r--bindings/python/tests/cindex/test_location.py50
2 files changed, 51 insertions, 1 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 2110170162..4b7dc005f6 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -112,7 +112,7 @@ class SourceLocation(Structure):
f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
SourceLocation_loc(self, byref(f), byref(l), byref(c), byref(o))
f = File(f) if f else None
- self._data = (f, int(l.value), int(c.value), int(c.value))
+ self._data = (f, int(l.value), int(c.value), int(o.value))
return self._data
@property
diff --git a/bindings/python/tests/cindex/test_location.py b/bindings/python/tests/cindex/test_location.py
new file mode 100644
index 0000000000..47c1c6021f
--- /dev/null
+++ b/bindings/python/tests/cindex/test_location.py
@@ -0,0 +1,50 @@
+from clang.cindex import Index
+
+baseInput="int one;\nint two;\n"
+
+def assert_location(loc, line, column, offset):
+ assert loc.line == line
+ assert loc.column == column
+ assert loc.offset == offset
+
+def test_location():
+ index = Index.create()
+ tu = index.parse('t.c', unsaved_files = [('t.c',baseInput)])
+
+ for n in tu.cursor.get_children():
+ if n.spelling == 'one':
+ assert_location(n.location,line=1,column=5,offset=4)
+ if n.spelling == 'two':
+ assert_location(n.location,line=2,column=5,offset=13)
+
+ # adding a linebreak at top should keep columns same
+ tu = index.parse('t.c', unsaved_files = [('t.c',"\n"+baseInput)])
+
+ for n in tu.cursor.get_children():
+ if n.spelling == 'one':
+ assert_location(n.location,line=2,column=5,offset=5)
+ if n.spelling == 'two':
+ assert_location(n.location,line=3,column=5,offset=14)
+
+ # adding a space should affect column on first line only
+ tu = index.parse('t.c', unsaved_files = [('t.c'," "+baseInput)])
+
+ for n in tu.cursor.get_children():
+ if n.spelling == 'one':
+ assert_location(n.location,line=1,column=6,offset=5)
+ if n.spelling == 'two':
+ assert_location(n.location,line=2,column=5,offset=14)
+
+def test_extent():
+ index = Index.create()
+ tu = index.parse('t.c', unsaved_files = [('t.c',baseInput)])
+
+ for n in tu.cursor.get_children():
+ if n.spelling == 'one':
+ assert_location(n.extent.start,line=1,column=1,offset=0)
+ assert_location(n.extent.end,line=1,column=8,offset=7)
+ assert baseInput[n.extent.start.offset:n.extent.end.offset] == "int one"
+ if n.spelling == 'two':
+ 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"