def add_equal_contents(stop_line1, stop_line2):
     line_slice1 = LineSlice(current_line1, stop_line1)
     line_slice2 = LineSlice(current_line2, stop_line2)
     text_block1 = self._complete_one_side(document1, line_slice1,
                                           document_model1)
     text_block2 = self._complete_one_side(document2, line_slice2,
                                           document_model2)
     self._link(text_block1, text_block2)
Example #2
0
    def append(self, chunk):
        """Append a chunk."""

        self._chunks.append(chunk)
        if self.slice1 is None:
            self.slice1 = LineSlice(chunk.chunk1.slice)
            self.slice2 = LineSlice(chunk.chunk2.slice)
        else:
            self.slice1 |= chunk.chunk1.slice
            self.slice2 |= chunk.chunk2.slice
    def flat_to_line_slice(self, flat_slice):
        """Convert a flat slice to a line slice and return it."""

        if not bool(flat_slice):
            return LineSlice(0, 0)

        start_line = self.line_of(flat_slice.start)
        if flat_slice:
            upper_line = self.line_of(flat_slice.upper)
        else:
            upper_line = start_line

        return LineSlice(start_line, upper_line + 1)
    def test_document(self):

        sub_string = 'qsdfg\r\nwxcvb\r'
        text_buffer = 'azerty\n' + sub_string + 'azerty\n'
        line_slice = LineSlice(1, 3)
        self._test_text(text_buffer, line_slice, sub_string)
        self._test_text(text_buffer + 'qsdfg', line_slice, sub_string)
        self._test_text(text_buffer[:-1] + '\r\n', line_slice, sub_string)
Example #5
0
    def _process_group(self, file_diff, opcodes):
        """Process a group of contiguous line changes and append the group to the file diff."""

        group = TwoWayGroup()
        for tag, start_1, stop_1, start_2, stop_2 in opcodes:
            slice1 = LineSlice(start_1, stop_1)
            slice2 = LineSlice(start_2, stop_2)
            chunk1 = file_diff.document1[slice1]
            chunk2 = file_diff.document2[slice2]
            if tag == 'equal':
                chunk_diff = TwoWayLineChunkEqual(chunk1, chunk2)
            elif tag == 'delete':
                chunk_diff = TwoWayLineChunkDelete(chunk1, chunk2)
            elif tag == 'insert':
                chunk_diff = TwoWayLineChunkInsert(chunk1, chunk2)
            elif tag == 'replace':
                chunks = self._process_replace_chunk(chunk1, chunk2)
                chunk_diff = TwoWayLineChunkReplace(chunk1, chunk2, chunks)
            group.append(chunk_diff)
        file_diff.append(group)
    def test_view(self):

        text_buffer = ''
        for i in range(10):
            text_buffer += 'azerty' + str(i) + '\n'

        raw_text_document = RawTextDocument(text_buffer)
        view = raw_text_document[LineSlice(1, 3)]
        self.assertEqual(str(view).splitlines(), text_buffer.splitlines()[1:3])
        self.assertEqual(view.substring(FlatSlice(0, 6)), 'azerty')

        text_buffer = "012\n45\n78\n01"
        raw_text_document = RawTextDocument(text_buffer)
        view = raw_text_document[FlatSlice(5, 11)]
        self.assertEqual(
            str(view).splitlines(), [x.strip() for x in view.lines()])