# Path: mistletoe/core_tokens.py
# class MatchObj:
#     def __init__(self, start, end, *fields):
#         self._start = start
#         self._end = end
#         self.fields = fields
# 
#     def start(self, n=0):
#         if n == 0:
#             return self._start
#         return self.fields[n-1][0]
# 
#     def end(self, n=0):
#         if n == 0:
#             return self._end
#         return self.fields[n-1][1]
# 
#     def group(self, n=0):
#         if n == 0:
#             return ''.join([field[2] for field in self.fields])
#         return self.fields[n-1][2]
# 
#     def __repr__(self):
#         return '<MatchObj fields={} start={} end={}>'.format(self.fields, self._start, self._end)
# 
# class Delimiter:
#     def __init__(self, start, end, string):
#         self.type = string[start:end]
#         self.number = end - start
#         self.active = True
#         self.start = start
#         self.end = end
#         if self.type.startswith(('*', '_')):
#             self.open = is_opener(start, end, string)
#             self.close = is_closer(start, end, string)
# 
#     def remove(self, n, left=True):
#         if self.number - n == 0:
#             return False
#         if left:
#             self.start = self.start + n
#             self.number = self.end - self.start
#             self.type = self.type[n:]
#             return True
#         self.end = self.end - n
#         self.number = self.end - self.start
#         self.type = self.type[:n]
#         return True
# 
#     def closed_by(self, other):
#         return not (self.type[0] != other.type[0]
#                     or (self.open and self.close or other.open and other.close)
#                     and (self.number + other.number) % 3 == 0)
# 
# 
#     def __repr__(self):
#         if not self.type.startswith(('*', '_')):
#             return '<Delimiter type={} active={}>'.format(repr(self.type), self.active)
#         return '<Delimiter type={} active={} open={} close={}>'.format(repr(self.type), self.active, self.open, self.close)
# 
# def follows(string, index, char):
#     return index + 1 < len(string) and string[index+1] == char
# 
# def shift_whitespace(string, index):
#     for i, c in enumerate(string[index:], start=index):
#         if c not in whitespace:
#             return i
#     return len(string)
# 
# def is_control_char(char):
#     return ord(char) < 32 or ord(char) == 127
# 
# def deactivate_delimiters(delimiters, index, delimiter_type):
#     for delimiter in delimiters[:index]:
#         if delimiter.type == delimiter_type:
#             delimiter.active = False
# 
# def preceded_by(start, string, charset):
#     preceding_char = string[start-1] if start > 0 else ' '
#     return preceding_char in charset
# 
# def succeeded_by(end, string, charset):
#     succeeding_char = string[end] if end < len(string) else ' '
#     return succeeding_char in charset


from unittest import TestCase
from unittest.mock import patch
from mistletoe.core_tokens import (MatchObj, Delimiter, follows, shift_whitespace,
        is_control_char, deactivate_delimiters, preceded_by, succeeded_by)
        self.assertEqual(match.group(2), 'b')

    def test_delimiter(self):
        delimiter = Delimiter(4, 6, 'abcd**')
        self.assertEqual(delimiter.type, '**')
        self.assertEqual(delimiter.number, 2)
        self.assertEqual(delimiter.active, True)
        self.assertEqual(delimiter.start, 4)
        self.assertEqual(delimiter.end, 6)

    def test_delimiter_remove_left(self):
        delimiter = Delimiter(4, 6, 'abcd**')
        self.assertTrue(delimiter.remove(1, left=True))
        self.assertEqual(delimiter.number, 1)
        self.assertEqual(delimiter.start, 5)
        self.assertEqual(delimiter.end, 6)

    def test_delimiter_remove_right(self):
        delimiter = Delimiter(4, 6, 'abcd**')
        self.assertTrue(delimiter.remove(1, left=False))
        self.assertEqual(delimiter.number, 1)
        self.assertEqual(delimiter.start, 4)
        self.assertEqual(delimiter.end, 5)

    def test_delimiter_remove_empty(self):
        delimiter = Delimiter(4, 6, 'abcd**')
        self.assertFalse(delimiter.remove(2))

    def test_follows(self):
        string = '(foobar)'

# Path: mistletoe/core_tokens.py
# class MatchObj:
#     def __init__(self, start, end, *fields):
#         self._start = start
#         self._end = end
#         self.fields = fields
# 
#     def start(self, n=0):
#         if n == 0:
#             return self._start
#         return self.fields[n-1][0]
# 
#     def end(self, n=0):
#         if n == 0:
#             return self._end
#         return self.fields[n-1][1]
# 
#     def group(self, n=0):
#         if n == 0:
#             return ''.join([field[2] for field in self.fields])
#         return self.fields[n-1][2]
# 
#     def __repr__(self):
#         return '<MatchObj fields={} start={} end={}>'.format(self.fields, self._start, self._end)
# 
# class Delimiter:
#     def __init__(self, start, end, string):
#         self.type = string[start:end]
#         self.number = end - start
#         self.active = True
#         self.start = start
#         self.end = end
#         if self.type.startswith(('*', '_')):
#             self.open = is_opener(start, end, string)
#             self.close = is_closer(start, end, string)
# 
#     def remove(self, n, left=True):
#         if self.number - n == 0:
#             return False
#         if left:
#             self.start = self.start + n
#             self.number = self.end - self.start
#             self.type = self.type[n:]
#             return True
#         self.end = self.end - n
#         self.number = self.end - self.start
#         self.type = self.type[:n]
#         return True
# 
#     def closed_by(self, other):
#         return not (self.type[0] != other.type[0]
#                     or (self.open and self.close or other.open and other.close)
#                     and (self.number + other.number) % 3 == 0)
# 
# 
#     def __repr__(self):
#         if not self.type.startswith(('*', '_')):
#             return '<Delimiter type={} active={}>'.format(repr(self.type), self.active)
#         return '<Delimiter type={} active={} open={} close={}>'.format(repr(self.type), self.active, self.open, self.close)
# 
# def follows(string, index, char):
#     return index + 1 < len(string) and string[index+1] == char
# 
# def shift_whitespace(string, index):
#     for i, c in enumerate(string[index:], start=index):
#         if c not in whitespace:
#             return i
#     return len(string)
# 
# def is_control_char(char):
#     return ord(char) < 32 or ord(char) == 127
# 
# def deactivate_delimiters(delimiters, index, delimiter_type):
#     for delimiter in delimiters[:index]:
#         if delimiter.type == delimiter_type:
#             delimiter.active = False
# 
# def preceded_by(start, string, charset):
#     preceding_char = string[start-1] if start > 0 else ' '
#     return preceding_char in charset
# 
# def succeeded_by(end, string, charset):
#     succeeding_char = string[end] if end < len(string) else ' '
#     return succeeding_char in charset


# Path: test/test_core_tokens.py
from unittest import TestCase
from unittest.mock import patch
from mistletoe.core_tokens import (MatchObj, Delimiter, follows, shift_whitespace,
        is_control_char, deactivate_delimiters, preceded_by, succeeded_by)

        self.assertEqual(match.group(2), 'b')

    def test_delimiter(self):
        delimiter = Delimiter(4, 6, 'abcd**')
        self.assertEqual(delimiter.type, '**')
        self.assertEqual(delimiter.number, 2)
        self.assertEqual(delimiter.active, True)
        self.assertEqual(delimiter.start, 4)
        self.assertEqual(delimiter.end, 6)

    def test_delimiter_remove_left(self):
        delimiter = Delimiter(4, 6, 'abcd**')
        self.assertTrue(delimiter.remove(1, left=True))
        self.assertEqual(delimiter.number, 1)
        self.assertEqual(delimiter.start, 5)
        self.assertEqual(delimiter.end, 6)

    def test_delimiter_remove_right(self):
        delimiter = Delimiter(4, 6, 'abcd**')
        self.assertTrue(delimiter.remove(1, left=False))
        self.assertEqual(delimiter.number, 1)
        self.assertEqual(delimiter.start, 4)
        self.assertEqual(delimiter.end, 5)

    def test_delimiter_remove_empty(self):
        delimiter = Delimiter(4, 6, 'abcd**')
        self.assertFalse(delimiter.remove(2))

    def test_follows(self):
        string = '(foobar)'

        self.assertTrue(follows(string, 6, ')'))