def __init__(self, tip_line, diff_lines, ignore): self.tip_line = tip_line self.reallines = diff_lines if not ignore and len(diff_lines) < RE_HUNK_LIMIT: self.diff_lines = rehunk(diff_lines) else: self.diff_lines = diff_lines
def side_lines(self): old, new = self._start_line_numbers() result = [] result.append(( '...', 'normal', self.tip_line, '...', 'normal', self.tip_line)) type_ = {'emp': 'normal', 'normal': 'normal', 'add': 'insertion', 'rem': 'deletion'} for l, r in rehunk(self.reallines, True): # side hunk l_type = l[1] r_type = r[1] disp_old = str(old) if l_type != 'emp' else ' ' disp_new = str(new) if r_type != 'emp' else ' ' result.append((disp_old, type_.get(l_type), l[2], disp_new, type_.get(r_type), r[2])) if l_type != 'emp': old += 1 if r_type != 'emp': new += 1 return result
def test_hunk(self): hunk = rehunk(a_hunk) assert hunk == [ ('idem', u' /* highlight style */'), ('rem', u'-.highlight { color: #008000; font-weight: bold; } /* Keyword */' ), ('add', u'+.highlight .hll { background-color: #ffffcc; }'), ('add', u'+.highlight { background: #ffffff; }'), ('add', u'+.highlight .c { color: #808080; } /* Comment */'), ('add', u'+.highlight .err { color: #F00000; background-color: #F0A0A0; } /* Error */' ), ('add', u'+.highlight \x00+.k \x01{ color: #008000; font-weight: bold; } /* Keyword */' ), ('idem', u' .highlight .o { color: #303030; } /* Operator */'), ('idem', u' .highlight .cm { color: #808080; } /* Comment.Multiline */'), ('idem', u' .highlight .cp { color: #507090; } /* Comment.Preproc */') ] # noqa
def side_lines(self): old, new = self._start_line_numbers() result = [] result.append( ('...', 'normal', self.tip_line, '...', 'normal', self.tip_line)) type_ = { 'emp': 'normal', 'normal': 'normal', 'add': 'insertion', 'rem': 'deletion' } for l, r in rehunk(self.reallines, True): # side hunk l_type = l[1] r_type = r[1] disp_old = str(old) if l_type != 'emp' else ' ' disp_new = str(new) if r_type != 'emp' else ' ' result.append((disp_old, type_.get(l_type), l[2], disp_new, type_.get(r_type), r[2])) if l_type != 'emp': old += 1 if r_type != 'emp': new += 1 return result
def test_hunk(self): hunk = rehunk(a_hunk) assert hunk == [('idem', u' /* highlight style */'), ('rem', u'-.highlight { color: #008000; font-weight: bold; } /* Keyword */'), ('add', u'+.highlight .hll { background-color: #ffffcc; }'), ('add', u'+.highlight { background: #ffffff; }'), ('add', u'+.highlight .c { color: #808080; } /* Comment */'), ('add', u'+.highlight .err { color: #F00000; background-color: #F0A0A0; } /* Error */'), ('add', u'+.highlight \x00+.k \x01{ color: #008000; font-weight: bold; } /* Keyword */'), ('idem', u' .highlight .o { color: #303030; } /* Operator */'), ('idem', u' .highlight .cm { color: #808080; } /* Comment.Multiline */'), ('idem', u' .highlight .cp { color: #507090; } /* Comment.Preproc */')] # noqa