You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
INPUTS
bindings
python
clang
examples
tests
cindex
INPUTS
__init__.py
test_access_specifiers.py
test_cdb.py
test_code_completion.py
test_comment.py
test_cursor.py
test_cursor_kind.py
test_diagnostics.py
test_exception_specification_kind.py
test_file.py
test_index.py
test_linkage.py
test_location.py
test_tls_kind.py
test_token_kind.py
test_tokens.py
test_translation_unit.py
test_type.py
util.py
__init__.py
README.txt
xml
cmake
docs
examples
include
lib
runtime
tools
unittests
utils
www
.arcconfig
.clang-format
.clang-tidy
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
INSTALL.txt
LICENSE.TXT
ModuleInfo.txt
NOTES.txt
README.txt
clang-tools-extra
compiler-rt
eng
libcxx
libcxxabi
libunwind
lld
lldb
llvm
nuget
openmp
polly
Directory.Build.props
Directory.Build.targets
NuGet.config
azure-pipelines.yml
build.cmd
build.sh
dir.common.props
global.json
llvm.proj
mxe-Win64.cmake.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
101 lines
3.6 KiB
Python
101 lines
3.6 KiB
Python
![]() |
from clang.cindex import Cursor
|
||
|
from clang.cindex import File
|
||
|
from clang.cindex import SourceLocation
|
||
|
from clang.cindex import SourceRange
|
||
|
from .util import get_cursor
|
||
|
from .util import get_tu
|
||
|
|
||
|
import unittest
|
||
|
|
||
|
|
||
|
baseInput="int one;\nint two;\n"
|
||
|
|
||
|
|
||
|
class TestLocation(unittest.TestCase):
|
||
|
def assert_location(self, loc, line, column, offset):
|
||
|
self.assertEqual(loc.line, line)
|
||
|
self.assertEqual(loc.column, column)
|
||
|
self.assertEqual(loc.offset, offset)
|
||
|
|
||
|
def test_location(self):
|
||
|
tu = get_tu(baseInput)
|
||
|
one = get_cursor(tu, 'one')
|
||
|
two = get_cursor(tu, 'two')
|
||
|
|
||
|
self.assertIsNotNone(one)
|
||
|
self.assertIsNotNone(two)
|
||
|
|
||
|
self.assert_location(one.location,line=1,column=5,offset=4)
|
||
|
self.assert_location(two.location,line=2,column=5,offset=13)
|
||
|
|
||
|
# adding a linebreak at top should keep columns same
|
||
|
tu = get_tu('\n' + baseInput)
|
||
|
one = get_cursor(tu, 'one')
|
||
|
two = get_cursor(tu, 'two')
|
||
|
|
||
|
self.assertIsNotNone(one)
|
||
|
self.assertIsNotNone(two)
|
||
|
|
||
|
self.assert_location(one.location,line=2,column=5,offset=5)
|
||
|
self.assert_location(two.location,line=3,column=5,offset=14)
|
||
|
|
||
|
# adding a space should affect column on first line only
|
||
|
tu = get_tu(' ' + baseInput)
|
||
|
one = get_cursor(tu, 'one')
|
||
|
two = get_cursor(tu, 'two')
|
||
|
|
||
|
self.assert_location(one.location,line=1,column=6,offset=5)
|
||
|
self.assert_location(two.location,line=2,column=5,offset=14)
|
||
|
|
||
|
# define the expected location ourselves and see if it matches
|
||
|
# the returned location
|
||
|
tu = get_tu(baseInput)
|
||
|
|
||
|
file = File.from_name(tu, 't.c')
|
||
|
location = SourceLocation.from_position(tu, file, 1, 5)
|
||
|
cursor = Cursor.from_location(tu, location)
|
||
|
|
||
|
one = get_cursor(tu, 'one')
|
||
|
self.assertIsNotNone(one)
|
||
|
self.assertEqual(one, cursor)
|
||
|
|
||
|
# Ensure locations referring to the same entity are equivalent.
|
||
|
location2 = SourceLocation.from_position(tu, file, 1, 5)
|
||
|
self.assertEqual(location, location2)
|
||
|
location3 = SourceLocation.from_position(tu, file, 1, 4)
|
||
|
self.assertNotEqual(location2, location3)
|
||
|
|
||
|
offset_location = SourceLocation.from_offset(tu, file, 5)
|
||
|
cursor = Cursor.from_location(tu, offset_location)
|
||
|
verified = False
|
||
|
for n in [n for n in tu.cursor.get_children() if n.spelling == 'one']:
|
||
|
self.assertEqual(n, cursor)
|
||
|
verified = True
|
||
|
|
||
|
self.assertTrue(verified)
|
||
|
|
||
|
def test_extent(self):
|
||
|
tu = get_tu(baseInput)
|
||
|
one = get_cursor(tu, 'one')
|
||
|
two = get_cursor(tu, 'two')
|
||
|
|
||
|
self.assert_location(one.extent.start,line=1,column=1,offset=0)
|
||
|
self.assert_location(one.extent.end,line=1,column=8,offset=7)
|
||
|
self.assertEqual(baseInput[one.extent.start.offset:one.extent.end.offset], "int one")
|
||
|
|
||
|
self.assert_location(two.extent.start,line=2,column=1,offset=9)
|
||
|
self.assert_location(two.extent.end,line=2,column=8,offset=16)
|
||
|
self.assertEqual(baseInput[two.extent.start.offset:two.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)
|
||
|
self.assertEqual(range1, range2)
|
||
|
|
||
|
location3 = SourceLocation.from_position(tu, file, 1, 6)
|
||
|
range3 = SourceRange.from_locations(location1, location3)
|
||
|
self.assertNotEqual(range1, range3)
|