107
107
def test_get_delta(self):
108
108
f = self.get_file()
109
sha1s = self._setup_for_deltas(f)
110
expected_delta = (None, '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False,
111
[(0, 0, 1, [('base', 'line\n')])])
112
self.assertEqual(expected_delta, f.get_delta('base'))
114
text_name = 'chain1-'
115
for depth in range(26):
116
new_version = text_name + '%s' % depth
117
expected_delta = (next_parent, sha1s[depth],
119
[(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
120
self.assertEqual(expected_delta, f.get_delta(new_version))
121
next_parent = new_version
123
text_name = 'chain2-'
124
for depth in range(26):
125
new_version = text_name + '%s' % depth
126
expected_delta = (next_parent, sha1s[depth], False,
127
[(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
128
self.assertEqual(expected_delta, f.get_delta(new_version))
129
next_parent = new_version
130
# smoke test for eol support
131
expected_delta = ('base', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True, [])
132
self.assertEqual(['line'], f.get_lines('noeol'))
133
self.assertEqual(expected_delta, f.get_delta('noeol'))
135
def test_get_deltas(self):
137
sha1s = self._setup_for_deltas(f)
138
deltas = f.get_deltas(f.versions())
139
expected_delta = (None, '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False,
140
[(0, 0, 1, [('base', 'line\n')])])
141
self.assertEqual(expected_delta, deltas['base'])
143
text_name = 'chain1-'
144
for depth in range(26):
145
new_version = text_name + '%s' % depth
146
expected_delta = (next_parent, sha1s[depth],
148
[(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
149
self.assertEqual(expected_delta, deltas[new_version])
150
next_parent = new_version
152
text_name = 'chain2-'
153
for depth in range(26):
154
new_version = text_name + '%s' % depth
155
expected_delta = (next_parent, sha1s[depth], False,
156
[(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
157
self.assertEqual(expected_delta, deltas[new_version])
158
next_parent = new_version
159
# smoke tests for eol support
160
expected_delta = ('base', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True, [])
161
self.assertEqual(['line'], f.get_lines('noeol'))
162
self.assertEqual(expected_delta, deltas['noeol'])
163
# smoke tests for eol support - two noeol in a row same content
164
expected_deltas = (('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True,
165
[(0, 1, 2, [(u'noeolsecond', 'line\n'), (u'noeolsecond', 'line\n')])]),
166
('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True,
167
[(0, 0, 1, [('noeolsecond', 'line\n')]), (1, 1, 0, [])]))
168
self.assertEqual(['line\n', 'line'], f.get_lines('noeolsecond'))
169
self.assertTrue(deltas['noeolsecond'] in expected_deltas)
170
# two no-eol in a row, different content
171
expected_delta = ('noeolsecond', '8bb553a84e019ef1149db082d65f3133b195223b', True,
172
[(1, 2, 1, [(u'noeolnotshared', 'phone\n')])])
173
self.assertEqual(['line\n', 'phone'], f.get_lines('noeolnotshared'))
174
self.assertEqual(expected_delta, deltas['noeolnotshared'])
175
# eol folling a no-eol with content change
176
expected_delta = ('noeol', 'a61f6fb6cfc4596e8d88c34a308d1e724caf8977', False,
177
[(0, 1, 1, [(u'eol', 'phone\n')])])
178
self.assertEqual(['phone\n'], f.get_lines('eol'))
179
self.assertEqual(expected_delta, deltas['eol'])
180
# eol folling a no-eol with content change
181
expected_delta = ('noeol', '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False,
182
[(0, 1, 1, [(u'eolline', 'line\n')])])
183
self.assertEqual(['line\n'], f.get_lines('eolline'))
184
self.assertEqual(expected_delta, deltas['eolline'])
185
# eol with no parents
186
expected_delta = (None, '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
187
[(0, 0, 1, [(u'noeolbase', 'line\n')])])
188
self.assertEqual(['line'], f.get_lines('noeolbase'))
189
self.assertEqual(expected_delta, deltas['noeolbase'])
190
# eol with two parents, in inverse insertion order
191
expected_deltas = (('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
192
[(0, 1, 1, [(u'eolbeforefirstparent', 'line\n')])]),
193
('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
194
[(0, 1, 1, [(u'eolbeforefirstparent', 'line\n')])]))
195
self.assertEqual(['line'], f.get_lines('eolbeforefirstparent'))
196
#self.assertTrue(deltas['eolbeforefirstparent'] in expected_deltas)
198
def _setup_for_deltas(self, f):
109
199
self.assertRaises(errors.RevisionNotPresent, f.get_delta, 'base')
110
200
# add texts that should trip the knit maximum delta chain threshold
111
201
# as well as doing parallel chains of data in knits.
112
202
# this is done by two chains of 25 insertions
113
203
f.add_lines('base', [], ['line\n'])
204
f.add_lines('noeol', ['base'], ['line'])
205
# detailed eol tests:
206
# shared last line with parent no-eol
207
f.add_lines('noeolsecond', ['noeol'], ['line\n', 'line'])
208
# differing last line with parent, both no-eol
209
f.add_lines('noeolnotshared', ['noeolsecond'], ['line\n', 'phone'])
210
# add eol following a noneol parent, change content
211
f.add_lines('eol', ['noeol'], ['phone\n'])
212
# add eol following a noneol parent, no change content
213
f.add_lines('eolline', ['noeol'], ['line\n'])
214
# noeol with no parents:
215
f.add_lines('noeolbase', [], ['line'])
216
# noeol preceeding its leftmost parent in the output:
217
# this is done by making it a merge of two parents with no common
218
# anestry: noeolbase and noeol with the
219
# later-inserted parent the leftmost.
220
f.add_lines('eolbeforefirstparent', ['noeolbase', 'noeol'], ['line'])
221
# two identical eol texts
222
f.add_lines('noeoldup', ['noeol'], ['line'])
114
223
next_parent = 'base'
115
224
text_name = 'chain1-'
116
225
text = ['line\n']
154
263
text = text + ['line\n']
155
264
f.add_lines(new_version, [next_parent], text)
156
265
next_parent = new_version
157
f.add_lines('noeol', ['base'], ['line'])
158
expected_delta = (None, '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False,
159
[(0, 0, 1, [('base', 'line\n')])])
160
self.assertEqual(expected_delta, f.get_delta('base'))
162
next_name = 'chain1-'
163
for depth in range(26):
164
new_version = text_name + '%s' % depth
165
expected_delta = (next_parent, sha1s[depth],
167
[(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
168
self.assertEqual(expected_delta, f.get_delta(new_version))
169
next_parent = new_version
171
next_name = 'chain2-'
172
for depth in range(26):
173
new_version = text_name + '%s' % depth
174
expected_delta = (next_parent, sha1s[depth], False,
175
[(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
176
self.assertEqual(expected_delta, f.get_delta(new_version))
177
next_parent = new_version
178
# smoke test for eol support
179
expected_delta = ('base', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True, [])
180
self.assertEqual(['line'], f.get_lines('noeol'))
181
self.assertEqual(expected_delta, f.get_delta('noeol'))
183
268
def test_add_delta(self):
184
269
# tests for the add-delta facility.