# Path: skoolkit/textutils.py
# def find_unquoted(text, char, start=0, end=None, neg=False):
#     if end is None:
#         end = len(text)
#     index = text.find(char, start, end)
#     if index >= 0:
#         if '"' not in text[start:end] or index < text.index('"', start, end):
#             return index
#         for p in split_quoted(text[start:end]):
#             index = p.find(char)
#             if index >= 0 and ('"' not in p or index < p.index('"')):
#                 return start + index
#             start += len(p)
#     if neg:
#         return -1
#     return end
# 
# def split_unquoted(text, sep, maxsplit=-1):
#     if '"' not in text:
#         return text.split(sep, maxsplit)
#     elements = []
#     quoted = 0
#     for p in text.split(sep):
#         if quoted:
#             elements[-1] += sep + p
#         else:
#             elements.append(p)
#         i = 0
#         while i < len(p):
#             c = p[i]
#             if c == '"':
#                 quoted = 1 - quoted
#             elif c == '\\' and quoted:
#                 i += 1
#             i += 1
#     if len(elements) > maxsplit + 1 > 0:
#         elements[maxsplit:] = [sep.join(elements[maxsplit:])]
#     return elements
# 
# def partition_unquoted(text, sep, default=''):
#     parts = split_unquoted(text, sep, 1)
#     if len(parts) == 2:
#         return (parts[0], sep, parts[1])
#     return (text, '', default)
# 
# def split_quoted(text):
#     return [e for e in re.split(r'("(?:[^"\\]|\\.)*")', text) if e]


from skoolkittest import SkoolKitTestCase
from skoolkit.textutils import find_unquoted, split_unquoted, partition_unquoted, split_quoted
    ('"a"', ['"a"']),
    ('"a"+4', ['"a"', '+4']),
    ('"b"+5+"c"', ['"b"', '+5+', '"c"']),
    ('6+"d"+7', ['6+', '"d"', '+7']),
    ('"e"-"f"', ['"e"', '-', '"f"']),
    (r'"\""', [r'"\""']),
    (r'"\""*10', [r'"\""', '*10']),
    (r'"\\"+1', [r'"\\"', '+1']),
    (r'\"abc","d"', ['\\', '"abc"', ',', '"d"'])
)

class TextUtilsTest(SkoolKitTestCase):
    def setUp(self):
        SkoolKitTestCase.setUp(self)
        self.longMessage = True

    def _test_function(self, exp_result, func, *args, **kwargs):
        args_str = ', '.join([repr(a) for a in args])
        kwargs_str = ', '.join(['{}={!r}'.format(k, v) for k, v in kwargs.items()])
        if kwargs_str:
            kwargs_str = ', ' + kwargs_str
        msg = "{}({}{}) failed".format(func.__name__, args_str, kwargs_str)
        self.assertEqual(exp_result, func(*args, **kwargs), msg)

    def test_find_unquoted(self):
        for args, kwargs, exp_result in TEST_FIND:
            self._test_function(exp_result, find_unquoted, *args, **kwargs)

    def test_split_unquoted(self):
        for args, exp_result in TEST_SPLIT:

# Path: skoolkit/textutils.py
# def find_unquoted(text, char, start=0, end=None, neg=False):
#     if end is None:
#         end = len(text)
#     index = text.find(char, start, end)
#     if index >= 0:
#         if '"' not in text[start:end] or index < text.index('"', start, end):
#             return index
#         for p in split_quoted(text[start:end]):
#             index = p.find(char)
#             if index >= 0 and ('"' not in p or index < p.index('"')):
#                 return start + index
#             start += len(p)
#     if neg:
#         return -1
#     return end
# 
# def split_unquoted(text, sep, maxsplit=-1):
#     if '"' not in text:
#         return text.split(sep, maxsplit)
#     elements = []
#     quoted = 0
#     for p in text.split(sep):
#         if quoted:
#             elements[-1] += sep + p
#         else:
#             elements.append(p)
#         i = 0
#         while i < len(p):
#             c = p[i]
#             if c == '"':
#                 quoted = 1 - quoted
#             elif c == '\\' and quoted:
#                 i += 1
#             i += 1
#     if len(elements) > maxsplit + 1 > 0:
#         elements[maxsplit:] = [sep.join(elements[maxsplit:])]
#     return elements
# 
# def partition_unquoted(text, sep, default=''):
#     parts = split_unquoted(text, sep, 1)
#     if len(parts) == 2:
#         return (parts[0], sep, parts[1])
#     return (text, '', default)
# 
# def split_quoted(text):
#     return [e for e in re.split(r'("(?:[^"\\]|\\.)*")', text) if e]


# Path: tests/test_textutils.py
from skoolkittest import SkoolKitTestCase
from skoolkit.textutils import find_unquoted, split_unquoted, partition_unquoted, split_quoted

    ('"a"', ['"a"']),
    ('"a"+4', ['"a"', '+4']),
    ('"b"+5+"c"', ['"b"', '+5+', '"c"']),
    ('6+"d"+7', ['6+', '"d"', '+7']),
    ('"e"-"f"', ['"e"', '-', '"f"']),
    (r'"\""', [r'"\""']),
    (r'"\""*10', [r'"\""', '*10']),
    (r'"\\"+1', [r'"\\"', '+1']),
    (r'\"abc","d"', ['\\', '"abc"', ',', '"d"'])
)

class TextUtilsTest(SkoolKitTestCase):
    def setUp(self):
        SkoolKitTestCase.setUp(self)
        self.longMessage = True

    def _test_function(self, exp_result, func, *args, **kwargs):
        args_str = ', '.join([repr(a) for a in args])
        kwargs_str = ', '.join(['{}={!r}'.format(k, v) for k, v in kwargs.items()])
        if kwargs_str:
            kwargs_str = ', ' + kwargs_str
        msg = "{}({}{}) failed".format(func.__name__, args_str, kwargs_str)
        self.assertEqual(exp_result, func(*args, **kwargs), msg)

    def test_find_unquoted(self):
        for args, kwargs, exp_result in TEST_FIND:
            self._test_function(exp_result, find_unquoted, *args, **kwargs)

    def test_split_unquoted(self):
        for args, exp_result in TEST_SPLIT:

            self._test_function(exp_result, split_unquoted, *args)