mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-29 16:36:52 +08:00
Merge branch 'feature_827_fuzzy_search' of https://github.com/jmfrank63/jedi
This commit is contained in:
@@ -317,3 +317,51 @@ def test_goto_follow_builtin_imports(Script):
|
||||
def test_docstrings_for_completions(Script):
|
||||
for c in Script('').completions():
|
||||
assert isinstance(c.docstring(), (str, unicode))
|
||||
|
||||
|
||||
def test_fuzzy_completion(Script):
|
||||
script = Script('string = "hello"\nstring.upper')
|
||||
assert ['isupper',
|
||||
'upper'] == [comp.name for comp in script.completions(fuzzy=True)]
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info < (3, 3),
|
||||
reason="requires python3.3 or higher")
|
||||
def test_math_fuzzy_completion(Script):
|
||||
script = Script('import math\nmath.og')
|
||||
assert ['copysign', 'log', 'log10', 'log1p',
|
||||
'log2'] == [comp.name for comp in script.completions(fuzzy=True)]
|
||||
|
||||
@pytest.mark.skipif(sys.version_info < (3, 3),
|
||||
reason="requires python3.3 or higher")
|
||||
def test_file_fuzzy_completion(Script, tmp_path):
|
||||
folder0 = tmp_path / "inference"
|
||||
folder0.mkdir()
|
||||
file0_path0 = folder0 / "sys_path.py"
|
||||
file0_path0.write_text('\n')
|
||||
file0_path1 = folder0 / "syntax_tree.py"
|
||||
file0_path1.write_text('\n')
|
||||
script = Script('"{}/yt'.format(folder0))
|
||||
assert ['syntax_tree.py"', 'sys_path.py"'] \
|
||||
== [comp.name for comp in script.completions(fuzzy=True)]
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info > (2, 7),
|
||||
reason="requires python3.3 or higher")
|
||||
def test_math_fuzzy_completion(Script):
|
||||
script = Script('import math\nmath.og')
|
||||
assert ['copysign', 'log', 'log10',
|
||||
'log1p'] == [comp.name for comp in script.completions(fuzzy=True)]
|
||||
|
||||
@pytest.mark.skipif(sys.version_info > (2, 7),
|
||||
reason="requires python3.3 or higher")
|
||||
def test_file_fuzzy_completion(Script, tmp_path):
|
||||
folder0 = tmp_path / u"inference"
|
||||
folder0.mkdir()
|
||||
file0_path0 = folder0 / u"sys_path.py"
|
||||
file0_path0.write_text('\n')
|
||||
file0_path1 = folder0 / u"syntax_tree.py"
|
||||
file0_path1.write_text('\n')
|
||||
script = Script('"{}/yt'.format(folder0))
|
||||
assert ['syntax_tree.py"', 'sys_path.py"'] \
|
||||
== [comp.name for comp in script.completions(fuzzy=True)]
|
||||
|
||||
@@ -271,3 +271,15 @@ def test_file_path_completions(Script, file, code, column, expected):
|
||||
assert len(comps) > 100 # This is basically global completions.
|
||||
else:
|
||||
assert [c.complete for c in comps] == expected
|
||||
|
||||
from jedi.api.helpers import start_match, fuzzy_match
|
||||
|
||||
def test_start_match():
|
||||
assert start_match('Condition', 'C')
|
||||
|
||||
def test_fuzzy_match():
|
||||
assert fuzzy_match('Condition', 'i')
|
||||
assert not fuzzy_match('Condition', 'p')
|
||||
assert fuzzy_match('Condition', 'ii')
|
||||
assert not fuzzy_match('Condition', 'Ciito')
|
||||
assert fuzzy_match('Condition', 'Cdiio')
|
||||
|
||||
Reference in New Issue
Block a user