mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-04 19:26:52 +00:00
Add a way to do case-insensitive sorting via file-contents-sorter.
This commit is contained in:
parent
e1668fe86a
commit
0c760253f3
2 changed files with 58 additions and 19 deletions
|
|
@ -6,28 +6,52 @@ from pre_commit_hooks.file_contents_sorter import PASS
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('input_s', 'expected_retval', 'output'),
|
||||
('input_s', 'argv', 'expected_retval', 'output'),
|
||||
(
|
||||
(b'', FAIL, b'\n'),
|
||||
(b'lonesome\n', PASS, b'lonesome\n'),
|
||||
(b'missing_newline', FAIL, b'missing_newline\n'),
|
||||
(b'newline\nmissing', FAIL, b'missing\nnewline\n'),
|
||||
(b'missing\nnewline', FAIL, b'missing\nnewline\n'),
|
||||
(b'alpha\nbeta\n', PASS, b'alpha\nbeta\n'),
|
||||
(b'beta\nalpha\n', FAIL, b'alpha\nbeta\n'),
|
||||
(b'C\nc\n', PASS, b'C\nc\n'),
|
||||
(b'c\nC\n', FAIL, b'C\nc\n'),
|
||||
(b'mag ical \n tre vor\n', FAIL, b' tre vor\nmag ical \n'),
|
||||
(b'@\n-\n_\n#\n', FAIL, b'#\n-\n@\n_\n'),
|
||||
(b'extra\n\n\nwhitespace\n', FAIL, b'extra\nwhitespace\n'),
|
||||
(b'whitespace\n\n\nextra\n', FAIL, b'extra\nwhitespace\n'),
|
||||
(b'', [], FAIL, b'\n'),
|
||||
(b'lonesome\n', [], PASS, b'lonesome\n'),
|
||||
(b'missing_newline', [], FAIL, b'missing_newline\n'),
|
||||
(b'newline\nmissing', [], FAIL, b'missing\nnewline\n'),
|
||||
(b'missing\nnewline', [], FAIL, b'missing\nnewline\n'),
|
||||
(b'alpha\nbeta\n', [], PASS, b'alpha\nbeta\n'),
|
||||
(b'beta\nalpha\n', [], FAIL, b'alpha\nbeta\n'),
|
||||
(b'C\nc\n', [], PASS, b'C\nc\n'),
|
||||
(b'c\nC\n', [], FAIL, b'C\nc\n'),
|
||||
(b'mag ical \n tre vor\n', [], FAIL, b' tre vor\nmag ical \n'),
|
||||
(b'@\n-\n_\n#\n', [], FAIL, b'#\n-\n@\n_\n'),
|
||||
(b'extra\n\n\nwhitespace\n', [], FAIL, b'extra\nwhitespace\n'),
|
||||
(b'whitespace\n\n\nextra\n', [], FAIL, b'extra\nwhitespace\n'),
|
||||
(
|
||||
b'fee\nFie\nFoe\nfum\n',
|
||||
[],
|
||||
FAIL,
|
||||
b'Fie\nFoe\nfee\nfum\n',
|
||||
),
|
||||
(
|
||||
b'Fie\nFoe\nfee\nfum\n',
|
||||
[],
|
||||
PASS,
|
||||
b'Fie\nFoe\nfee\nfum\n',
|
||||
),
|
||||
(
|
||||
b'fee\nFie\nFoe\nfum\n',
|
||||
['--ignore-case'],
|
||||
PASS,
|
||||
b'fee\nFie\nFoe\nfum\n',
|
||||
),
|
||||
(
|
||||
b'Fie\nFoe\nfee\nfum\n',
|
||||
['--ignore-case'],
|
||||
FAIL,
|
||||
b'fee\nFie\nFoe\nfum\n',
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_integration(input_s, expected_retval, output, tmpdir):
|
||||
def test_integration(input_s, argv, expected_retval, output, tmpdir):
|
||||
path = tmpdir.join('file.txt')
|
||||
path.write_binary(input_s)
|
||||
|
||||
output_retval = main([str(path)])
|
||||
output_retval = main([str(path)] + argv)
|
||||
|
||||
assert path.read_binary() == output
|
||||
assert output_retval == expected_retval
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue