def test_from_style_ranges_single(self): self.assertEqual(str(Command.from_style_ranges({ 'inlineStyleRanges': [ { 'offset': 0, 'length': 4, 'style': 'shazam', } ] })), str([ Command('start_inline_style', 0, 'shazam'), Command('stop_inline_style', 4, 'shazam'), ]))
def build_commands(self, block: Block) -> List[Command]: """ Build all of the manipulation commands for a given block. - One pair to set the text. - Multiple pairs for styles. - Multiple pairs for entities. """ style_commands = Command.from_style_ranges(block) entity_commands = Command.from_entity_ranges(block) styles_and_entities = style_commands + entity_commands styles_and_entities.sort(key=attrgetter("index")) return ([Command("start_text", 0)] + styles_and_entities + [Command("stop_text", len(block["text"]))])
def test_from_style_ranges_single(self): self.assertEqual( str( Command.from_style_ranges({ "inlineStyleRanges": [{ "offset": 0, "length": 4, "style": "shazam" }] })), str([ Command("start_inline_style", 0, "shazam"), Command("stop_inline_style", 4, "shazam"), ]), )
def test_from_style_ranges_multiple(self): self.assertEqual(str(Command.from_style_ranges({ 'inlineStyleRanges': [ { 'offset': 0, 'length': 4, 'style': 'shazam', }, { 'offset': 9, 'length': 3, 'style': 'wazzum', }, ], })), str([ Command('start_inline_style', 0, 'shazam'), Command('stop_inline_style', 4, 'shazam'), Command('start_inline_style', 9, 'wazzum'), Command('stop_inline_style', 12, 'wazzum'), ]))
def test_from_style_ranges_multiple(self): self.assertEqual( str( Command.from_style_ranges({ "inlineStyleRanges": [ { "offset": 0, "length": 4, "style": "shazam" }, { "offset": 9, "length": 3, "style": "wazzum" }, ] })), str([ Command("start_inline_style", 0, "shazam"), Command("stop_inline_style", 4, "shazam"), Command("start_inline_style", 9, "wazzum"), Command("stop_inline_style", 12, "wazzum"), ]), )
def test_from_style_ranges_empty(self): self.assertEqual( str(Command.from_style_ranges({"inlineStyleRanges": []})), str([]))