109
class DeltaAdd(TestBase):
110
"""Detection of changes prior to inserting new revision."""
113
k.add([], ['line 1'])
115
self.assertEqual(k._l,
121
changes = list(k._delta(set([0]),
125
self.log('raw changes: ' + pformat(changes))
127
# currently there are 3 lines in the weave, and we insert after them
128
self.assertEquals(changes,
129
[(3, 3, ['new line'])])
131
changes = k._delta(set([0]),
135
self.assertEquals(list(changes),
136
[(1, 1, ['top line'])])
138
self.check_read_write(k)
108
141
class InvalidAdd(TestBase):
109
142
"""Try to use invalid version number during add."""
110
143
def runTest(self):
653
674
self.check_read_write(k)
657
class MergeCases(TestBase):
658
def doMerge(self, base, a, b, mp):
659
from cStringIO import StringIO
660
from textwrap import dedent
666
w.add([], map(addcrlf, base))
667
w.add([0], map(addcrlf, a))
668
w.add([0], map(addcrlf, b))
670
self.log('weave is:')
673
self.log(tmpf.getvalue())
675
self.log('merge plan:')
676
p = list(w.plan_merge(1, 2))
677
for state, line in p:
679
self.log('%12s | %s' % (state, line[:-1]))
683
mt.writelines(w.weave_merge(p))
685
self.log(mt.getvalue())
687
mp = map(addcrlf, mp)
688
self.assertEqual(mt.readlines(), mp)
691
def testOneInsert(self):
697
def testSeparateInserts(self):
698
self.doMerge(['aaa', 'bbb', 'ccc'],
699
['aaa', 'xxx', 'bbb', 'ccc'],
700
['aaa', 'bbb', 'yyy', 'ccc'],
701
['aaa', 'xxx', 'bbb', 'yyy', 'ccc'])
703
def testSameInsert(self):
704
self.doMerge(['aaa', 'bbb', 'ccc'],
705
['aaa', 'xxx', 'bbb', 'ccc'],
706
['aaa', 'xxx', 'bbb', 'yyy', 'ccc'],
707
['aaa', 'xxx', 'bbb', 'yyy', 'ccc'])
709
def testOverlappedInsert(self):
710
self.doMerge(['aaa', 'bbb'],
711
['aaa', 'xxx', 'yyy', 'bbb'],
712
['aaa', 'xxx', 'bbb'],
713
['aaa', '<<<<', 'xxx', 'yyy', '====', 'xxx', '>>>>', 'bbb'])
715
# really it ought to reduce this to
716
# ['aaa', 'xxx', 'yyy', 'bbb']
719
def testClashReplace(self):
720
self.doMerge(['aaa'],
723
['<<<<', 'xxx', '====', 'yyy', 'zzz', '>>>>'])
725
def testNonClashInsert(self):
726
self.doMerge(['aaa'],
729
['<<<<', 'xxx', 'aaa', '====', 'yyy', 'zzz', '>>>>'])
731
self.doMerge(['aaa'],
737
def testDeleteAndModify(self):
738
"""Clashing delete and modification.
740
If one side modifies a region and the other deletes it then
741
there should be a conflict with one side blank.
744
#######################################
745
# skippd, not working yet
748
self.doMerge(['aaa', 'bbb', 'ccc'],
749
['aaa', 'ddd', 'ccc'],
751
['<<<<', 'aaa', '====', '>>>>', 'ccc'])
757
679
from unittest import TestSuite, TestLoader
760
682
tl = TestLoader()
761
683
suite = TestSuite()
762
684
suite.addTest(tl.loadTestsFromModule(testweave))