forked from VimPlug/jedi
Start actual testing of the new parser.
This commit is contained in:
@@ -126,6 +126,9 @@ class Node(Base):
|
|||||||
if sys.version_info > (3, 0):
|
if sys.version_info > (3, 0):
|
||||||
__str__ = __unicode__
|
__str__ = __unicode__
|
||||||
|
|
||||||
|
def get_code(self):
|
||||||
|
return str(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def prefix(self):
|
def prefix(self):
|
||||||
"""
|
"""
|
||||||
@@ -186,7 +189,7 @@ def convert(grammar, raw_node):
|
|||||||
if type == tokenize.NAME:
|
if type == tokenize.NAME:
|
||||||
return pr.Name(value, start_pos, prefix)
|
return pr.Name(value, start_pos, prefix)
|
||||||
elif type in (tokenize.STRING, tokenize.NUMBER):
|
elif type in (tokenize.STRING, tokenize.NUMBER):
|
||||||
return pr.Name(value, start_pos, prefix)
|
return pr.Literal(value, start_pos, prefix)
|
||||||
elif type in (tokenize.NEWLINE, tokenize.ENDMARKER):
|
elif type in (tokenize.NEWLINE, tokenize.ENDMARKER):
|
||||||
return pr.Whitespace(value, start_pos, prefix)
|
return pr.Whitespace(value, start_pos, prefix)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -219,11 +219,14 @@ class Literal(_Leaf):
|
|||||||
return literal_eval(self.value)
|
return literal_eval(self.value)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
# TODO remove?
|
||||||
|
"""
|
||||||
if is_py3:
|
if is_py3:
|
||||||
s = self.literal
|
s = self.literal
|
||||||
else:
|
else:
|
||||||
s = self.literal.encode('ascii', 'replace')
|
s = self.literal.encode('ascii', 'replace')
|
||||||
return "<%s: %s>" % (type(self).__name__, s)
|
"""
|
||||||
|
return "<%s: %s>" % (type(self).__name__, self.value)
|
||||||
|
|
||||||
|
|
||||||
class Operator(_Leaf):
|
class Operator(_Leaf):
|
||||||
@@ -278,7 +281,7 @@ class Simple(Base):
|
|||||||
return self.children[-1].end_pos
|
return self.children[-1].end_pos
|
||||||
|
|
||||||
def get_code(self):
|
def get_code(self):
|
||||||
return "".join(str(c) for c in self.children)
|
return "".join(c.get_code() for c in self.children)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
code = self.get_code().replace('\n', ' ')
|
code = self.get_code().replace('\n', ' ')
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from jedi.parser.pgen2 import Driver
|
|||||||
def test_basic():
|
def test_basic():
|
||||||
def compare(string):
|
def compare(string):
|
||||||
"""Generates the AST object and then regenerates the code."""
|
"""Generates the AST object and then regenerates the code."""
|
||||||
return d.parse_string(string).get_code() == string
|
assert d.parse_string(string).get_code() == string
|
||||||
|
|
||||||
#if self.options["print_function"]:
|
#if self.options["print_function"]:
|
||||||
# python_grammar = pygram.python_grammar_no_print_statement
|
# python_grammar = pygram.python_grammar_no_print_statement
|
||||||
@@ -18,6 +18,10 @@ def test_basic():
|
|||||||
logger = logging.getLogger("RefactoringTool")
|
logger = logging.getLogger("RefactoringTool")
|
||||||
d = Driver(pytree.python_grammar, convert=pytree.convert, logger=logger)
|
d = Driver(pytree.python_grammar, convert=pytree.convert, logger=logger)
|
||||||
|
|
||||||
|
compare('\na #pass\n')
|
||||||
|
compare('wblabla* 1\t\n')
|
||||||
|
compare('def x(a, b:3): pass\n')
|
||||||
|
|
||||||
print(d)
|
print(d)
|
||||||
tree = d.parse_string('wblabla* 1\t\n')
|
tree = d.parse_string('wblabla* 1\t\n')
|
||||||
print(repr(tree))
|
print(repr(tree))
|
||||||
|
|||||||
Reference in New Issue
Block a user