def _local_text_changes(lhs, rhs): """Account for only text changes between nodes. This explicitly excludes children""" if lhs.text != rhs.text or lhs.title != rhs.title: node_changes = {"op": MODIFIED} text_opcodes = get_opcodes(lhs.text, rhs.text) if text_opcodes: node_changes["text"] = text_opcodes title_opcodes = get_opcodes(lhs.title, rhs.title) if title_opcodes: node_changes["title"] = title_opcodes return (lhs.label_id, node_changes)
def test_getopcodes(self): old = 'I have a string to change' new = 'We have a string to change now' codes = difftext.get_opcodes(old, new) self.assertEquals( [ [('delete', 0, 1), ('insert', 0, 'We')], ('insert', 25, ' now')], codes)
def _local_text_changes(lhs, rhs): """Account for only text changes between nodes. This explicitly excludes children""" l_text, r_text, l_title, r_title = [ _whitespace.sub(' ', text) for text in (lhs.text, rhs.text, lhs.title, rhs.title)] if l_text != r_text or l_title != r_title: node_changes = {"op": MODIFIED} text_opcodes = get_opcodes(l_text, r_text) if text_opcodes: node_changes["text"] = text_opcodes title_opcodes = get_opcodes(l_title, r_title) if title_opcodes: node_changes["title"] = title_opcodes return (lhs.label_id, node_changes)
def test_ins_opcodes_trailing_space(self): old = 'Howdy howdy. ' new = 'Howdy howdy. More content' codes = difftext.get_opcodes(old, new) self.assertEquals( [('insert', 13, 'More content')], codes)
def test_del_opcodes_middle(self): old = "I have a string to change" new = 'I have a change' codes = difftext.get_opcodes(old, new) self.assertEquals( [('delete', 9, 19)], codes)
def test_del_opcodes(self): old = "I have a string to change" new = 'have a string to change' codes = difftext.get_opcodes(old, new) self.assertEquals( [('delete', 0, 2)], codes)
def test_ins_opcodes(self): old = "I a string to change" new = "I have a string to change" codes = difftext.get_opcodes(old, new) self.assertEquals( [('insert', 2, 'have ')], codes)
def test_getopcodes(self): old = 'I have a string to change' new = 'We have a string to change now' codes = difftext.get_opcodes(old, new) self.assertEquals([[('delete', 0, 1), ('insert', 0, 'We')], ('insert', 25, ' now')], codes)
def test_ins_opcodes_trailing_space(self): old = 'Howdy howdy. ' new = 'Howdy howdy. More content' codes = difftext.get_opcodes(old, new) self.assertEquals([('insert', 13, 'More content')], codes)
def test_del_opcodes_middle(self): old = "I have a string to change" new = 'I have a change' codes = difftext.get_opcodes(old, new) self.assertEquals([('delete', 9, 19)], codes)
def test_del_opcodes(self): old = "I have a string to change" new = 'have a string to change' codes = difftext.get_opcodes(old, new) self.assertEquals([('delete', 0, 2)], codes)
def test_ins_opcodes(self): old = "I a string to change" new = "I have a string to change" codes = difftext.get_opcodes(old, new) self.assertEquals([('insert', 2, 'have ')], codes)