Skip to content

Commit

Permalink
Test output newlines when skipping first line
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
aaossa committed Oct 6, 2022
1 parent 7baf898 commit 02d1d17
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 02d1d17

Please sign in to comment.