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)
118
141
class InvalidAdd(TestBase):
119
142
"""Try to use invalid version number during add."""
120
143
def runTest(self):
123
self.assertRaises(IndexError,
146
self.assertRaises(ValueError,
152
k.add('text2', [0], ['line 1', 'diverged line'])
174
k.add([0], ['line 1', 'diverged line'])
154
176
self.assertEqual(k.annotate(2),
156
178
(2, 'diverged line')])
158
180
text3 = ['line 1', 'middle line', 'line 2']
163
# self.log("changes to text3: " + pformat(list(k._delta(set([0, 1]), text3))))
184
self.log("changes to text3: " + pformat(list(k._delta(set([0, 1]), text3))))
165
self.log("k._weave=" + pformat(k._weave))
186
self.log("k._l=" + pformat(k._l))
167
188
self.assertEqual(k.annotate(3),
517
534
text0 = ['cheddar', 'stilton', 'gruyere']
518
535
text1 = ['cheddar', 'blue vein', 'neufchatel', 'chevre']
520
k.add('text0', [], text0)
521
k.add('text1', [0], text1)
523
self.log('k._weave=' + pformat(k._weave))
540
self.log('k._l=' + pformat(k._l))
525
542
self.assertEqual(k.get(0), text0)
526
543
self.assertEqual(k.get(1), text1)
538
555
['header', '', 'line from 1', 'fixup line', 'line from 2'],
541
k.add('text0', [], texts[0])
542
k.add('text1', [0], texts[1])
543
k.add('text2', [0], texts[2])
544
k.add('merge', [0, 1, 2], texts[3])
561
k.add([0, 1, 2], texts[3])
546
563
for i, t in enumerate(texts):
547
564
self.assertEqual(k.get(i), t)
609
626
['header', 'aaa', 'bbb', 'line from 2', 'more from 2'],
612
k.add('text0', [], texts[0])
613
k.add('text1', [0], texts[1])
614
k.add('text2', [0], texts[2])
616
self.log('k._weave=' + pformat(k._weave))
633
self.log('k._l=' + pformat(k._l))
618
635
m = list(k.mash_iter([0, 1, 2]))
672
686
self.check_read_write(k)
676
class MergeCases(TestBase):
677
def doMerge(self, base, a, b, mp):
678
from cStringIO import StringIO
679
from textwrap import dedent
685
w.add('text0', [], map(addcrlf, base))
686
w.add('text1', [0], map(addcrlf, a))
687
w.add('text2', [0], map(addcrlf, b))
689
self.log('weave is:')
692
self.log(tmpf.getvalue())
694
self.log('merge plan:')
695
p = list(w.plan_merge(1, 2))
696
for state, line in p:
698
self.log('%12s | %s' % (state, line[:-1]))
702
mt.writelines(w.weave_merge(p))
704
self.log(mt.getvalue())
706
mp = map(addcrlf, mp)
707
self.assertEqual(mt.readlines(), mp)
710
def testOneInsert(self):
716
def testSeparateInserts(self):
717
self.doMerge(['aaa', 'bbb', 'ccc'],
718
['aaa', 'xxx', 'bbb', 'ccc'],
719
['aaa', 'bbb', 'yyy', 'ccc'],
720
['aaa', 'xxx', 'bbb', 'yyy', 'ccc'])
722
def testSameInsert(self):
723
self.doMerge(['aaa', 'bbb', 'ccc'],
724
['aaa', 'xxx', 'bbb', 'ccc'],
725
['aaa', 'xxx', 'bbb', 'yyy', 'ccc'],
726
['aaa', 'xxx', 'bbb', 'yyy', 'ccc'])
728
def testOverlappedInsert(self):
729
self.doMerge(['aaa', 'bbb'],
730
['aaa', 'xxx', 'yyy', 'bbb'],
731
['aaa', 'xxx', 'bbb'],
732
['aaa', '<<<<', 'xxx', 'yyy', '====', 'xxx', '>>>>', 'bbb'])
734
# really it ought to reduce this to
735
# ['aaa', 'xxx', 'yyy', 'bbb']
738
def testClashReplace(self):
739
self.doMerge(['aaa'],
742
['<<<<', 'xxx', '====', 'yyy', 'zzz', '>>>>'])
744
def testNonClashInsert(self):
745
self.doMerge(['aaa'],
748
['<<<<', 'xxx', 'aaa', '====', 'yyy', 'zzz', '>>>>'])
750
self.doMerge(['aaa'],
756
def testDeleteAndModify(self):
757
"""Clashing delete and modification.
759
If one side modifies a region and the other deletes it then
760
there should be a conflict with one side blank.
763
#######################################
764
# skippd, not working yet
767
self.doMerge(['aaa', 'bbb', 'ccc'],
768
['aaa', 'ddd', 'ccc'],
770
['<<<<', 'aaa', '====', '>>>>', 'ccc'])
776
691
from unittest import TestSuite, TestLoader
779
694
tl = TestLoader()
780
695
suite = TestSuite()
781
696
suite.addTest(tl.loadTestsFromModule(testweave))