# Path: pre_commit_hooks/mixed_line_ending.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument(
#         '-f', '--fix',
#         choices=('auto', 'no') + tuple(FIX_TO_LINE_ENDING),
#         default='auto',
#         help='Replace line ending with the specified. Default is "auto"',
#     )
#     parser.add_argument('filenames', nargs='*', help='Filenames to fix')
#     args = parser.parse_args(argv)
# 
#     retv = 0
#     for filename in args.filenames:
#         if fix_filename(filename, args.fix):
#             if args.fix == 'no':
#                 print(f'{filename}: mixed line endings')
#             else:
#                 print(f'{filename}: fixed mixed line endings')
#             retv = 1
#     return retv


import pytest
from pre_commit_hooks.mixed_line_ending import main
from __future__ import annotations




@pytest.mark.parametrize(
    ('input_s', 'output'),
    (
        # mixed with majority of 'LF'
        (b'foo\r\nbar\nbaz\n', b'foo\nbar\nbaz\n'),
        # mixed with majority of 'CRLF'
        (b'foo\r\nbar\nbaz\r\n', b'foo\r\nbar\r\nbaz\r\n'),
        # mixed with majority of 'CR'
        (b'foo\rbar\nbaz\r', b'foo\rbar\rbaz\r'),
        # mixed with as much 'LF' as 'CRLF'
        (b'foo\r\nbar\n', b'foo\nbar\n'),
        # mixed with as much 'LF' as 'CR'
        (b'foo\rbar\n', b'foo\nbar\n'),
        # mixed with as much 'CRLF' as 'CR'
        (b'foo\r\nbar\r', b'foo\r\nbar\r\n'),
        # mixed with as much 'CRLF' as 'LF' as 'CR'
        (b'foo\r\nbar\nbaz\r', b'foo\nbar\nbaz\n'),
    ),
)
def test_mixed_line_ending_fixes_auto(input_s, output, tmpdir):
    path = tmpdir.join('file.txt')
    path.write_binary(input_s)

# Path: pre_commit_hooks/mixed_line_ending.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument(
#         '-f', '--fix',
#         choices=('auto', 'no') + tuple(FIX_TO_LINE_ENDING),
#         default='auto',
#         help='Replace line ending with the specified. Default is "auto"',
#     )
#     parser.add_argument('filenames', nargs='*', help='Filenames to fix')
#     args = parser.parse_args(argv)
# 
#     retv = 0
#     for filename in args.filenames:
#         if fix_filename(filename, args.fix):
#             if args.fix == 'no':
#                 print(f'{filename}: mixed line endings')
#             else:
#                 print(f'{filename}: fixed mixed line endings')
#             retv = 1
#     return retv


# Path: tests/mixed_line_ending_test.py
import pytest
from pre_commit_hooks.mixed_line_ending import main

from __future__ import annotations




@pytest.mark.parametrize(
    ('input_s', 'output'),
    (
        # mixed with majority of 'LF'
        (b'foo\r\nbar\nbaz\n', b'foo\nbar\nbaz\n'),
        # mixed with majority of 'CRLF'
        (b'foo\r\nbar\nbaz\r\n', b'foo\r\nbar\r\nbaz\r\n'),
        # mixed with majority of 'CR'
        (b'foo\rbar\nbaz\r', b'foo\rbar\rbaz\r'),
        # mixed with as much 'LF' as 'CRLF'
        (b'foo\r\nbar\n', b'foo\nbar\n'),
        # mixed with as much 'LF' as 'CR'
        (b'foo\rbar\n', b'foo\nbar\n'),
        # mixed with as much 'CRLF' as 'CR'
        (b'foo\r\nbar\r', b'foo\r\nbar\r\n'),
        # mixed with as much 'CRLF' as 'LF' as 'CR'
        (b'foo\r\nbar\nbaz\r', b'foo\nbar\nbaz\n'),
    ),
)
def test_mixed_line_ending_fixes_auto(input_s, output, tmpdir):
    path = tmpdir.join('file.txt')
    path.write_binary(input_s)

    ret = main((str(path),))