~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Patch Queue Manager
  • Date: 2012-07-28 20:20:38 UTC
  • mfrom: (6524.5.8 context_in_diffs)
  • Revision ID: pqm@pqm.ubuntu.com-20120728202038-cl923dptn267ve1x
(gz) Add option to specify how much context bzr should use in diffs (Paul
 Nixon)

Show diffs side-by-side

added added

removed removed

Lines of Context:
211
211
        self.assertIsInstance(output.getvalue(), str,
212
212
            'internal_diff should return bytestrings')
213
213
 
 
214
    def test_internal_diff_default_context(self):
 
215
        output = StringIO()
 
216
        diff.internal_diff('old', ['same_text\n','same_text\n','same_text\n',
 
217
                           'same_text\n','same_text\n','old_text\n'],
 
218
                           'new', ['same_text\n','same_text\n','same_text\n',
 
219
                           'same_text\n','same_text\n','new_text\n'], output)
 
220
        lines = output.getvalue().splitlines(True)
 
221
        self.check_patch(lines)
 
222
        self.assertEquals(['--- old\n',
 
223
                           '+++ new\n',
 
224
                           '@@ -3,4 +3,4 @@\n',
 
225
                           ' same_text\n',
 
226
                           ' same_text\n',
 
227
                           ' same_text\n',
 
228
                           '-old_text\n',
 
229
                           '+new_text\n',
 
230
                           '\n',
 
231
                          ]
 
232
                          , lines)
 
233
 
 
234
    def test_internal_diff_no_context(self):
 
235
        output = StringIO()
 
236
        diff.internal_diff('old', ['same_text\n','same_text\n','same_text\n',
 
237
                           'same_text\n','same_text\n','old_text\n'],
 
238
                           'new', ['same_text\n','same_text\n','same_text\n',
 
239
                           'same_text\n','same_text\n','new_text\n'], output,
 
240
                           context_lines=0)
 
241
        lines = output.getvalue().splitlines(True)
 
242
        self.check_patch(lines)
 
243
        self.assertEquals(['--- old\n',
 
244
                           '+++ new\n',
 
245
                           '@@ -6,1 +6,1 @@\n',
 
246
                           '-old_text\n',
 
247
                           '+new_text\n',
 
248
                           '\n',
 
249
                          ]
 
250
                          , lines)
 
251
 
 
252
    def test_internal_diff_more_context(self):
 
253
        output = StringIO()
 
254
        diff.internal_diff('old', ['same_text\n','same_text\n','same_text\n',
 
255
                           'same_text\n','same_text\n','old_text\n'],
 
256
                           'new', ['same_text\n','same_text\n','same_text\n',
 
257
                           'same_text\n','same_text\n','new_text\n'], output,
 
258
                           context_lines=4)
 
259
        lines = output.getvalue().splitlines(True)
 
260
        self.check_patch(lines)
 
261
        self.assertEquals(['--- old\n',
 
262
                           '+++ new\n',
 
263
                           '@@ -2,5 +2,5 @@\n',
 
264
                           ' same_text\n',
 
265
                           ' same_text\n',
 
266
                           ' same_text\n',
 
267
                           ' same_text\n',
 
268
                           '-old_text\n',
 
269
                           '+new_text\n',
 
270
                           '\n',
 
271
                          ]
 
272
                          , lines)
 
273
 
 
274
 
 
275
 
 
276
 
214
277
 
215
278
class TestDiffFiles(tests.TestCaseInTempDir):
216
279