def test_mapping(self): from ktug_hanyang_pua.models import Mapping lineFormat = self.make_one() line = 'U+1107 U+1107 U+110B => U+112C' parsed = lineFormat.parse(line) self.assertEqual( Mapping((0x1107, 0x1107, 0x110B), (0x112C, ), None), parsed, ) formatted = lineFormat.format(parsed) self.assertEqual( line, formatted, ) line = 'U+F86A =>' parsed = lineFormat.parse(line) self.assertEqual( Mapping((0xF86A, ), (), None), parsed, ) formatted = lineFormat.format(parsed) self.assertEqual( line, formatted, )
def test_format_and_parse_without_comment(self): from ktug_hanyang_pua.models import Mapping from ktug_hanyang_pua.formats import MappingDictFormat dictFormat = MappingDictFormat(comment=False) for index, mapping in enumerate(TABLE.MAPPINGLIST): mapping = Mapping( source=mapping.source[0], target=mapping.target, comment=mapping.comment, ) d = dictFormat.format(mapping) self.assertEqual( TABLE.MAPPINGDICTS_WITHOUT_COMMENT[index], d, ) parsed = dictFormat.parse(d) parsed = Mapping( source=tuple([parsed.source]), target=tuple(parsed.target), comment=parsed.comment, ) self.assertEqual( TABLE.MAPPINGLIST[index], parsed, )
def test_format_and_parse(self): from ktug_hanyang_pua.models import Mapping dictFormat = self.make_one() for index, mapping in enumerate(TABLE.MAPPINGLIST): mapping = Mapping( source=mapping.source[0], target=mapping.target, comment=mapping.comment, ) d = dictFormat.format(mapping) self.assertEqual( TABLE.MAPPINGDICTS[index], d, ) parsed = dictFormat.parse(d) parsed = Mapping( source=tuple([parsed.source]), target=tuple(parsed.target), comment=parsed.comment, ) self.assertEqual( TABLE.MAPPINGLIST[index], parsed, )
def MAPPINGLIST_SWITCHED(self): from ktug_hanyang_pua.models import Mapping return ( Mapping( source=(0x115F, 0x1161, 0x11AE), target=(0xE0BC, ), comment=None, ), Mapping( source=(0x115F, 0x1161, 0xD7CD), target=(0xE0BD, ), comment=None, ), Mapping( source=(0x115F, 0x11A3), target=(0xE0C6, ), comment=None, ), Mapping( source=(0x115F, 0x11A3, 0x11AE), target=(0xE0C7, ), comment=None, ), Mapping( source=(0x115F, 0x1163, 0x11AB), target=(0xE0C8, ), comment=None, ), Mapping( source=(), target=(0xF86A, ), comment=None, ), )
def test_mapping_with_comment(self): from ktug_hanyang_pua.models import Mapping from ktug_hanyang_pua.models import Comment lineFormat = self.make_one() line = 'U+11BC U+11A8 U+11A8 => U+11ED %%% legacy encoding' parsed = lineFormat.parse(line) self.assertEqual( Mapping((0x11BC, 0x11A8, 0x11A8), (0x11ED, ), Comment(' legacy encoding')), parsed) formatted = lineFormat.format(parsed) self.assertEqual( line, formatted, )
def test_build_tree(self): from ktug_hanyang_pua.models import Mapping from ktug_hanyang_pua.formats import IterableFormat from ktug_hanyang_pua.formats import LineFormat from ktug_hanyang_pua.tree import build_tree mappingsFormat = IterableFormat(LineFormat()) mappings = mappingsFormat.parse(TREE.MAPPINGS) mappings = (Mapping( source=m.target, target=m.source[0], comment=None, ) for m in mappings) nodelist, node_childrens = build_tree(mappings) self.assertEqual(TREE.NODELIST, nodelist) self.assertEqual(TREE.NODE_CHILDRENS, node_childrens)