# Path: clearly/client/code_highlighter.py
# def typed_code(p: Any, wrap: bool = True) -> str:
#     if p is None:
#         return NONE
# 
#     if isinstance(p, bool):
#         return Colors.CYAN(str(p))
# 
#     if isinstance(p, str):
#         if "'" in p and '"' not in p:
#             escape = '"'
#         else:
#             escape = "'"
#             p = p.replace("'", "\\'")
#         return Colors.YELLOW('{c}{p}{c}'.format(p=p, c=escape))
# 
#     if isinstance(p, (int, float, complex)):
#         return Colors.GREEN(str(p))
# 
#     if isinstance(p, CallDescriptor):
#         func_args = typed_code(p.args, wrap=False) if p.args else ''
#         if p.kwargs:
#             if p.args:
#                 func_args += SEPARATOR
#             func_args += typed_code(p.kwargs, wrap=False)
#         return '{}({})'.format(p.name, func_args)
# 
#     if isinstance(p, list):
#         f = '[{}]' if wrap else '{}'
#         return f.format(SEPARATOR.join(typed_code(x) for x in p))
# 
#     if isinstance(p, set):
#         return '{{{}}}'.format(typed_code(sorted(p, key=lambda x: str(x)), wrap=False))
# 
#     if isinstance(p, tuple):
#         if wrap:
#             f = '({})' if len(p) != 1 else '({},)'
#         else:
#             f = '{}'
#         return f.format(SEPARATOR.join(typed_code(x) for x in p))
# 
#     if isinstance(p, dict):
#         if wrap:
#             f = '{{{}}}'
#             sep = DICT_SEPARATOR
# 
#             def key(k):
#                 return typed_code(k)
#         else:
#             f = '{}'
#             sep = KWARGS_SEPARATOR
# 
#             def key(k):
#                 return Colors.ORANGE(k)
# 
#         return f.format(
#             SEPARATOR.join('{}{}{}'.format(key(k), sep, typed_code(v))
#                            for k, v in p.items()))
# 
#     return repr(p)
# 
# Path: clearly/utils/safe_compiler.py
# NON_PRINTABLE_PATTERN = re.compile('[\x00-\x1f]')
# def safe_compile_text(txt: str, raises: bool = False) -> Any:
#     def _convert(node):
# def _encode_to_hex(match: Match) -> str:


from collections import OrderedDict
from datetime import datetime
from decimal import Decimal
from clearly.client.code_highlighter import typed_code
from clearly.utils.safe_compiler import CallDescriptor
import pytest

    # unicode
    ('rogério', "'rogério'"),
    (('á', 'ç'), "('á', 'ç')"),
    ({'ñ', 'ô'}, "{'ñ', 'ô'}"),
    ({'ì': 'ü'}, "{'ì': 'ü'}"),

    # complex structures
    ((1, (2, True, {5, 4}), ['ba', 'b'], {1: 2}), "(1, (2, True, {4, 5}), ['ba', 'b'], {1: 2})"),
    ([1, (2, 3), {'ok': True}], "[1, (2, 3), {'ok': True}]"),
    (OrderedDict((((1, 2), ['a', 'b']), (True, {5, 6, 7}))),
     "{(1, 2): ['a', 'b'], True: {5, 6, 7}}"),

    # repr fallback
    (datetime(2018, 1, 1), 'datetime.datetime(2018, 1, 1, 0, 0)'),
    (Decimal('1.23'), "Decimal('1.23')"),

    # functions
    (CallDescriptor('rogerio', None, None), 'rogerio()'),
    (CallDescriptor('datetime', (2018, 1, 1), None), 'datetime(2018, 1, 1)'),
    (CallDescriptor('datetime.timedelta', None, {'secs': 1}), 'datetime.timedelta(secs=1)'),
    ((1, CallDescriptor('f', (1,), None), CallDescriptor('g', None, {'x': 2})),
     '(1, f(1), g(x=2))'),
    (['a', CallDescriptor('m.n', ('1',), None)], "['a', m.n('1')]"),
    ({True, CallDescriptor('f', (False,), None)}, '{f(False), True}'),
    ({None: CallDescriptor('f', None, {'param': None})}, '{None: f(param=None)}'),

    # complex functions
    (CallDescriptor('rogerio', ((1, 2), {'name': 'ok'}), {'dry_run': True}),
     "rogerio((1, 2), {'name': 'ok'}, dry_run=True)"),

# Path: clearly/client/code_highlighter.py
# def typed_code(p: Any, wrap: bool = True) -> str:
#     if p is None:
#         return NONE
# 
#     if isinstance(p, bool):
#         return Colors.CYAN(str(p))
# 
#     if isinstance(p, str):
#         if "'" in p and '"' not in p:
#             escape = '"'
#         else:
#             escape = "'"
#             p = p.replace("'", "\\'")
#         return Colors.YELLOW('{c}{p}{c}'.format(p=p, c=escape))
# 
#     if isinstance(p, (int, float, complex)):
#         return Colors.GREEN(str(p))
# 
#     if isinstance(p, CallDescriptor):
#         func_args = typed_code(p.args, wrap=False) if p.args else ''
#         if p.kwargs:
#             if p.args:
#                 func_args += SEPARATOR
#             func_args += typed_code(p.kwargs, wrap=False)
#         return '{}({})'.format(p.name, func_args)
# 
#     if isinstance(p, list):
#         f = '[{}]' if wrap else '{}'
#         return f.format(SEPARATOR.join(typed_code(x) for x in p))
# 
#     if isinstance(p, set):
#         return '{{{}}}'.format(typed_code(sorted(p, key=lambda x: str(x)), wrap=False))
# 
#     if isinstance(p, tuple):
#         if wrap:
#             f = '({})' if len(p) != 1 else '({},)'
#         else:
#             f = '{}'
#         return f.format(SEPARATOR.join(typed_code(x) for x in p))
# 
#     if isinstance(p, dict):
#         if wrap:
#             f = '{{{}}}'
#             sep = DICT_SEPARATOR
# 
#             def key(k):
#                 return typed_code(k)
#         else:
#             f = '{}'
#             sep = KWARGS_SEPARATOR
# 
#             def key(k):
#                 return Colors.ORANGE(k)
# 
#         return f.format(
#             SEPARATOR.join('{}{}{}'.format(key(k), sep, typed_code(v))
#                            for k, v in p.items()))
# 
#     return repr(p)
# 
# Path: clearly/utils/safe_compiler.py
# NON_PRINTABLE_PATTERN = re.compile('[\x00-\x1f]')
# def safe_compile_text(txt: str, raises: bool = False) -> Any:
#     def _convert(node):
# def _encode_to_hex(match: Match) -> str:


# Path: tests/unit/client/test_code_highlighter.py
from collections import OrderedDict
from datetime import datetime
from decimal import Decimal
from clearly.client.code_highlighter import typed_code
from clearly.utils.safe_compiler import CallDescriptor
import pytest


    # unicode
    ('rogério', "'rogério'"),
    (('á', 'ç'), "('á', 'ç')"),
    ({'ñ', 'ô'}, "{'ñ', 'ô'}"),
    ({'ì': 'ü'}, "{'ì': 'ü'}"),

    # complex structures
    ((1, (2, True, {5, 4}), ['ba', 'b'], {1: 2}), "(1, (2, True, {4, 5}), ['ba', 'b'], {1: 2})"),
    ([1, (2, 3), {'ok': True}], "[1, (2, 3), {'ok': True}]"),
    (OrderedDict((((1, 2), ['a', 'b']), (True, {5, 6, 7}))),
     "{(1, 2): ['a', 'b'], True: {5, 6, 7}}"),

    # repr fallback
    (datetime(2018, 1, 1), 'datetime.datetime(2018, 1, 1, 0, 0)'),
    (Decimal('1.23'), "Decimal('1.23')"),

    # functions
    (CallDescriptor('rogerio', None, None), 'rogerio()'),
    (CallDescriptor('datetime', (2018, 1, 1), None), 'datetime(2018, 1, 1)'),
    (CallDescriptor('datetime.timedelta', None, {'secs': 1}), 'datetime.timedelta(secs=1)'),
    ((1, CallDescriptor('f', (1,), None), CallDescriptor('g', None, {'x': 2})),
     '(1, f(1), g(x=2))'),
    (['a', CallDescriptor('m.n', ('1',), None)], "['a', m.n('1')]"),
    ({True, CallDescriptor('f', (False,), None)}, '{f(False), True}'),
    ({None: CallDescriptor('f', None, {'param': None})}, '{None: f(param=None)}'),

    # complex functions
    (CallDescriptor('rogerio', ((1, 2), {'name': 'ok'}), {'dry_run': True}),
     "rogerio((1, 2), {'name': 'ok'}, dry_run=True)"),

    (CallDescriptor('call', None,