# Path: rebulk/pattern.py
# class StringPattern(Pattern):
#     """
#     Definition of one or many strings to search for.
#     """
# 
#     def __init__(self, *patterns, **kwargs):
#         super().__init__(**kwargs)
#         self._patterns = patterns
#         self._kwargs = kwargs
#         self._match_kwargs = filter_match_kwargs(kwargs)
# 
#     @property
#     def patterns(self):
#         return self._patterns
# 
#     @property
#     def match_options(self):
#         return self._match_kwargs
# 
#     def _match(self, pattern, input_string, context=None):
#         for index in find_all(input_string, pattern, **self._kwargs):
#             match = Match(index, index + len(pattern), pattern=self, input_string=input_string, **self._match_kwargs)
#             if match:
#                 yield match
# 
# Path: rebulk/validators.py
# def chars_before(chars, match):
#     """
#     Validate the match if left character is in a given sequence.
# 
#     :param chars:
#     :type chars:
#     :param match:
#     :type match:
#     :return:
#     :rtype:
#     """
#     if match.start <= 0:
#         return True
#     return match.input_string[match.start - 1] in chars
# 
# def chars_after(chars, match):
#     """
#     Validate the match if right character is in a given sequence.
# 
#     :param chars:
#     :type chars:
#     :param match:
#     :type match:
#     :return:
#     :rtype:
#     """
#     if match.end >= len(match.input_string):
#         return True
#     return match.input_string[match.end] in chars
# 
# def chars_surround(chars, match):
#     """
#     Validate the match if surrounding characters are in a given sequence.
# 
#     :param chars:
#     :type chars:
#     :param match:
#     :type match:
#     :return:
#     :rtype:
#     """
#     return chars_before(chars, match) and chars_after(chars, match)
# 
# def validators(*chained_validators):
#     """
#     Creates a validator chain from several validator functions.
# 
#     :param chained_validators:
#     :type chained_validators:
#     :return:
#     :rtype:
#     """
# 
#     def validator_chain(match):  # pylint:disable=missing-docstring
#         for chained_validator in chained_validators:
#             if not chained_validator(match):
#                 return False
#         return True
# 
#     return validator_chain


from functools import partial
from rebulk.pattern import StringPattern
from ..validators import chars_before, chars_after, chars_surround, validators

def test_right_chars():
    matches = list(StringPattern("word", validator=right).matches("xxxwordxxx"))
    assert len(matches) == 0

    matches = list(StringPattern("word", validator=right).matches("xxxword.xxx"))
    assert len(matches) == 1

    matches = list(StringPattern("word", validator=right).matches("xxxword"))
    assert len(matches) == 1


def test_surrounding_chars():
    matches = list(StringPattern("word", validator=surrounding).matches("xxxword xxx"))
    assert len(matches) == 0

    matches = list(StringPattern("word", validator=surrounding).matches("xxx.wordxxx"))
    assert len(matches) == 0

    matches = list(StringPattern("word", validator=surrounding).matches("xxx word_xxx"))
    assert len(matches) == 1

    matches = list(StringPattern("word", validator=surrounding).matches("word"))
    assert len(matches) == 1


def test_chain():
    matches = list(StringPattern("word", validator=validators(left, right)).matches("xxxword xxx"))
    assert len(matches) == 0


# Path: rebulk/pattern.py
# class StringPattern(Pattern):
#     """
#     Definition of one or many strings to search for.
#     """
# 
#     def __init__(self, *patterns, **kwargs):
#         super().__init__(**kwargs)
#         self._patterns = patterns
#         self._kwargs = kwargs
#         self._match_kwargs = filter_match_kwargs(kwargs)
# 
#     @property
#     def patterns(self):
#         return self._patterns
# 
#     @property
#     def match_options(self):
#         return self._match_kwargs
# 
#     def _match(self, pattern, input_string, context=None):
#         for index in find_all(input_string, pattern, **self._kwargs):
#             match = Match(index, index + len(pattern), pattern=self, input_string=input_string, **self._match_kwargs)
#             if match:
#                 yield match
# 
# Path: rebulk/validators.py
# def chars_before(chars, match):
#     """
#     Validate the match if left character is in a given sequence.
# 
#     :param chars:
#     :type chars:
#     :param match:
#     :type match:
#     :return:
#     :rtype:
#     """
#     if match.start <= 0:
#         return True
#     return match.input_string[match.start - 1] in chars
# 
# def chars_after(chars, match):
#     """
#     Validate the match if right character is in a given sequence.
# 
#     :param chars:
#     :type chars:
#     :param match:
#     :type match:
#     :return:
#     :rtype:
#     """
#     if match.end >= len(match.input_string):
#         return True
#     return match.input_string[match.end] in chars
# 
# def chars_surround(chars, match):
#     """
#     Validate the match if surrounding characters are in a given sequence.
# 
#     :param chars:
#     :type chars:
#     :param match:
#     :type match:
#     :return:
#     :rtype:
#     """
#     return chars_before(chars, match) and chars_after(chars, match)
# 
# def validators(*chained_validators):
#     """
#     Creates a validator chain from several validator functions.
# 
#     :param chained_validators:
#     :type chained_validators:
#     :return:
#     :rtype:
#     """
# 
#     def validator_chain(match):  # pylint:disable=missing-docstring
#         for chained_validator in chained_validators:
#             if not chained_validator(match):
#                 return False
#         return True
# 
#     return validator_chain


# Path: rebulk/test/test_validators.py
from functools import partial
from rebulk.pattern import StringPattern
from ..validators import chars_before, chars_after, chars_surround, validators


def test_right_chars():
    matches = list(StringPattern("word", validator=right).matches("xxxwordxxx"))
    assert len(matches) == 0

    matches = list(StringPattern("word", validator=right).matches("xxxword.xxx"))
    assert len(matches) == 1

    matches = list(StringPattern("word", validator=right).matches("xxxword"))
    assert len(matches) == 1


def test_surrounding_chars():
    matches = list(StringPattern("word", validator=surrounding).matches("xxxword xxx"))
    assert len(matches) == 0

    matches = list(StringPattern("word", validator=surrounding).matches("xxx.wordxxx"))
    assert len(matches) == 0

    matches = list(StringPattern("word", validator=surrounding).matches("xxx word_xxx"))
    assert len(matches) == 1

    matches = list(StringPattern("word", validator=surrounding).matches("word"))
    assert len(matches) == 1


def test_chain():
    matches = list(StringPattern("word", validator=validators(left, right)).matches("xxxword xxx"))
    assert len(matches) == 0


    matches = list(StringPattern("word", validator=validators(left, right)).matches("xxx.wordxxx"))