20
20
# TODO: tests regarding version names
21
# TODO: rbc 20050108 test that join does not leave an inconsistent weave
24
24
"""test suite for weave algorithm"""
26
26
from pprint import pformat
28
from bzrlib.weave import Weave, WeaveFormatError, WeaveError
28
import bzrlib.errors as errors
29
from bzrlib.weave import Weave, WeaveFormatError, WeaveError, reweave
29
30
from bzrlib.weavefile import write_weave, read_weave
30
31
from bzrlib.selftest import TestCase
31
32
from bzrlib.osutils import sha_string
752
758
self.doMerge(['aaa', 'bbb'],
753
759
['aaa', 'xxx', 'yyy', 'bbb'],
754
760
['aaa', 'xxx', 'bbb'],
755
['aaa', '<<<<', 'xxx', 'yyy', '====', 'xxx', '>>>>', 'bbb'])
761
['aaa', '<<<<<<<', 'xxx', 'yyy', '=======', 'xxx',
757
764
# really it ought to reduce this to
758
765
# ['aaa', 'xxx', 'yyy', 'bbb']
762
769
self.doMerge(['aaa'],
765
['<<<<', 'xxx', '====', 'yyy', 'zzz', '>>>>'])
772
['<<<<<<<', 'xxx', '=======', 'yyy', 'zzz',
767
775
def testNonClashInsert(self):
768
776
self.doMerge(['aaa'],
771
['<<<<', 'xxx', 'aaa', '====', 'yyy', 'zzz', '>>>>'])
779
['<<<<<<<', 'xxx', 'aaa', '=======', 'yyy', 'zzz',
773
782
self.doMerge(['aaa'],
790
799
self.doMerge(['aaa', 'bbb', 'ccc'],
791
800
['aaa', 'ddd', 'ccc'],
793
['<<<<', 'aaa', '====', '>>>>', 'ccc'])
797
if __name__ == '__main__':
800
sys.exit(unittest.main())
802
['<<<<<<<<', 'aaa', '=======', '>>>>>>>', 'ccc'])
805
class JoinWeavesTests(TestBase):
807
super(JoinWeavesTests, self).setUp()
808
self.weave1 = Weave()
809
self.lines1 = ['hello\n']
810
self.lines3 = ['hello\n', 'cruel\n', 'world\n']
811
self.weave1.add('v1', [], self.lines1)
812
self.weave1.add('v2', [0], ['hello\n', 'world\n'])
813
self.weave1.add('v3', [1], self.lines3)
815
def test_join_empty(self):
816
"""Join two empty weaves."""
817
eq = self.assertEqual
821
eq(w1.numversions(), 0)
823
def test_join_empty_to_nonempty(self):
824
"""Join empty weave onto nonempty."""
825
self.weave1.join(Weave())
826
self.assertEqual(len(self.weave1), 3)
828
def test_join_unrelated(self):
829
"""Join two weaves with no history in common."""
831
wb.add('b1', [], ['line from b\n'])
834
eq = self.assertEqual
836
eq(sorted(list(w1.iter_names())),
837
['b1', 'v1', 'v2', 'v3'])
839
def test_join_related(self):
840
wa = self.weave1.copy()
841
wb = self.weave1.copy()
842
wa.add('a1', ['v3'], ['hello\n', 'sweet\n', 'world\n'])
843
wb.add('b1', ['v3'], ['hello\n', 'pale blue\n', 'world\n'])
844
eq = self.assertEquals
849
eq(wa.get_lines('b1'),
850
['hello\n', 'pale blue\n', 'world\n'])
852
def test_join_parent_disagreement(self):
853
"""Cannot join weaves with different parents for a version."""
856
wa.add('v1', [], ['hello\n'])
858
wb.add('v1', ['v0'], ['hello\n'])
859
self.assertRaises(WeaveError,
862
def test_join_text_disagreement(self):
863
"""Cannot join weaves with different texts for a version."""
866
wa.add('v1', [], ['hello\n'])
867
wb.add('v1', [], ['not\n', 'hello\n'])
868
self.assertRaises(WeaveError,
871
def test_join_unordered(self):
872
"""Join weaves where indexes differ.
874
The source weave contains a different version at index 0."""
875
wa = self.weave1.copy()
877
wb.add('x1', [], ['line from x1\n'])
878
wb.add('v1', [], ['hello\n'])
879
wb.add('v2', ['v1'], ['hello\n', 'world\n'])
881
eq = self.assertEquals
882
eq(sorted(wa.iter_names()), ['v1', 'v2', 'v3', 'x1',])
883
eq(wa.get_text('x1'), 'line from x1\n')