Skip to content

Commit

Permalink
Demonstrate a parsing error w/ EOL w/ empty line
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Aug 22, 2019
1 parent 15b6e6b commit aabf31f
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/test_regression.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from baron import parse, dumps
import pytest

from baron import parse, parser, dumps


def test_regression_trailing_comment_after_colon():
Expand All @@ -22,3 +24,25 @@ def test_regression_trailing_comment_after_colon_no_space_dump():
def test_comment_in_middle_of_ifelseblock():
code = 'if a:\n pass\n# comment\nelse:\n pass\n'
assert dumps(parse(code)) == code


@pytest.mark.parametrize(
'code',
(
'sss = "some str"\\\n# some comment\nprint(sss)',
'sss = "some str"\\\n\nprint(sss)',
),
)
def test_eol_esc_no_continuation(code):
"""Test that parser reads escaped EOL continuation w/ empty line."""
assert dumps(parse(code)) == code


def test_eol_esc_invalid_continuation():
"""Test that illegal escaped EOL continuation raises an error."""
code = 'sss = "some str"\\\nprint(sss)'
with pytest.raises(
parser.ParsingError,
match='^Error, got an unexpected token NAME here:',
):
parse(code)

0 comments on commit aabf31f

Please sign in to comment.