From aabf31f8bd1ff52b260aa2b117c82e6f8d216f84 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Thu, 22 Aug 2019 12:00:00 +0200 Subject: [PATCH] Demonstrate a parsing error w/ EOL w/ empty line Ref: https://github.com/PyCQA/redbaron/issues/186 --- tests/test_regression.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/test_regression.py b/tests/test_regression.py index 1ec6bd04..b57f6ed9 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -1,4 +1,6 @@ -from baron import parse, dumps +import pytest + +from baron import parse, parser, dumps def test_regression_trailing_comment_after_colon(): @@ -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)