end_of_file_fixer: write platform native line endings

The most common setup for git is to use platform-native line endings in checkout
(`core.autocrlf` set to `true`). So the eol file fixer should write native
line endings.
This commit is contained in:
Bernhard Walle 2023-04-19 11:29:31 +02:00
parent b0f11fe246
commit cbd515b47c
2 changed files with 6 additions and 3 deletions

View file

@ -1,6 +1,7 @@
from __future__ import annotations
import io
import os
import pytest
@ -9,14 +10,15 @@ from pre_commit_hooks.end_of_file_fixer import main
# Input, expected return value, expected output
platform_eol = os.linesep.encode('ascii')
TESTS = (
(b'foo\n', 0, b'foo\n'),
(b'', 0, b''),
(b'\n\n', 1, b''),
(b'\n\n\n\n', 1, b''),
(b'foo', 1, b'foo\n'),
(b'foo', 1, b'foo' + platform_eol),
(b'foo\n\n\n', 1, b'foo\n'),
(b'\xe2\x98\x83', 1, b'\xe2\x98\x83\n'),
(b'\xe2\x98\x83', 1, b'\xe2\x98\x83' + platform_eol),
(b'foo\r\n', 0, b'foo\r\n'),
(b'foo\r\n\r\n\r\n', 1, b'foo\r\n'),
(b'foo\r', 0, b'foo\r'),