From 02d1d172ead122bf4e70ede6027d946a62d123a9 Mon Sep 17 00:00:00 2001 From: Antonio Ossa Guerra Date: Thu, 6 Oct 2022 16:32:18 -0300 Subject: [PATCH] Test output newlines when skipping first line When skipping the first line of source code, the reference newline must be taken from the second line of the file instead of the first one, in case that the file mixes more than one kind of newline character Signed-off-by: Antonio Ossa Guerra --- tests/test_black.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_black.py b/tests/test_black.py index e06f95cd62f..5d0175d9d66 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -355,6 +355,16 @@ def test_skip_source_first_line(self) -> None: actual = f.read() self.assertFormatEqual(source, actual) + def test_skip_source_first_line_when_mixing_newlines(self) -> None: + code_mixing_newlines = b"Header will be skipped\r\ni = [1,2,3]\nj = [1,2,3]\n" + expected = b"Header will be skipped\r\ni = [1, 2, 3]\nj = [1, 2, 3]\n" + with TemporaryDirectory() as workspace: + test_file = Path(workspace) / "skip_header.py" + test_file.write_bytes(code_mixing_newlines) + mode = replace(DEFAULT_MODE, skip_source_first_line=True) + ff(test_file, mode=mode, write_back=black.WriteBack.YES) + self.assertEqual(test_file.read_bytes(), expected) + def test_skip_magic_trailing_comma(self) -> None: source, _ = read_data("simple_cases", "expression") expected, _ = read_data(