~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_weave.py

  • Committer: Martin Pool
  • Date: 2006-03-24 19:11:33 UTC
  • mto: This revision was merged to the branch mainline in revision 1626.
  • Revision ID: mbp@sourcefrog.net-20060324191133-4f45292db5c5d487
(weave-merge) don't treat killed-both lines as points of agreement; 
makes sure that killed-[ab] lines next to change reasons aren't 
omitted from conflict descriptions.

Add more weave merge tests about line deletion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
781
781
                     ['aaa', 'ccc'],
782
782
                     ['<<<<<<<< ', 'aaa', '=======', '>>>>>>> ', 'ccc'])
783
783
 
 
784
    def _test_merge_from_strings(self, base, a, b, expected):
 
785
        w = Weave()
 
786
        w.add_lines('text0', [], base.splitlines(True))
 
787
        w.add_lines('text1', ['text0'], a.splitlines(True))
 
788
        w.add_lines('text2', ['text0'], b.splitlines(True))
 
789
        self.log('merge plan:')
 
790
        p = list(w.plan_merge('text1', 'text2'))
 
791
        for state, line in p:
 
792
            if line:
 
793
                self.log('%12s | %s' % (state, line[:-1]))
 
794
        self.log('merge result:')
 
795
        result_text = ''.join(w.weave_merge(p))
 
796
        self.log(result_text)
 
797
        self.assertEqualDiff(result_text, expected)
 
798
 
 
799
    def test_deletion_extended(self):
 
800
        """One side deletes, the other deletes more.
 
801
        """
 
802
        base = """\
 
803
            line 1
 
804
            line 2
 
805
            line 3
 
806
            """
 
807
        a = """\
 
808
            line 1
 
809
            line 2
 
810
            """
 
811
        b = """\
 
812
            line 1
 
813
            """
 
814
        result = """\
 
815
            line 1
 
816
            """
 
817
        self._test_merge_from_strings(base, a, b, result)
 
818
 
 
819
    def test_deletion_overlap(self):
 
820
        """Delete overlapping regions with no other conflict.
 
821
 
 
822
        Arguably it'd be better to treat these as agreement, rather than 
 
823
        conflict, but for now conflict is safer.
 
824
        """
 
825
        base = """\
 
826
            start context
 
827
            int a() {}
 
828
            int b() {}
 
829
            int c() {}
 
830
            end context
 
831
            """
 
832
        a = """\
 
833
            start context
 
834
            int a() {}
 
835
            end context
 
836
            """
 
837
        b = """\
 
838
            start context
 
839
            int c() {}
 
840
            end context
 
841
            """
 
842
        result = """\
 
843
            start context
 
844
<<<<<<< 
 
845
            int a() {}
 
846
=======
 
847
            int c() {}
 
848
>>>>>>> 
 
849
            end context
 
850
            """
 
851
        self._test_merge_from_strings(base, a, b, result)
 
852
 
 
853
    def test_agreement_deletion(self):
 
854
        """Agree to delete some lines, without conflicts."""
 
855
        base = """\
 
856
            start context
 
857
            base line 1
 
858
            base line 2
 
859
            end context
 
860
            """
 
861
        a = """\
 
862
            start context
 
863
            base line 1
 
864
            end context
 
865
            """
 
866
        b = """\
 
867
            start context
 
868
            base line 1
 
869
            end context
 
870
            """
 
871
        result = """\
 
872
            start context
 
873
            base line 1
 
874
            end context
 
875
            """
 
876
        self._test_merge_from_strings(base, a, b, result)
 
877
 
 
878
    def test_sync_on_deletion(self):
 
879
        """Specific case of merge where we can synchronize incorrectly.
 
880
        
 
881
        A previous version of the weave merge concluded that the two versions
 
882
        agreed on deleting line 2, and this could be a synchronization point.
 
883
        Line 1 was then considered in isolation, and thought to be deleted on 
 
884
        both sides.
 
885
 
 
886
        It's better to consider the whole thing as a disagreement region.
 
887
        """
 
888
        base = """\
 
889
            start context
 
890
            base line 1
 
891
            base line 2
 
892
            end context
 
893
            """
 
894
        a = """\
 
895
            start context
 
896
            base line 1
 
897
            a's replacement line 2
 
898
            end context
 
899
            """
 
900
        b = """\
 
901
            start context
 
902
            b replaces
 
903
            both lines
 
904
            end context
 
905
            """
 
906
        result = """\
 
907
            start context
 
908
<<<<<<< 
 
909
            base line 1
 
910
            a's replacement line 2
 
911
=======
 
912
            b replaces
 
913
            both lines
 
914
>>>>>>> 
 
915
            end context
 
916
            """
 
917
        self._test_merge_from_strings(base, a, b, result)
 
918
 
784
919
 
785
920
class JoinWeavesTests(TestBase):
786
921
    def setUp(self):
974
1109
        w2.join(w1) # extract 3b to add txt1 
975
1110
 
976
1111
 
977
 
class TestNeedsRweave(TestCase):
 
1112
class TestNeedsReweave(TestCase):
978
1113
    """Internal corner cases for when reweave is needed."""
979
1114
 
980
1115
    def test_compatible_parents(self):
990
1125
        self.assertFalse(w1._compatible_parents(set(), set([1])))
991
1126
        self.assertFalse(w1._compatible_parents(my_parents, set([1, 2, 3, 4])))
992
1127
        self.assertFalse(w1._compatible_parents(my_parents, set([4])))
993
 
        
994