140
140
except NotImplementedError:
143
def test_add_reserved(self):
145
self.assertRaises(errors.ReservedId,
146
vf.add_lines, 'a:', [], ['a\n', 'b\n', 'c\n'])
148
self.assertRaises(errors.ReservedId,
149
vf.add_delta, 'a:', [], None, 'sha1', False, ((0, 0, 0, []),))
151
def test_get_reserved(self):
153
self.assertRaises(errors.ReservedId, vf.get_delta, 'b:')
154
self.assertRaises(errors.ReservedId, vf.get_texts, ['b:'])
155
self.assertRaises(errors.ReservedId, vf.get_lines, 'b:')
156
self.assertRaises(errors.ReservedId, vf.get_text, 'b:')
158
143
def test_get_delta(self):
159
144
f = self.get_file()
160
145
sha1s = self._setup_for_deltas(f)
213
198
self.assertEqual(expected_delta, deltas['noeol'])
214
199
# smoke tests for eol support - two noeol in a row same content
215
200
expected_deltas = (('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True,
216
[(0, 1, 2, [('noeolsecond', 'line\n'), ('noeolsecond', 'line\n')])]),
201
[(0, 1, 2, [(u'noeolsecond', 'line\n'), (u'noeolsecond', 'line\n')])]),
217
202
('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True,
218
203
[(0, 0, 1, [('noeolsecond', 'line\n')]), (1, 1, 0, [])]))
219
204
self.assertEqual(['line\n', 'line'], f.get_lines('noeolsecond'))
220
205
self.assertTrue(deltas['noeolsecond'] in expected_deltas)
221
206
# two no-eol in a row, different content
222
207
expected_delta = ('noeolsecond', '8bb553a84e019ef1149db082d65f3133b195223b', True,
223
[(1, 2, 1, [('noeolnotshared', 'phone\n')])])
208
[(1, 2, 1, [(u'noeolnotshared', 'phone\n')])])
224
209
self.assertEqual(['line\n', 'phone'], f.get_lines('noeolnotshared'))
225
210
self.assertEqual(expected_delta, deltas['noeolnotshared'])
226
211
# eol folling a no-eol with content change
227
212
expected_delta = ('noeol', 'a61f6fb6cfc4596e8d88c34a308d1e724caf8977', False,
228
[(0, 1, 1, [('eol', 'phone\n')])])
213
[(0, 1, 1, [(u'eol', 'phone\n')])])
229
214
self.assertEqual(['phone\n'], f.get_lines('eol'))
230
215
self.assertEqual(expected_delta, deltas['eol'])
231
216
# eol folling a no-eol with content change
232
217
expected_delta = ('noeol', '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False,
233
[(0, 1, 1, [('eolline', 'line\n')])])
218
[(0, 1, 1, [(u'eolline', 'line\n')])])
234
219
self.assertEqual(['line\n'], f.get_lines('eolline'))
235
220
self.assertEqual(expected_delta, deltas['eolline'])
236
221
# eol with no parents
237
222
expected_delta = (None, '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
238
[(0, 0, 1, [('noeolbase', 'line\n')])])
223
[(0, 0, 1, [(u'noeolbase', 'line\n')])])
239
224
self.assertEqual(['line'], f.get_lines('noeolbase'))
240
225
self.assertEqual(expected_delta, deltas['noeolbase'])
241
226
# eol with two parents, in inverse insertion order
242
227
expected_deltas = (('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
243
[(0, 1, 1, [('eolbeforefirstparent', 'line\n')])]),
228
[(0, 1, 1, [(u'eolbeforefirstparent', 'line\n')])]),
244
229
('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
245
[(0, 1, 1, [('eolbeforefirstparent', 'line\n')])]))
230
[(0, 1, 1, [(u'eolbeforefirstparent', 'line\n')])]))
246
231
self.assertEqual(['line'], f.get_lines('eolbeforefirstparent'))
247
232
#self.assertTrue(deltas['eolbeforefirstparent'] in expected_deltas)
684
666
# test key graph related apis: getncestry, _graph, get_parents
686
668
# - these are ghost unaware and must not be reflect ghosts
687
self.assertEqual(['notbxbfse'], vf.get_ancestry('notbxbfse'))
688
self.assertEqual([], vf.get_parents('notbxbfse'))
689
self.assertEqual({'notbxbfse':[]}, vf.get_graph())
690
self.assertFalse(vf.has_version(parent_id_unicode))
691
self.assertFalse(vf.has_version(parent_id_utf8))
669
self.assertEqual([u'notbxbfse'], vf.get_ancestry(u'notbxbfse'))
670
self.assertEqual([], vf.get_parents(u'notbxbfse'))
671
self.assertEqual({u'notbxbfse':[]}, vf.get_graph())
672
self.assertFalse(vf.has_version(u'b\xbfse'))
692
673
# we have _with_ghost apis to give us ghost information.
693
self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry_with_ghosts(['notbxbfse']))
694
self.assertEqual([parent_id_utf8], vf.get_parents_with_ghosts('notbxbfse'))
695
self.assertEqual({'notbxbfse':[parent_id_utf8]}, vf.get_graph_with_ghosts())
696
self.assertTrue(vf.has_ghost(parent_id_unicode))
697
self.assertTrue(vf.has_ghost(parent_id_utf8))
674
self.assertEqual([u'b\xbfse', u'notbxbfse'], vf.get_ancestry_with_ghosts([u'notbxbfse']))
675
self.assertEqual([u'b\xbfse'], vf.get_parents_with_ghosts(u'notbxbfse'))
676
self.assertEqual({u'notbxbfse':[u'b\xbfse']}, vf.get_graph_with_ghosts())
677
self.assertTrue(vf.has_ghost(u'b\xbfse'))
698
678
# if we add something that is a ghost of another, it should correct the
699
679
# results of the prior apis
700
vf.add_lines(parent_id_unicode, [], [])
701
self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry(['notbxbfse']))
702
self.assertEqual([parent_id_utf8], vf.get_parents('notbxbfse'))
703
self.assertEqual({parent_id_utf8:[],
704
'notbxbfse':[parent_id_utf8],
680
vf.add_lines(u'b\xbfse', [], [])
681
self.assertEqual([u'b\xbfse', u'notbxbfse'], vf.get_ancestry([u'notbxbfse']))
682
self.assertEqual([u'b\xbfse'], vf.get_parents(u'notbxbfse'))
683
self.assertEqual({u'b\xbfse':[],
684
u'notbxbfse':[u'b\xbfse'],
707
self.assertTrue(vf.has_version(parent_id_unicode))
708
self.assertTrue(vf.has_version(parent_id_utf8))
687
self.assertTrue(vf.has_version(u'b\xbfse'))
709
688
# we have _with_ghost apis to give us ghost information.
710
self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry_with_ghosts(['notbxbfse']))
711
self.assertEqual([parent_id_utf8], vf.get_parents_with_ghosts('notbxbfse'))
712
self.assertEqual({parent_id_utf8:[],
713
'notbxbfse':[parent_id_utf8],
689
self.assertEqual([u'b\xbfse', u'notbxbfse'], vf.get_ancestry_with_ghosts([u'notbxbfse']))
690
self.assertEqual([u'b\xbfse'], vf.get_parents_with_ghosts(u'notbxbfse'))
691
self.assertEqual({u'b\xbfse':[],
692
u'notbxbfse':[u'b\xbfse'],
715
694
vf.get_graph_with_ghosts())
716
self.assertFalse(vf.has_ghost(parent_id_unicode))
717
self.assertFalse(vf.has_ghost(parent_id_utf8))
695
self.assertFalse(vf.has_ghost(u'b\xbfse'))
719
697
def test_add_lines_with_ghosts_after_normal_revs(self):
720
698
# some versioned file formats allow lines to be added with parent