mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
further regression tests
This commit is contained in:
@@ -62,6 +62,9 @@ class Completion(object):
|
|||||||
def get_type(self):
|
def get_type(self):
|
||||||
return type(self.name.parent())
|
return type(self.name.parent())
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<%s: %s>' % (self.__class__.__name__, self.name)
|
||||||
|
|
||||||
|
|
||||||
class Definition(object):
|
class Definition(object):
|
||||||
def __init__(self, definition):
|
def __init__(self, definition):
|
||||||
@@ -249,14 +252,13 @@ def get_definition(source, line, column, source_path):
|
|||||||
scopes = set([f.parser.user_scope])
|
scopes = set([f.parser.user_scope])
|
||||||
elif not goto_path:
|
elif not goto_path:
|
||||||
op = f.get_operator_under_cursor()
|
op = f.get_operator_under_cursor()
|
||||||
scopes = set([keywords.get_operator(op)])
|
scopes = set([keywords.get_operator(op)] if op else [])
|
||||||
else:
|
else:
|
||||||
scopes = _prepare_goto(source, pos, source_path, f, goto_path)
|
scopes = _prepare_goto(source, pos, source_path, f, goto_path)
|
||||||
|
|
||||||
# add keywords
|
# add keywords
|
||||||
scopes |= keywords.get_keywords(string=goto_path)
|
scopes |= keywords.get_keywords(string=goto_path)
|
||||||
|
|
||||||
|
|
||||||
d = set([Definition(s) for s in scopes])
|
d = set([Definition(s) for s in scopes])
|
||||||
_clear_caches()
|
_clear_caches()
|
||||||
return d
|
return d
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ class TestRegression(unittest.TestCase):
|
|||||||
def get_def(self, src, pos):
|
def get_def(self, src, pos):
|
||||||
return functions.get_definition(src, pos[0], pos[1], '')
|
return functions.get_definition(src, pos[0], pos[1], '')
|
||||||
|
|
||||||
|
def complete(self, src, pos):
|
||||||
|
return functions.complete(src, pos[0], pos[1], '')
|
||||||
|
|
||||||
def test_get_definition_cursor(self):
|
def test_get_definition_cursor(self):
|
||||||
|
|
||||||
s = ("class A():\n"
|
s = ("class A():\n"
|
||||||
@@ -65,8 +68,18 @@ class TestRegression(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_definition_at_zero(self):
|
def test_get_definition_at_zero(self):
|
||||||
assert self.get_def("a", (1,1)) == set()
|
assert self.get_def("a", (1,1)) == set()
|
||||||
##assert self.get_def("", (1,0)) == set()
|
s = self.get_def("str", (1,1))
|
||||||
|
assert len(s) == 1
|
||||||
|
assert list(s)[0].description == 'class str'
|
||||||
|
assert self.get_def("", (1,0)) == set()
|
||||||
|
|
||||||
|
def test_complete_at_zero(self):
|
||||||
|
s = self.complete("str", (1,3))
|
||||||
|
assert len(s) == 1
|
||||||
|
assert list(s)[0].word == 'str'
|
||||||
|
|
||||||
|
s = self.complete("", (1,0))
|
||||||
|
assert len(s) > 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user