def test_from_patch(self): self.assertEqual(multiparent.MultiParent( [multiparent.NewText(['a\n']), multiparent.ParentText(0, 1, 2, 3)]), multiparent.MultiParent.from_patch('i 1\na\n\nc 0 1 2 3')) self.assertEqual(multiparent.MultiParent( [multiparent.NewText(['a']), multiparent.ParentText(0, 1, 2, 3)]), multiparent.MultiParent.from_patch('i 1\na\nc 0 1 2 3\n'))
def test_eq(self): diff = multiparent.MultiParent.from_lines(LINES_1) diff2 = multiparent.MultiParent.from_lines(LINES_1) self.assertEqual(diff, diff2) diff3 = multiparent.MultiParent.from_lines(LINES_2) self.assertFalse(diff == diff3) self.assertFalse(diff == Mock(hunks=[multiparent.NewText(LINES_1)])) self.assertEqual(multiparent.MultiParent( [multiparent.NewText(LINES_1), multiparent.ParentText(0, 1, 2, 3)]), multiparent.MultiParent( [multiparent.NewText(LINES_1), multiparent.ParentText(0, 1, 2, 3)]))
def test_to_patch(self): self.assertEqual(['i 1\n', 'a\n', '\n', 'c 0 1 2 3\n'], list( multiparent.MultiParent([ multiparent.NewText(['a\n']), multiparent.ParentText(0, 1, 2, 3) ]).to_patch()))
def test_num_lines(self): mp = multiparent.MultiParent([multiparent.NewText(['a\n'])]) self.assertEqual(1, mp.num_lines()) mp.hunks.append(multiparent.NewText(['b\n', 'c\n'])) self.assertEqual(3, mp.num_lines()) mp.hunks.append(multiparent.ParentText(0, 0, 3, 2)) self.assertEqual(5, mp.num_lines()) mp.hunks.append(multiparent.NewText(['f\n', 'g\n'])) self.assertEqual(7, mp.num_lines())
def test_compute_diffs(self): vf = self.make_three_vf() # The content is in the order requested, even if it isn't topological gen = versionedfile._MPDiffGenerator(vf, [('two', ), ('three', ), ('one', )]) diffs = gen.compute_diffs() expected_diffs = [ multiparent.MultiParent([ multiparent.ParentText(0, 0, 0, 1), multiparent.NewText(['second\n']) ]), multiparent.MultiParent([ multiparent.ParentText(1, 0, 0, 2), multiparent.NewText(['third\n']) ]), multiparent.MultiParent([multiparent.NewText(['first\n'])]), ] self.assertEqual(expected_diffs, diffs)
def test_make_patch_from_binary(self): patch = multiparent.MultiParent.from_texts(''.join(LF_SPLIT_LINES)) expected = multiparent.MultiParent([ multiparent.NewText(LF_SPLIT_LINES)]) self.assertEqual(expected, patch)