mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 12:54:29 +08:00
Trying to change the prefix parsing a bit.
This commit is contained in:
@@ -1,20 +1,24 @@
|
||||
from itertools import zip_longest
|
||||
|
||||
import pytest
|
||||
|
||||
import parso
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('string', 'tokens'), [
|
||||
('#', ['#']),
|
||||
(' # ', [' ', '# ']),
|
||||
(' # \n', [' ', '# ', '\n']),
|
||||
(' # \f\n', [' ', '# ', '\f', '\n']),
|
||||
(' \n', [' ', '\n']),
|
||||
(' \n ', [' ', '\n', ' ']),
|
||||
(' \f ', [' ', '\f', ' ']),
|
||||
(' \f ', [' ', '\f', ' ']),
|
||||
(' \r\n', [' ', '\r\n']),
|
||||
('\\\n', ['\\\n']),
|
||||
('\\\r\n', ['\\\r\n']),
|
||||
('\t\t\n\t', ['\t\t', '\n', '\t']),
|
||||
('', ['']),
|
||||
('#', ['#', '']),
|
||||
(' # ', ['# ', '']),
|
||||
(' # \n', ['# ', '\n', '']),
|
||||
(' # \f\n', ['# ', '\f', '\n', '']),
|
||||
(' \n', ['\n', '']),
|
||||
(' \n ', ['\n', ' ']),
|
||||
(' \f ', ['\f', ' ']),
|
||||
(' \f ', ['\f', ' ']),
|
||||
(' \r\n', ['\r\n', '']),
|
||||
('\\\n', ['\\\n', '']),
|
||||
('\\\r\n', ['\\\r\n', '']),
|
||||
('\t\t\n\t', ['\n', '\t']),
|
||||
])
|
||||
def test_simple_prefix_splitting(string, tokens):
|
||||
tree = parso.parse(string)
|
||||
@@ -23,14 +27,14 @@ def test_simple_prefix_splitting(string, tokens):
|
||||
|
||||
parsed_tokens = list(leaf._split_prefix())
|
||||
start_pos = (1, 0)
|
||||
for pt, expected in zip(parsed_tokens, tokens):
|
||||
for pt, expected in zip_longest(parsed_tokens, tokens):
|
||||
assert pt.value == expected
|
||||
|
||||
# Calculate the estimated end_pos
|
||||
if expected.endswith('\n'):
|
||||
end_pos = start_pos[0] + 1, 0
|
||||
else:
|
||||
end_pos = start_pos[0], start_pos[1] + len(expected)
|
||||
end_pos = start_pos[0], start_pos[1] + len(expected) + len(pt.spacing)
|
||||
|
||||
#assert start_pos == pt.start_pos
|
||||
assert end_pos == pt.end_pos
|
||||
@@ -38,12 +42,12 @@ def test_simple_prefix_splitting(string, tokens):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('string', 'types'), [
|
||||
('# ', ['comment']),
|
||||
('\r\n', ['newline']),
|
||||
('\f', ['formfeed']),
|
||||
('\\\n', ['backslash']),
|
||||
(' \t', ['indentation']),
|
||||
(' \t ', ['indentation']),
|
||||
('# ', ['comment', 'spacing']),
|
||||
('\r\n', ['newline', 'spacing']),
|
||||
('\f', ['formfeed', 'spacing']),
|
||||
('\\\n', ['backslash', 'spacing']),
|
||||
(' \t', ['spacing']),
|
||||
(' \t ', ['spacing']),
|
||||
])
|
||||
def test_prefix_splitting_types(string, types):
|
||||
tree = parso.parse(string)
|
||||
|
||||
Reference in New Issue
Block a user