[cfe-commits] r137829 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_location.py

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Aug 17 10:20:24 PDT 2011


Author: akirtzidis
Date: Wed Aug 17 12:20:24 2011
New Revision: 137829

URL: http://llvm.org/viewvc/llvm-project?rev=137829&view=rev
Log:
[python] Fix bug of the SourceLocation binding.
Patch by Anders Waldenborg!

Added:
    cfe/trunk/bindings/python/tests/cindex/test_location.py
Modified:
    cfe/trunk/bindings/python/clang/cindex.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=137829&r1=137828&r2=137829&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Wed Aug 17 12:20:24 2011
@@ -112,7 +112,7 @@
             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

Added: cfe/trunk/bindings/python/tests/cindex/test_location.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_location.py?rev=137829&view=auto
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_location.py (added)
+++ cfe/trunk/bindings/python/tests/cindex/test_location.py Wed Aug 17 12:20:24 2011
@@ -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"





More information about the cfe-commits mailing list