Пример #1
0
 def test_only_removals(self):
     q1 = deque([1, 2])
     q2 = deque([])
     lcs_marker = ()
     expected_diff_block = diff.DiffBlock([
         diff.DiffItem(diff.remove, 1, (0, 1, 0, 0)),
         diff.DiffItem(diff.remove, 2, (1, 2, 0, 0))
     ])
     db_factory = diff._create_diff_blocks(q1, q2, lcs_marker)
     self.assertEqual(next(db_factory), expected_diff_block)
Пример #2
0
 def test_some_changes_after_an_unchanged_item(self):
     q1 = deque([0, 1, 2])
     q2 = deque([0, 3, 4])
     lcs_marker = ((0, 0),)
     expected_diff_block = diff.DiffBlock([
         diff.DiffItem(diff.unchanged, 0, (0, 1, 0, 1)),
         diff.DiffItem(diff.remove, 1, (1, 2, 1, 1)),
         diff.DiffItem(diff.remove, 2, (2, 3, 1, 1)),
         diff.DiffItem(diff.insert, 3, (3, 3, 1, 2)),
         diff.DiffItem(diff.insert, 4, (3, 3, 2, 3))
     ])
     db_factory = diff._create_diff_blocks(q1, q2, lcs_marker)
     self.assertEqual(next(db_factory), expected_diff_block)
Пример #3
0
 def test_only_unchanged(self):
     q1 = deque([1, 2])
     q2 = deque([1, 2])
     lcs_markers = ((1, 1), (0, 0))
     expected_diff_block_1 = diff.DiffBlock([
         diff.DiffItem(diff.unchanged, 2, (1, 2, 1, 2))
     ])
     expected_diff_block_2 = diff.DiffBlock([
         diff.DiffItem(diff.unchanged, 1, (0, 1, 0, 1))
     ])
     db_factory = diff._create_diff_blocks(q1, q2, lcs_markers)
     self.assertEqual(next(db_factory), expected_diff_block_1)
     self.assertEqual(next(db_factory), expected_diff_block_2)
Пример #4
0
 def test_changes_before_the_first_unchanged_item(self):
     q1 = deque([1, 4])
     q2 = deque([2, 4])
     lcs_markers = ((1, 1),)
     expected_diff_block_1 = diff.DiffBlock([
         diff.DiffItem(diff.unchanged, 4, (1, 2, 1, 2))
     ])
     expected_diff_block_2 = diff.DiffBlock([
         diff.DiffItem(diff.remove, 1, (0, 1, 0, 0)),
         diff.DiffItem(diff.insert, 2, (1, 1, 0, 1)),
     ])
     db_factory = diff._create_diff_blocks(q1, q2, lcs_markers)
     self.assertEqual(next(db_factory), expected_diff_block_1)
     self.assertEqual(next(db_factory), expected_diff_block_2)
Пример #5
0
 def test_empty_diff_block(self):
     db_factory = diff._create_diff_blocks(deque([]), deque([]), ())
     self.assertEqual(next(db_factory), diff.DiffBlock())