# Path: coaster/logger.py
# class RepeatValueIndicator:
#     """Represent a repeating value."""
# 
#     def __init__(self, key):
#         """Init with key."""
#         self.key = key
# 
#     def __repr__(self):
#         """Return representation."""
#         return f'<same as prior {self.key!r}>'
# 
#     __str__ = __repr__
# 
# def filtered_value(key, value):
#     """Find and mask sensitive values based on key names."""
#     if isinstance(key, str) and _filter_re.search(key):
#         return filtered_value_indicator
#     if isinstance(value, str):
#         return _card_re.sub('[Filtered]', value)
#     return value
# 
# def pprint_with_indent(dictlike, outfile, indent=4):
#     """Filter values and pprint with indent to create a Markdown code block."""
#     out = StringIO()
#     pprint(  # noqa: T003
#         {key: filtered_value(key, value) for key, value in dictlike.items()}, out
#     )
#     outfile.write(textwrap.indent(out.getvalue(), ' ' * indent))
#     out.close()


from io import StringIO
from coaster.logger import RepeatValueIndicator, filtered_value, pprint_with_indent
    # The filter uses a verbose regex. Words in the middle of the regex also work
    assert repr(filtered_value('access_token', 'secret-here')) == '[Filtered]'
    # Filters are case insensitive
    assert repr(filtered_value('TELEGRAM_ERROR_APIKEY', 'api:key')) == '[Filtered]'
    # Keys with 'token' as a word are also filtered
    assert repr(filtered_value('SMS_TWILIO_TOKEN', 'api:key')) == '[Filtered]'

    # Numbers that look like card numbers are filtered
    assert (
        filtered_value('anything', 'My number is 1234 5678 9012 3456')
        == 'My number is [Filtered]'
    )
    # This works with any combination of spaces and dashes within the number
    assert (
        filtered_value('anything', 'My number is 1234  5678-90123456')
        == 'My number is [Filtered]'
    )


def test_pprint_with_indent():
    """Test pprint_with_indent does indentation."""
    out = StringIO()
    data = {
        12: 34,
        'confirm_password': '12345qwerty',
        'credentials': ['abc', 'def'],
        'key': 'value',
        'nested_dict': {'password': 'not_filtered'},
        'password': '12345qwerty',
    }

# Path: coaster/logger.py
# class RepeatValueIndicator:
#     """Represent a repeating value."""
# 
#     def __init__(self, key):
#         """Init with key."""
#         self.key = key
# 
#     def __repr__(self):
#         """Return representation."""
#         return f'<same as prior {self.key!r}>'
# 
#     __str__ = __repr__
# 
# def filtered_value(key, value):
#     """Find and mask sensitive values based on key names."""
#     if isinstance(key, str) and _filter_re.search(key):
#         return filtered_value_indicator
#     if isinstance(value, str):
#         return _card_re.sub('[Filtered]', value)
#     return value
# 
# def pprint_with_indent(dictlike, outfile, indent=4):
#     """Filter values and pprint with indent to create a Markdown code block."""
#     out = StringIO()
#     pprint(  # noqa: T003
#         {key: filtered_value(key, value) for key, value in dictlike.items()}, out
#     )
#     outfile.write(textwrap.indent(out.getvalue(), ' ' * indent))
#     out.close()


# Path: tests/test_logger.py
from io import StringIO
from coaster.logger import RepeatValueIndicator, filtered_value, pprint_with_indent

    # The filter uses a verbose regex. Words in the middle of the regex also work
    assert repr(filtered_value('access_token', 'secret-here')) == '[Filtered]'
    # Filters are case insensitive
    assert repr(filtered_value('TELEGRAM_ERROR_APIKEY', 'api:key')) == '[Filtered]'
    # Keys with 'token' as a word are also filtered
    assert repr(filtered_value('SMS_TWILIO_TOKEN', 'api:key')) == '[Filtered]'

    # Numbers that look like card numbers are filtered
    assert (
        filtered_value('anything', 'My number is 1234 5678 9012 3456')
        == 'My number is [Filtered]'
    )
    # This works with any combination of spaces and dashes within the number
    assert (
        filtered_value('anything', 'My number is 1234  5678-90123456')
        == 'My number is [Filtered]'
    )


def test_pprint_with_indent():
    """Test pprint_with_indent does indentation."""
    out = StringIO()
    data = {
        12: 34,
        'confirm_password': '12345qwerty',
        'credentials': ['abc', 'def'],
        'key': 'value',
        'nested_dict': {'password': 'not_filtered'},
        'password': '12345qwerty',
    }

    pprint_with_indent(data, out)