# Path: foil/patterns.py
# def match_subgroup(sequence, pattern):
#     """Yield the sub-group element dictionary that match a regex pattern."""
# 
#     for element in sequence:
#         match = re.match(pattern, element)
# 
#         if match:
#             yield match.groupdict()
# 
# def match_group(choices: Iterable) -> str:
#     return '|'.join(choices)
# 
# def add_regex_start_end(pattern_function):
#     """Decorator for adding regex pattern start and end characters."""
# 
#     @wraps(pattern_function)
#     def func_wrapper(*args, **kwargs):
#         return r'^{}$'.format(pattern_function(*args, **kwargs))
#     return func_wrapper
# 
# def tokenize_group_pattern(name, choices):
#     pattern = match_group(choices)
#     return tokenize_pattern(name, pattern)


import re
import unittest
from foil.patterns import (
    match_subgroup, match_group, add_regex_start_end, tokenize_group_pattern
)
        element2 = r'(?P<element2>[0-9])'
        pattern = re.compile(element1 + r'_' + element2)
        sequence = ['A_1', '1_Z', 'B_2', 'C_#']

        expected = [
            {'element1': 'A', 'element2': '1'},
            {'element1': 'B', 'element2': '2'}
        ]

        result = list(match_subgroup(sequence, pattern))

        self.assertEqual(expected, result)


class TestReHelpers(unittest.TestCase):

    def test_match_group(self):
        result = match_group(['apple', 'orange', 'peach'])
        expected = 'apple|orange|peach'

        self.assertEqual(expected, result)

    def test_add_regex_start_end(self):
        # NOTE: purposely using one positional and one keyword arg in test.
        @add_regex_start_end
        def foo(currency, country='[A-Z]{2}'):
            return '{currency}_{country}'.format(currency=currency,
                                                 country=country)

        result = foo('USD')

# Path: foil/patterns.py
# def match_subgroup(sequence, pattern):
#     """Yield the sub-group element dictionary that match a regex pattern."""
# 
#     for element in sequence:
#         match = re.match(pattern, element)
# 
#         if match:
#             yield match.groupdict()
# 
# def match_group(choices: Iterable) -> str:
#     return '|'.join(choices)
# 
# def add_regex_start_end(pattern_function):
#     """Decorator for adding regex pattern start and end characters."""
# 
#     @wraps(pattern_function)
#     def func_wrapper(*args, **kwargs):
#         return r'^{}$'.format(pattern_function(*args, **kwargs))
#     return func_wrapper
# 
# def tokenize_group_pattern(name, choices):
#     pattern = match_group(choices)
#     return tokenize_pattern(name, pattern)


# Path: tests/test_patterns.py
import re
import unittest
from foil.patterns import (
    match_subgroup, match_group, add_regex_start_end, tokenize_group_pattern
)

        element2 = r'(?P<element2>[0-9])'
        pattern = re.compile(element1 + r'_' + element2)
        sequence = ['A_1', '1_Z', 'B_2', 'C_#']

        expected = [
            {'element1': 'A', 'element2': '1'},
            {'element1': 'B', 'element2': '2'}
        ]

        result = list(match_subgroup(sequence, pattern))

        self.assertEqual(expected, result)


class TestReHelpers(unittest.TestCase):

    def test_match_group(self):
        result = match_group(['apple', 'orange', 'peach'])
        expected = 'apple|orange|peach'

        self.assertEqual(expected, result)

    def test_add_regex_start_end(self):
        # NOTE: purposely using one positional and one keyword arg in test.
        @add_regex_start_end
        def foo(currency, country='[A-Z]{2}'):
            return '{currency}_{country}'.format(currency=currency,
                                                 country=country)

        result = foo('USD')

        expected = '^USD_[A-Z]{2}$'