mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +00:00
Add unit test for mixed_line_ending --fix={cr,crlf}
This commit is contained in:
parent
609d01178c
commit
63bb1fd1f5
1 changed files with 50 additions and 0 deletions
|
|
@ -48,3 +48,53 @@ def test_detect_mixed_line_ending(input_s, expected_retval, output, tmpdir):
|
||||||
|
|
||||||
assert ret == expected_retval
|
assert ret == expected_retval
|
||||||
assert path.read() == output
|
assert path.read() == output
|
||||||
|
|
||||||
|
|
||||||
|
# Input, expected return value, expected output
|
||||||
|
TESTS_FIX_FORCE_LF = (
|
||||||
|
# only 'LF'
|
||||||
|
(b'foo\nbar\nbaz\n', 1, b'foo\nbar\nbaz\n'),
|
||||||
|
# only 'CRLF'
|
||||||
|
(b'foo\r\nbar\r\nbaz\r\n', 1, b'foo\nbar\nbaz\n'),
|
||||||
|
# mixed with majority of 'LF'
|
||||||
|
(b'foo\r\nbar\nbaz\n', 1, b'foo\nbar\nbaz\n'),
|
||||||
|
# mixed with majority of 'CRLF'
|
||||||
|
(b'foo\r\nbar\nbaz\r\n', 1, b'foo\nbar\nbaz\n'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(('input_s', 'expected_retval', 'output'),
|
||||||
|
TESTS_FIX_FORCE_LF)
|
||||||
|
def test_mixed_line_ending_fix_force_lf(input_s, expected_retval, output,
|
||||||
|
tmpdir):
|
||||||
|
path = tmpdir.join('file.txt')
|
||||||
|
path.write(input_s)
|
||||||
|
ret = mixed_line_ending(('--fix=lf', '-vv', path.strpath))
|
||||||
|
|
||||||
|
assert ret == expected_retval
|
||||||
|
assert path.read() == output
|
||||||
|
|
||||||
|
|
||||||
|
# Input, expected return value, expected output
|
||||||
|
TESTS_FIX_FORCE_CRLF = (
|
||||||
|
# only 'LF'
|
||||||
|
(b'foo\nbar\nbaz\n', 1, b'foo\r\nbar\r\nbaz\r\n'),
|
||||||
|
# only 'CRLF'
|
||||||
|
(b'foo\r\nbar\r\nbaz\r\n', 1, b'foo\r\nbar\r\nbaz\r\n'),
|
||||||
|
# mixed with majority of 'LF'
|
||||||
|
(b'foo\r\nbar\nbaz\n', 1, b'foo\r\nbar\r\nbaz\r\n'),
|
||||||
|
# mixed with majority of 'CRLF'
|
||||||
|
(b'foo\r\nbar\nbaz\r\n', 1, b'foo\r\nbar\r\nbaz\r\n'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(('input_s', 'expected_retval', 'output'),
|
||||||
|
TESTS_FIX_FORCE_CRLF)
|
||||||
|
def test_mixed_line_ending_fix_force_crlf(input_s, expected_retval, output,
|
||||||
|
tmpdir):
|
||||||
|
path = tmpdir.join('file.txt')
|
||||||
|
path.write(input_s)
|
||||||
|
ret = mixed_line_ending(('--fix=crlf', '-vv', path.strpath))
|
||||||
|
|
||||||
|
assert ret == expected_retval
|
||||||
|
assert path.read() == output
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue