# Path: seaworthy/stream/matchers.py
# class EqualsMatcher(StreamMatcher):
#     """
#     Matcher that matches items by equality.
#     """
#     def __init__(self, expected_item):
#         self._expected_item = expected_item
# 
#     def match(self, item):
#         """
#         Return ``True`` if the item matches the expected value exactly,
#         otherwise ``False``.
#         """
#         return item == self._expected_item
# 
#     def args_str(self):
#         """
#         Return an args string for the repr.
#         """
#         return repr(self._expected_item)
# 
# class OrderedMatcher(CombinationMatcher):
#     """
#     Matcher that takes a list of matchers, and uses one after the next after
#     each has a successful match. Returns True ("matches") on the final match.
# 
#     **Note:** This is a *stateful* matcher. Once it has done its matching,
#     you'll need to create a new instance.
#     """
#     def __init__(self, *matchers):
#         super().__init__(*matchers)
#         self._position = 0
# 
#     def match(self, item):
#         """
#         Return ``True`` if the expected matchers are matched in the expected
#         order, otherwise ``False``.
#         """
#         if self._position == len(self._matchers):
#             raise RuntimeError('Matcher exhausted, no more matchers to use')
# 
#         matcher = self._matchers[self._position]
#         if matcher(item):
#             self._position += 1
# 
#         if self._position == len(self._matchers):
#             # All patterns have been matched
#             return True
# 
#         return False
# 
#     def args_str(self):
#         """
#         Return an args string for the repr.
#         """
#         matched = [str(m) for m in self._matchers[:self._position]]
#         unmatched = [str(m) for m in self._matchers[self._position:]]
#         return 'matched=[{}], unmatched=[{}]'.format(
#             ', '.join(matched), ', '.join(unmatched))
# 
# class RegexMatcher(StreamMatcher):
#     """
#     Matcher that matches items by regex pattern.
#     """
#     def __init__(self, pattern):
#         self._regex = re.compile(pattern)
# 
#     def match(self, item):
#         """
#         Return ``True`` if the item matches the expected regex, otherwise
#         ``False``.
#         """
#         return self._regex.search(item) is not None
# 
#     def args_str(self):
#         """
#         Return an args string for the repr.
#         """
#         return repr(self._regex.pattern)
# 
# class UnorderedMatcher(CombinationMatcher):
#     """
#     Matcher that takes a list of matchers, and matches each one to an item.
#     Each item is tested against each unmatched matcher until a match is found
#     or all unmatched matchers are checked. Returns True ("matches") on the
#     final match.
# 
#     .. note::
# 
#         This is a *stateful* matcher. Once it has done its matching,
#         you'll need to create a new instance.
#     """
#     def __init__(self, *matchers):
#         super().__init__(*matchers)
#         self._used_matchers = []
# 
#     @property
#     def _unused_matchers(self):
#         return [m for m in self._matchers if m not in self._used_matchers]
# 
#     def match(self, item):
#         """
#         Return ``True`` if the expected matchers are matched in any order,
#         otherwise ``False``.
#         """
#         if not self._unused_matchers:
#             raise RuntimeError('Matcher exhausted, no more matchers to use')
# 
#         for matcher in self._unused_matchers:
#             if matcher(item):
#                 self._used_matchers.append(matcher)
#                 break
# 
#         if not self._unused_matchers:
#             # All patterns have been matched
#             return True
# 
#         return False
# 
#     def args_str(self):
#         """
#         Return an args string for the repr.
#         """
#         matched = [str(m) for m in self._used_matchers]
#         unmatched = [str(m) for m in self._unused_matchers]
#         return 'matched=[{}], unmatched=[{}]'.format(
#             ', '.join(matched), ', '.join(unmatched))


import unittest
from seaworthy.stream.matchers import (
    EqualsMatcher, OrderedMatcher, RegexMatcher, UnorderedMatcher)



class TestEqualsMatcher(unittest.TestCase):
    def test_matching(self):
        """ Matches exactly equal strings and nothing else. """
        matcher = EqualsMatcher('foo')
        self.assertTrue(matcher('foo'))
        self.assertFalse(matcher('foobar'))

    def test_str(self):
        """ The string representation is readable. """

# Path: seaworthy/stream/matchers.py
# class EqualsMatcher(StreamMatcher):
#     """
#     Matcher that matches items by equality.
#     """
#     def __init__(self, expected_item):
#         self._expected_item = expected_item
# 
#     def match(self, item):
#         """
#         Return ``True`` if the item matches the expected value exactly,
#         otherwise ``False``.
#         """
#         return item == self._expected_item
# 
#     def args_str(self):
#         """
#         Return an args string for the repr.
#         """
#         return repr(self._expected_item)
# 
# class OrderedMatcher(CombinationMatcher):
#     """
#     Matcher that takes a list of matchers, and uses one after the next after
#     each has a successful match. Returns True ("matches") on the final match.
# 
#     **Note:** This is a *stateful* matcher. Once it has done its matching,
#     you'll need to create a new instance.
#     """
#     def __init__(self, *matchers):
#         super().__init__(*matchers)
#         self._position = 0
# 
#     def match(self, item):
#         """
#         Return ``True`` if the expected matchers are matched in the expected
#         order, otherwise ``False``.
#         """
#         if self._position == len(self._matchers):
#             raise RuntimeError('Matcher exhausted, no more matchers to use')
# 
#         matcher = self._matchers[self._position]
#         if matcher(item):
#             self._position += 1
# 
#         if self._position == len(self._matchers):
#             # All patterns have been matched
#             return True
# 
#         return False
# 
#     def args_str(self):
#         """
#         Return an args string for the repr.
#         """
#         matched = [str(m) for m in self._matchers[:self._position]]
#         unmatched = [str(m) for m in self._matchers[self._position:]]
#         return 'matched=[{}], unmatched=[{}]'.format(
#             ', '.join(matched), ', '.join(unmatched))
# 
# class RegexMatcher(StreamMatcher):
#     """
#     Matcher that matches items by regex pattern.
#     """
#     def __init__(self, pattern):
#         self._regex = re.compile(pattern)
# 
#     def match(self, item):
#         """
#         Return ``True`` if the item matches the expected regex, otherwise
#         ``False``.
#         """
#         return self._regex.search(item) is not None
# 
#     def args_str(self):
#         """
#         Return an args string for the repr.
#         """
#         return repr(self._regex.pattern)
# 
# class UnorderedMatcher(CombinationMatcher):
#     """
#     Matcher that takes a list of matchers, and matches each one to an item.
#     Each item is tested against each unmatched matcher until a match is found
#     or all unmatched matchers are checked. Returns True ("matches") on the
#     final match.
# 
#     .. note::
# 
#         This is a *stateful* matcher. Once it has done its matching,
#         you'll need to create a new instance.
#     """
#     def __init__(self, *matchers):
#         super().__init__(*matchers)
#         self._used_matchers = []
# 
#     @property
#     def _unused_matchers(self):
#         return [m for m in self._matchers if m not in self._used_matchers]
# 
#     def match(self, item):
#         """
#         Return ``True`` if the expected matchers are matched in any order,
#         otherwise ``False``.
#         """
#         if not self._unused_matchers:
#             raise RuntimeError('Matcher exhausted, no more matchers to use')
# 
#         for matcher in self._unused_matchers:
#             if matcher(item):
#                 self._used_matchers.append(matcher)
#                 break
# 
#         if not self._unused_matchers:
#             # All patterns have been matched
#             return True
# 
#         return False
# 
#     def args_str(self):
#         """
#         Return an args string for the repr.
#         """
#         matched = [str(m) for m in self._used_matchers]
#         unmatched = [str(m) for m in self._unused_matchers]
#         return 'matched=[{}], unmatched=[{}]'.format(
#             ', '.join(matched), ', '.join(unmatched))


# Path: seaworthy/tests-core/stream/test_matchers.py
import unittest
from seaworthy.stream.matchers import (
    EqualsMatcher, OrderedMatcher, RegexMatcher, UnorderedMatcher)




class TestEqualsMatcher(unittest.TestCase):
    def test_matching(self):
        """ Matches exactly equal strings and nothing else. """
        matcher = EqualsMatcher('foo')
        self.assertTrue(matcher('foo'))
        self.assertFalse(matcher('foobar'))

    def test_str(self):
        """ The string representation is readable. """

        matcher = EqualsMatcher('bar')