# Path: pre_commit_hooks/trailing_whitespace_fixer.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument(
#         '--no-markdown-linebreak-ext',
#         action='store_true',
#         help=argparse.SUPPRESS,
#     )
#     parser.add_argument(
#         '--markdown-linebreak-ext',
#         action='append',
#         default=[],
#         metavar='*|EXT[,EXT,...]',
#         help=(
#             'Markdown extensions (or *) to not strip linebreak spaces.  '
#             'default: %(default)s'
#         ),
#     )
#     parser.add_argument(
#         '--chars',
#         help=(
#             'The set of characters to strip from the end of lines.  '
#             'Defaults to all whitespace characters.'
#         ),
#     )
#     parser.add_argument('filenames', nargs='*', help='Filenames to fix')
#     args = parser.parse_args(argv)
# 
#     if args.no_markdown_linebreak_ext:
#         print('--no-markdown-linebreak-ext now does nothing!')
# 
#     md_args = args.markdown_linebreak_ext
#     if '' in md_args:
#         parser.error('--markdown-linebreak-ext requires a non-empty argument')
#     all_markdown = '*' in md_args
#     # normalize extensions; split at ',', lowercase, and force 1 leading '.'
#     md_exts = [
#         '.' + x.lower().lstrip('.') for x in ','.join(md_args).split(',')
#     ]
# 
#     # reject probable "eaten" filename as extension: skip leading '.' with [1:]
#     for ext in md_exts:
#         if any(c in ext[1:] for c in r'./\:'):
#             parser.error(
#                 f'bad --markdown-linebreak-ext extension '
#                 f'{ext!r} (has . / \\ :)\n'
#                 f"  (probably filename; use '--markdown-linebreak-ext=EXT')",
#             )
#     chars = None if args.chars is None else args.chars.encode()
#     return_code = 0
#     for filename in args.filenames:
#         _, extension = os.path.splitext(filename.lower())
#         md = all_markdown or extension in md_exts
#         if _fix_file(filename, md, chars):
#             print(f'Fixing {filename}')
#             return_code = 1
#     return return_code


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




@pytest.mark.parametrize(
    ('input_s', 'expected'),
    (
        ('foo \nbar \n', 'foo\nbar\n'),
        ('bar\t\nbaz\t\n', 'bar\nbaz\n'),
    ),
)
def test_fixes_trailing_whitespace(input_s, expected, tmpdir):
    path = tmpdir.join('file.md')
    path.write(input_s)

# Path: pre_commit_hooks/trailing_whitespace_fixer.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument(
#         '--no-markdown-linebreak-ext',
#         action='store_true',
#         help=argparse.SUPPRESS,
#     )
#     parser.add_argument(
#         '--markdown-linebreak-ext',
#         action='append',
#         default=[],
#         metavar='*|EXT[,EXT,...]',
#         help=(
#             'Markdown extensions (or *) to not strip linebreak spaces.  '
#             'default: %(default)s'
#         ),
#     )
#     parser.add_argument(
#         '--chars',
#         help=(
#             'The set of characters to strip from the end of lines.  '
#             'Defaults to all whitespace characters.'
#         ),
#     )
#     parser.add_argument('filenames', nargs='*', help='Filenames to fix')
#     args = parser.parse_args(argv)
# 
#     if args.no_markdown_linebreak_ext:
#         print('--no-markdown-linebreak-ext now does nothing!')
# 
#     md_args = args.markdown_linebreak_ext
#     if '' in md_args:
#         parser.error('--markdown-linebreak-ext requires a non-empty argument')
#     all_markdown = '*' in md_args
#     # normalize extensions; split at ',', lowercase, and force 1 leading '.'
#     md_exts = [
#         '.' + x.lower().lstrip('.') for x in ','.join(md_args).split(',')
#     ]
# 
#     # reject probable "eaten" filename as extension: skip leading '.' with [1:]
#     for ext in md_exts:
#         if any(c in ext[1:] for c in r'./\:'):
#             parser.error(
#                 f'bad --markdown-linebreak-ext extension '
#                 f'{ext!r} (has . / \\ :)\n'
#                 f"  (probably filename; use '--markdown-linebreak-ext=EXT')",
#             )
#     chars = None if args.chars is None else args.chars.encode()
#     return_code = 0
#     for filename in args.filenames:
#         _, extension = os.path.splitext(filename.lower())
#         md = all_markdown or extension in md_exts
#         if _fix_file(filename, md, chars):
#             print(f'Fixing {filename}')
#             return_code = 1
#     return return_code


# Path: tests/trailing_whitespace_fixer_test.py
import pytest
from pre_commit_hooks.trailing_whitespace_fixer import main

from __future__ import annotations




@pytest.mark.parametrize(
    ('input_s', 'expected'),
    (
        ('foo \nbar \n', 'foo\nbar\n'),
        ('bar\t\nbaz\t\n', 'bar\nbaz\n'),
    ),
)
def test_fixes_trailing_whitespace(input_s, expected, tmpdir):
    path = tmpdir.join('file.md')
    path.write(input_s)

    assert main((str(path),)) == 1