Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate a parsing error w/ EOL w/ empty line #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Psycojoker would this be mergeable if I mark it as xfail?

"""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)