mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Some simplifications for the parsers.
This commit is contained in:
@@ -26,7 +26,7 @@ def test_carriage_return_splitting():
|
|||||||
assert [n.value for lst in module.get_used_names().values() for n in lst] == ['Foo']
|
assert [n.value for lst in module.get_used_names().values() for n in lst] == ['Foo']
|
||||||
|
|
||||||
|
|
||||||
def check_p(src, number_parsers_used):
|
def check_p(src):
|
||||||
module_node = parse(src)
|
module_node = parse(src)
|
||||||
assert src == module_node.get_code()
|
assert src == module_node.get_code()
|
||||||
return module_node
|
return module_node
|
||||||
@@ -40,7 +40,7 @@ def test_for():
|
|||||||
for a1 in 1,"":
|
for a1 in 1,"":
|
||||||
a1
|
a1
|
||||||
""")
|
""")
|
||||||
check_p(src, 1)
|
check_p(src)
|
||||||
|
|
||||||
|
|
||||||
def test_class_with_class_var():
|
def test_class_with_class_var():
|
||||||
@@ -51,7 +51,7 @@ def test_class_with_class_var():
|
|||||||
self.foo = 4
|
self.foo = 4
|
||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
check_p(src, 3)
|
check_p(src)
|
||||||
|
|
||||||
|
|
||||||
def test_func_with_if():
|
def test_func_with_if():
|
||||||
@@ -65,7 +65,7 @@ def test_func_with_if():
|
|||||||
else:
|
else:
|
||||||
return a
|
return a
|
||||||
""")
|
""")
|
||||||
check_p(src, 1)
|
check_p(src)
|
||||||
|
|
||||||
|
|
||||||
def test_decorator():
|
def test_decorator():
|
||||||
@@ -75,7 +75,7 @@ def test_decorator():
|
|||||||
def dec(self, a):
|
def dec(self, a):
|
||||||
return a
|
return a
|
||||||
""")
|
""")
|
||||||
check_p(src, 2)
|
check_p(src)
|
||||||
|
|
||||||
|
|
||||||
def test_nested_funcs():
|
def test_nested_funcs():
|
||||||
@@ -85,7 +85,7 @@ def test_nested_funcs():
|
|||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
""")
|
""")
|
||||||
check_p(src, 3)
|
check_p(src)
|
||||||
|
|
||||||
|
|
||||||
def test_multi_line_params():
|
def test_multi_line_params():
|
||||||
@@ -96,7 +96,7 @@ def test_multi_line_params():
|
|||||||
|
|
||||||
foo = 1
|
foo = 1
|
||||||
""")
|
""")
|
||||||
check_p(src, 2)
|
check_p(src)
|
||||||
|
|
||||||
|
|
||||||
def test_class_func_if():
|
def test_class_func_if():
|
||||||
@@ -110,7 +110,7 @@ def test_class_func_if():
|
|||||||
|
|
||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
check_p(src, 3)
|
check_p(src)
|
||||||
|
|
||||||
|
|
||||||
def test_multi_line_for():
|
def test_multi_line_for():
|
||||||
@@ -121,7 +121,7 @@ def test_multi_line_for():
|
|||||||
|
|
||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
check_p(src, 1)
|
check_p(src)
|
||||||
|
|
||||||
|
|
||||||
def test_wrong_indentation():
|
def test_wrong_indentation():
|
||||||
@@ -131,7 +131,7 @@ def test_wrong_indentation():
|
|||||||
b
|
b
|
||||||
a
|
a
|
||||||
""")
|
""")
|
||||||
#check_p(src, 1)
|
check_p(src)
|
||||||
|
|
||||||
src = dedent("""\
|
src = dedent("""\
|
||||||
def complex():
|
def complex():
|
||||||
@@ -143,7 +143,7 @@ def test_wrong_indentation():
|
|||||||
def other():
|
def other():
|
||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
check_p(src, 3)
|
check_p(src)
|
||||||
|
|
||||||
|
|
||||||
def test_strange_parentheses():
|
def test_strange_parentheses():
|
||||||
@@ -154,7 +154,7 @@ def test_strange_parentheses():
|
|||||||
def x():
|
def x():
|
||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
check_p(src, 2)
|
check_p(src)
|
||||||
|
|
||||||
|
|
||||||
def test_fake_parentheses():
|
def test_fake_parentheses():
|
||||||
@@ -172,7 +172,7 @@ def test_fake_parentheses():
|
|||||||
def z():
|
def z():
|
||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
check_p(src, 3, 2, 1)
|
check_p(src)
|
||||||
|
|
||||||
|
|
||||||
def test_additional_indent():
|
def test_additional_indent():
|
||||||
@@ -182,7 +182,7 @@ def test_additional_indent():
|
|||||||
pass
|
pass
|
||||||
''')
|
''')
|
||||||
|
|
||||||
check_p(source, 2)
|
check_p(source)
|
||||||
|
|
||||||
|
|
||||||
def test_round_trip():
|
def test_round_trip():
|
||||||
@@ -202,4 +202,4 @@ def test_parentheses_in_string():
|
|||||||
import abc
|
import abc
|
||||||
|
|
||||||
abc.''')
|
abc.''')
|
||||||
check_p(code, 2, 1, 1)
|
check_p(code)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ def test_form_feed_characters():
|
|||||||
jedi.Script(s, line=2, column=18).call_signatures()
|
jedi.Script(s, line=2, column=18).call_signatures()
|
||||||
|
|
||||||
|
|
||||||
def check_p(src, number_parsers_used):
|
def check_p(src):
|
||||||
module_node = parse(src)
|
module_node = parse(src)
|
||||||
assert src == module_node.get_code()
|
assert src == module_node.get_code()
|
||||||
return module_node
|
return module_node
|
||||||
@@ -28,7 +28,7 @@ def test_if():
|
|||||||
''')
|
''')
|
||||||
|
|
||||||
# Two parsers needed, one for pass and one for the function.
|
# Two parsers needed, one for pass and one for the function.
|
||||||
check_p(src, 2)
|
check_p(src)
|
||||||
assert [d.name for d in jedi.Script(src, 8, 6).goto_definitions()] == ['int']
|
assert [d.name for d in jedi.Script(src, 8, 6).goto_definitions()] == ['int']
|
||||||
|
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ def test_class_and_if():
|
|||||||
|
|
||||||
# COMMENT
|
# COMMENT
|
||||||
a_func()""")
|
a_func()""")
|
||||||
check_p(src, 5, 5)
|
check_p(src)
|
||||||
assert [d.name for d in jedi.Script(src).goto_definitions()] == ['int']
|
assert [d.name for d in jedi.Script(src).goto_definitions()] == ['int']
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user