168
162
self.assertRaises(errors.ReservedId,
169
163
vf.add_lines, 'a:', [], ['a\n', 'b\n', 'c\n'])
171
self.assertRaises(errors.ReservedId,
172
vf.add_delta, 'a:', [], None, 'sha1', False, ((0, 0, 0, []),))
165
def test_add_lines_nostoresha(self):
166
"""When nostore_sha is supplied using old content raises."""
168
empty_text = ('a', [])
169
sample_text_nl = ('b', ["foo\n", "bar\n"])
170
sample_text_no_nl = ('c', ["foo\n", "bar"])
172
for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
173
sha, _, _ = vf.add_lines(version, [], lines)
175
# we now have a copy of all the lines in the vf.
176
for sha, (version, lines) in zip(
177
shas, (empty_text, sample_text_nl, sample_text_no_nl)):
178
self.assertRaises(errors.ExistingContent,
179
vf.add_lines, version + "2", [], lines,
181
# and no new version should have been added.
182
self.assertRaises(errors.RevisionNotPresent, vf.get_lines,
185
def test_add_lines_with_ghosts_nostoresha(self):
186
"""When nostore_sha is supplied using old content raises."""
188
empty_text = ('a', [])
189
sample_text_nl = ('b', ["foo\n", "bar\n"])
190
sample_text_no_nl = ('c', ["foo\n", "bar"])
192
for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
193
sha, _, _ = vf.add_lines(version, [], lines)
195
# we now have a copy of all the lines in the vf.
196
# is the test applicable to this vf implementation?
198
vf.add_lines_with_ghosts('d', [], [])
199
except NotImplementedError:
200
raise TestSkipped("add_lines_with_ghosts is optional")
201
for sha, (version, lines) in zip(
202
shas, (empty_text, sample_text_nl, sample_text_no_nl)):
203
self.assertRaises(errors.ExistingContent,
204
vf.add_lines_with_ghosts, version + "2", [], lines,
206
# and no new version should have been added.
207
self.assertRaises(errors.RevisionNotPresent, vf.get_lines,
210
def test_add_lines_return_value(self):
211
# add_lines should return the sha1 and the text size.
213
empty_text = ('a', [])
214
sample_text_nl = ('b', ["foo\n", "bar\n"])
215
sample_text_no_nl = ('c', ["foo\n", "bar"])
216
# check results for the three cases:
217
for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
218
# the first two elements are the same for all versioned files:
219
# - the digest and the size of the text. For some versioned files
220
# additional data is returned in additional tuple elements.
221
result = vf.add_lines(version, [], lines)
222
self.assertEqual(3, len(result))
223
self.assertEqual((osutils.sha_strings(lines), sum(map(len, lines))),
225
# parents should not affect the result:
226
lines = sample_text_nl[1]
227
self.assertEqual((osutils.sha_strings(lines), sum(map(len, lines))),
228
vf.add_lines('d', ['b', 'c'], lines)[0:2])
174
230
def test_get_reserved(self):
175
231
vf = self.get_file()
176
self.assertRaises(errors.ReservedId, vf.get_delta, 'b:')
177
232
self.assertRaises(errors.ReservedId, vf.get_texts, ['b:'])
178
233
self.assertRaises(errors.ReservedId, vf.get_lines, 'b:')
179
234
self.assertRaises(errors.ReservedId, vf.get_text, 'b:')
181
def test_get_delta(self):
183
sha1s = self._setup_for_deltas(f)
184
expected_delta = (None, '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False,
185
[(0, 0, 1, [('base', 'line\n')])])
186
self.assertEqual(expected_delta, f.get_delta('base'))
188
text_name = 'chain1-'
189
for depth in range(26):
190
new_version = text_name + '%s' % depth
191
expected_delta = (next_parent, sha1s[depth],
193
[(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
194
self.assertEqual(expected_delta, f.get_delta(new_version))
195
next_parent = new_version
197
text_name = 'chain2-'
198
for depth in range(26):
199
new_version = text_name + '%s' % depth
200
expected_delta = (next_parent, sha1s[depth], False,
201
[(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
202
self.assertEqual(expected_delta, f.get_delta(new_version))
203
next_parent = new_version
204
# smoke test for eol support
205
expected_delta = ('base', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True, [])
206
self.assertEqual(['line'], f.get_lines('noeol'))
207
self.assertEqual(expected_delta, f.get_delta('noeol'))
209
def test_get_deltas(self):
211
sha1s = self._setup_for_deltas(f)
212
deltas = f.get_deltas(f.versions())
213
expected_delta = (None, '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False,
214
[(0, 0, 1, [('base', 'line\n')])])
215
self.assertEqual(expected_delta, deltas['base'])
217
text_name = 'chain1-'
218
for depth in range(26):
219
new_version = text_name + '%s' % depth
220
expected_delta = (next_parent, sha1s[depth],
222
[(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
223
self.assertEqual(expected_delta, deltas[new_version])
224
next_parent = new_version
226
text_name = 'chain2-'
227
for depth in range(26):
228
new_version = text_name + '%s' % depth
229
expected_delta = (next_parent, sha1s[depth], False,
230
[(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
231
self.assertEqual(expected_delta, deltas[new_version])
232
next_parent = new_version
233
# smoke tests for eol support
234
expected_delta = ('base', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True, [])
235
self.assertEqual(['line'], f.get_lines('noeol'))
236
self.assertEqual(expected_delta, deltas['noeol'])
237
# smoke tests for eol support - two noeol in a row same content
238
expected_deltas = (('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True,
239
[(0, 1, 2, [('noeolsecond', 'line\n'), ('noeolsecond', 'line\n')])]),
240
('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True,
241
[(0, 0, 1, [('noeolsecond', 'line\n')]), (1, 1, 0, [])]))
242
self.assertEqual(['line\n', 'line'], f.get_lines('noeolsecond'))
243
self.assertTrue(deltas['noeolsecond'] in expected_deltas)
244
# two no-eol in a row, different content
245
expected_delta = ('noeolsecond', '8bb553a84e019ef1149db082d65f3133b195223b', True,
246
[(1, 2, 1, [('noeolnotshared', 'phone\n')])])
247
self.assertEqual(['line\n', 'phone'], f.get_lines('noeolnotshared'))
248
self.assertEqual(expected_delta, deltas['noeolnotshared'])
249
# eol folling a no-eol with content change
250
expected_delta = ('noeol', 'a61f6fb6cfc4596e8d88c34a308d1e724caf8977', False,
251
[(0, 1, 1, [('eol', 'phone\n')])])
252
self.assertEqual(['phone\n'], f.get_lines('eol'))
253
self.assertEqual(expected_delta, deltas['eol'])
254
# eol folling a no-eol with content change
255
expected_delta = ('noeol', '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False,
256
[(0, 1, 1, [('eolline', 'line\n')])])
257
self.assertEqual(['line\n'], f.get_lines('eolline'))
258
self.assertEqual(expected_delta, deltas['eolline'])
259
# eol with no parents
260
expected_delta = (None, '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
261
[(0, 0, 1, [('noeolbase', 'line\n')])])
262
self.assertEqual(['line'], f.get_lines('noeolbase'))
263
self.assertEqual(expected_delta, deltas['noeolbase'])
264
# eol with two parents, in inverse insertion order
265
expected_deltas = (('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
266
[(0, 1, 1, [('eolbeforefirstparent', 'line\n')])]),
267
('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
268
[(0, 1, 1, [('eolbeforefirstparent', 'line\n')])]))
269
self.assertEqual(['line'], f.get_lines('eolbeforefirstparent'))
270
#self.assertTrue(deltas['eolbeforefirstparent'] in expected_deltas)
272
236
def test_make_mpdiffs(self):
273
237
from bzrlib import multiparent
274
238
vf = self.get_file('foo')