# Path: cjktools/resources/bilingual_dict.py
# class ClashPolicy(Enum):
# class BilingualDictionary(dict):
# class DictionaryEntry(object):
#     def __init__(self, fmt):
#     def update(self, rhs_dictionary, clash_policy=ClashPolicy.Overwrite):
#     def __init__(self, word, readings, senses):
#     def update(self, rhs_entry):
#     def senses_by_reading(self):
#     def __repr__(self):
#     def __str__(self):
#     def __hash__(self):
# 
# Path: cjktools/errors.py
# class NotYetImplementedError(Exception):
#     """
#     A placeholder to use when you define a method but haven't implemented
#     it yet.
#     """
#     pass
# 
# Path: cjktools/resources/dict_format.py
# class RegexFormat(DictionaryFormat):
#     """
#     Describes a dictionary format, by providing regular expressions
#     for the header, the entry lines, and senses within an entry line. The
#     entry line pattern should have named values called 'word', 'reading',
#     and 'senses'.
#     """
# 
#     def __init__(self, name, header_pattern, line_pattern, sense_pattern):
#         self.name = name
#         self.header_pattern = re.compile(header_pattern, re.UNICODE)
#         self.line_pattern = re.compile(line_pattern, re.UNICODE)
#         self.sense_pattern = re.compile(sense_pattern, re.UNICODE)
# 
#     def match_header(self, header_line):
#         return bool(self.header_pattern.match(header_line))
# 
#     def parse_line(self, entry_line):
#         match = self.line_pattern.match(entry_line)
#         if not match:
#             raise FormatError("Bad line: %s" % entry_line)
# 
#         match_dict = match.groupdict()
# 
#         word = match_dict['word'].replace(' ', '')
#         reading = (match_dict.get('reading') or word).replace(' ', '')
#         readings = [reading]
#         sense_line = match_dict.get('senses')
# 
#         senses = []
#         for match in self.sense_pattern.finditer(sense_line):
#             senses.append(match.groupdict()['sense'])
# 
#         if not senses:
#             raise FormatError("No senses for word: %s" % word)
# 
#         return DictionaryEntry(word, readings, senses)


import unittest
from cjktools.resources import bilingual_dict
from cjktools.errors import NotYetImplementedError
from cjktools.resources.dict_format import RegexFormat
    '^.？？？.*$',
    '^(?P<word>[^ ]+) (\[(?P<reading>[^\]]+)\] )?(?P<senses>.*)$',
    '/(?P<sense>[^/]+)'
)


class BilingualDictTest(unittest.TestCase):
    def testUpdateDefaultPolicy(self):
        d1 = bilingual_dict.BilingualDictionary(edict_fmt)

        d1['a'] = 2
        d2 = {'a': 4, 'b': 1}

        d1.update(d2)

        self.assertEqual(d1['a'], 4)
        self.assertEqual(d1['b'], 1)

    def testClashPolicyOverwrite(self):
        d1 = bilingual_dict.BilingualDictionary(edict_fmt)

        d1['a'] = 2
        d2 = {'a': 4, 'b': 1}

        d1.update(d2, clash_policy=bilingual_dict.ClashPolicy.Overwrite)

        self.assertEqual(d1['a'], 4)
        self.assertEqual(d1['b'], 1)

    def testClashPolicyMerge(self):

# Path: cjktools/resources/bilingual_dict.py
# class ClashPolicy(Enum):
# class BilingualDictionary(dict):
# class DictionaryEntry(object):
#     def __init__(self, fmt):
#     def update(self, rhs_dictionary, clash_policy=ClashPolicy.Overwrite):
#     def __init__(self, word, readings, senses):
#     def update(self, rhs_entry):
#     def senses_by_reading(self):
#     def __repr__(self):
#     def __str__(self):
#     def __hash__(self):
# 
# Path: cjktools/errors.py
# class NotYetImplementedError(Exception):
#     """
#     A placeholder to use when you define a method but haven't implemented
#     it yet.
#     """
#     pass
# 
# Path: cjktools/resources/dict_format.py
# class RegexFormat(DictionaryFormat):
#     """
#     Describes a dictionary format, by providing regular expressions
#     for the header, the entry lines, and senses within an entry line. The
#     entry line pattern should have named values called 'word', 'reading',
#     and 'senses'.
#     """
# 
#     def __init__(self, name, header_pattern, line_pattern, sense_pattern):
#         self.name = name
#         self.header_pattern = re.compile(header_pattern, re.UNICODE)
#         self.line_pattern = re.compile(line_pattern, re.UNICODE)
#         self.sense_pattern = re.compile(sense_pattern, re.UNICODE)
# 
#     def match_header(self, header_line):
#         return bool(self.header_pattern.match(header_line))
# 
#     def parse_line(self, entry_line):
#         match = self.line_pattern.match(entry_line)
#         if not match:
#             raise FormatError("Bad line: %s" % entry_line)
# 
#         match_dict = match.groupdict()
# 
#         word = match_dict['word'].replace(' ', '')
#         reading = (match_dict.get('reading') or word).replace(' ', '')
#         readings = [reading]
#         sense_line = match_dict.get('senses')
# 
#         senses = []
#         for match in self.sense_pattern.finditer(sense_line):
#             senses.append(match.groupdict()['sense'])
# 
#         if not senses:
#             raise FormatError("No senses for word: %s" % word)
# 
#         return DictionaryEntry(word, readings, senses)


# Path: cjktools/tests/resources/test_bilingual_dict.py
import unittest
from cjktools.resources import bilingual_dict
from cjktools.errors import NotYetImplementedError
from cjktools.resources.dict_format import RegexFormat

    '^.？？？.*$',
    '^(?P<word>[^ ]+) (\[(?P<reading>[^\]]+)\] )?(?P<senses>.*)$',
    '/(?P<sense>[^/]+)'
)


class BilingualDictTest(unittest.TestCase):
    def testUpdateDefaultPolicy(self):
        d1 = bilingual_dict.BilingualDictionary(edict_fmt)

        d1['a'] = 2
        d2 = {'a': 4, 'b': 1}

        d1.update(d2)

        self.assertEqual(d1['a'], 4)
        self.assertEqual(d1['b'], 1)

    def testClashPolicyOverwrite(self):
        d1 = bilingual_dict.BilingualDictionary(edict_fmt)

        d1['a'] = 2
        d2 = {'a': 4, 'b': 1}

        d1.update(d2, clash_policy=bilingual_dict.ClashPolicy.Overwrite)

        self.assertEqual(d1['a'], 4)
        self.assertEqual(d1['b'], 1)

    def testClashPolicyMerge(self):

        d1 = bilingual_dict.BilingualDictionary(edict_fmt)