Skip to content

Commit 5427ca4

Browse files
committed
Demonstrate a parsing error w/ EOL w/ empty line
Ref: PyCQA/redbaron#186
1 parent 15b6e6b commit 5427ca4

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

tests/test_regression.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from baron import parse, dumps
1+
import pytest
2+
3+
from baron import parse, parser, dumps
24

35

46
def test_regression_trailing_comment_after_colon():
@@ -22,3 +24,25 @@ def test_regression_trailing_comment_after_colon_no_space_dump():
2224
def test_comment_in_middle_of_ifelseblock():
2325
code = 'if a:\n pass\n# comment\nelse:\n pass\n'
2426
assert dumps(parse(code)) == code
27+
28+
29+
@pytest.mark.parametrize(
30+
'code',
31+
(
32+
'sss = "some str"\\\n# some comment\nprint(sss)',
33+
'sss = "some str"\\\n\nprint(sss)',
34+
),
35+
)
36+
def test_eol_esc_no_continuation(code):
37+
"""Test that parser reads escaped EOL continuation w/ empty line."""
38+
assert dumps(parse(code)) == code
39+
40+
41+
def test_eol_esc_invalid_continuation():
42+
"""Test that illegal escaped EOL continuation raises an error."""
43+
code = 'sss = "some str"\\\nprint(sss)'
44+
with pytest.raises(
45+
parser.ParsingError,
46+
match='Error, got an unexpected token SPACE here:',
47+
):
48+
parse(code)

0 commit comments

Comments
 (0)