aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/parso/py3/tests/test_prefix.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/python/parso/py3/tests/test_prefix.py
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/parso/py3/tests/test_prefix.py')
-rw-r--r--contrib/python/parso/py3/tests/test_prefix.py150
1 files changed, 75 insertions, 75 deletions
diff --git a/contrib/python/parso/py3/tests/test_prefix.py b/contrib/python/parso/py3/tests/test_prefix.py
index e2b9b511bc..58c1dcf98f 100644
--- a/contrib/python/parso/py3/tests/test_prefix.py
+++ b/contrib/python/parso/py3/tests/test_prefix.py
@@ -1,75 +1,75 @@
-from itertools import zip_longest
-from codecs import BOM_UTF8
-
-import pytest
-
-import parso
-
-unicode_bom = BOM_UTF8.decode('utf-8')
-
-
-@pytest.mark.parametrize(('string', 'tokens'), [
- ('', ['']),
- ('#', ['#', '']),
- (' # ', ['# ', '']),
- (' # \n', ['# ', '\n', '']),
- (' # \f\n', ['# ', '\f', '\n', '']),
- (' \n', ['\n', '']),
- (' \n ', ['\n', ' ']),
- (' \f ', ['\f', ' ']),
- (' \f ', ['\f', ' ']),
- (' \r\n', ['\r\n', '']),
- (' \r', ['\r', '']),
- ('\\\n', ['\\\n', '']),
- ('\\\r\n', ['\\\r\n', '']),
- ('\t\t\n\t', ['\n', '\t']),
-])
-def test_simple_prefix_splitting(string, tokens):
- tree = parso.parse(string)
- leaf = tree.children[0]
- assert leaf.type == 'endmarker'
-
- parsed_tokens = list(leaf._split_prefix())
- start_pos = (1, 0)
- for pt, expected in zip_longest(parsed_tokens, tokens):
- assert pt.value == expected
-
- # Calculate the estimated end_pos
- if expected.endswith('\n') or expected.endswith('\r'):
- end_pos = start_pos[0] + 1, 0
- else:
- 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
- start_pos = end_pos
-
-
-@pytest.mark.parametrize(('string', 'types'), [
- ('# ', ['comment', 'spacing']),
- ('\r\n', ['newline', 'spacing']),
- ('\f', ['formfeed', 'spacing']),
- ('\\\n', ['backslash', 'spacing']),
- (' \t', ['spacing']),
- (' \t ', ['spacing']),
- (unicode_bom + ' # ', ['bom', 'comment', 'spacing']),
-])
-def test_prefix_splitting_types(string, types):
- tree = parso.parse(string)
- leaf = tree.children[0]
- assert leaf.type == 'endmarker'
- parsed_tokens = list(leaf._split_prefix())
- assert [t.type for t in parsed_tokens] == types
-
-
-def test_utf8_bom():
- tree = parso.parse(unicode_bom + 'a = 1')
- expr_stmt = tree.children[0]
- assert expr_stmt.start_pos == (1, 0)
-
- tree = parso.parse(unicode_bom + '\n')
- endmarker = tree.children[0]
- parts = list(endmarker._split_prefix())
- assert [p.type for p in parts] == ['bom', 'newline', 'spacing']
- assert [p.start_pos for p in parts] == [(1, 0), (1, 0), (2, 0)]
- assert [p.end_pos for p in parts] == [(1, 0), (2, 0), (2, 0)]
+from itertools import zip_longest
+from codecs import BOM_UTF8
+
+import pytest
+
+import parso
+
+unicode_bom = BOM_UTF8.decode('utf-8')
+
+
+@pytest.mark.parametrize(('string', 'tokens'), [
+ ('', ['']),
+ ('#', ['#', '']),
+ (' # ', ['# ', '']),
+ (' # \n', ['# ', '\n', '']),
+ (' # \f\n', ['# ', '\f', '\n', '']),
+ (' \n', ['\n', '']),
+ (' \n ', ['\n', ' ']),
+ (' \f ', ['\f', ' ']),
+ (' \f ', ['\f', ' ']),
+ (' \r\n', ['\r\n', '']),
+ (' \r', ['\r', '']),
+ ('\\\n', ['\\\n', '']),
+ ('\\\r\n', ['\\\r\n', '']),
+ ('\t\t\n\t', ['\n', '\t']),
+])
+def test_simple_prefix_splitting(string, tokens):
+ tree = parso.parse(string)
+ leaf = tree.children[0]
+ assert leaf.type == 'endmarker'
+
+ parsed_tokens = list(leaf._split_prefix())
+ start_pos = (1, 0)
+ for pt, expected in zip_longest(parsed_tokens, tokens):
+ assert pt.value == expected
+
+ # Calculate the estimated end_pos
+ if expected.endswith('\n') or expected.endswith('\r'):
+ end_pos = start_pos[0] + 1, 0
+ else:
+ 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
+ start_pos = end_pos
+
+
+@pytest.mark.parametrize(('string', 'types'), [
+ ('# ', ['comment', 'spacing']),
+ ('\r\n', ['newline', 'spacing']),
+ ('\f', ['formfeed', 'spacing']),
+ ('\\\n', ['backslash', 'spacing']),
+ (' \t', ['spacing']),
+ (' \t ', ['spacing']),
+ (unicode_bom + ' # ', ['bom', 'comment', 'spacing']),
+])
+def test_prefix_splitting_types(string, types):
+ tree = parso.parse(string)
+ leaf = tree.children[0]
+ assert leaf.type == 'endmarker'
+ parsed_tokens = list(leaf._split_prefix())
+ assert [t.type for t in parsed_tokens] == types
+
+
+def test_utf8_bom():
+ tree = parso.parse(unicode_bom + 'a = 1')
+ expr_stmt = tree.children[0]
+ assert expr_stmt.start_pos == (1, 0)
+
+ tree = parso.parse(unicode_bom + '\n')
+ endmarker = tree.children[0]
+ parts = list(endmarker._split_prefix())
+ assert [p.type for p in parts] == ['bom', 'newline', 'spacing']
+ assert [p.start_pos for p in parts] == [(1, 0), (1, 0), (2, 0)]
+ assert [p.end_pos for p in parts] == [(1, 0), (2, 0), (2, 0)]