diff --git a/test/test_parser/test_old_fast_parser.py b/test/test_parser/test_old_fast_parser.py index e8fc725d..796b947f 100644 --- a/test/test_parser/test_old_fast_parser.py +++ b/test/test_parser/test_old_fast_parser.py @@ -8,13 +8,11 @@ However the tests might still be relevant for the parser. from textwrap import dedent -import jedi -from jedi._compatibility import u from jedi.parser.python import parse def test_carriage_return_splitting(): - source = u(dedent(''' + source = dedent(''' @@ -22,39 +20,18 @@ def test_carriage_return_splitting(): class Foo(): pass - ''')) + ''') source = source.replace('\n', '\r\n') module = parse(source) assert [n.value for lst in module.get_used_names().values() for n in lst] == ['Foo'] -def check_p(src, number_parsers_used, number_of_splits=None, number_of_misses=0): - if number_of_splits is None: - number_of_splits = number_parsers_used - +def check_p(src, number_parsers_used): module_node = parse(src) - assert src == module_node.get_code() return module_node -def test_if(): - src = dedent('''\ - def func(): - x = 3 - if x: - def y(): - return x - return y() - - func() - ''') - - # Two parsers needed, one for pass and one for the function. - check_p(src, 2) - assert [d.name for d in jedi.Script(src, 8, 6).goto_definitions()] == ['int'] - - def test_for(): src = dedent("""\ for a in [1,2]: @@ -111,24 +88,6 @@ def test_nested_funcs(): check_p(src, 3) -def test_class_and_if(): - src = dedent("""\ - class V: - def __init__(self): - pass - - if 1: - c = 3 - - def a_func(): - return 1 - - # COMMENT - a_func()""") - check_p(src, 5, 5) - assert [d.name for d in jedi.Script(src).goto_definitions()] == ['int'] - - def test_multi_line_params(): src = dedent("""\ def x(a, @@ -226,44 +185,6 @@ def test_additional_indent(): check_p(source, 2) -def test_incomplete_function(): - source = '''return ImportErr''' - - script = jedi.Script(dedent(source), 1, 3) - assert script.completions() - - -def test_string_literals(): - """Simplified case of jedi-vim#377.""" - source = dedent(""" - x = ur''' - - def foo(): - pass - """) - - script = jedi.Script(dedent(source)) - assert script._get_module().tree_node.end_pos == (6, 0) - assert script.completions() - - -def test_decorator_string_issue(): - """ - Test case from #589 - """ - source = dedent('''\ - """ - @""" - def bla(): - pass - - bla.''') - - s = jedi.Script(source) - assert s.completions() - assert s._get_module().tree_node.get_code() == source - - def test_round_trip(): code = dedent(''' def x(): diff --git a/test/test_parso_integration/test_basic.py b/test/test_parso_integration/test_basic.py index 01aff796..a9ec14e6 100644 --- a/test/test_parso_integration/test_basic.py +++ b/test/test_parso_integration/test_basic.py @@ -1,6 +1,52 @@ +from textwrap import dedent + +from jedi.parser.python import parse import jedi def test_form_feed_characters(): s = "\f\nclass Test(object):\n pass" jedi.Script(s, line=2, column=18).call_signatures() + + +def check_p(src, number_parsers_used): + module_node = parse(src) + assert src == module_node.get_code() + return module_node + + +def test_if(): + src = dedent('''\ + def func(): + x = 3 + if x: + def y(): + return x + return y() + + func() + ''') + + # Two parsers needed, one for pass and one for the function. + check_p(src, 2) + assert [d.name for d in jedi.Script(src, 8, 6).goto_definitions()] == ['int'] + + +def test_class_and_if(): + src = dedent("""\ + class V: + def __init__(self): + pass + + if 1: + c = 3 + + def a_func(): + return 1 + + # COMMENT + a_func()""") + check_p(src, 5, 5) + assert [d.name for d in jedi.Script(src).goto_definitions()] == ['int'] + + diff --git a/test/test_parso_integration/test_error_correction.py b/test/test_parso_integration/test_error_correction.py index 153c34d9..49814733 100644 --- a/test/test_parso_integration/test_error_correction.py +++ b/test/test_parso_integration/test_error_correction.py @@ -1,3 +1,5 @@ +from textwrap import dedent + import jedi @@ -10,3 +12,41 @@ def test_error_correction_with(): assert len(comps) > 30 # `open` completions have a closed attribute. assert [1 for c in comps if c.name == 'closed'] + + +def test_string_literals(): + """Simplified case of jedi-vim#377.""" + source = dedent(""" + x = ur''' + + def foo(): + pass + """) + + script = jedi.Script(dedent(source)) + assert script._get_module().tree_node.end_pos == (6, 0) + assert script.completions() + + +def test_incomplete_function(): + source = '''return ImportErr''' + + script = jedi.Script(dedent(source), 1, 3) + assert script.completions() + + +def test_decorator_string_issue(): + """ + Test case from #589 + """ + source = dedent('''\ + """ + @""" + def bla(): + pass + + bla.''') + + s = jedi.Script(source) + assert s.completions() + assert s._get_module().tree_node.get_code() == source