/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Michael Ellerman
  • Date: 2006-03-09 00:24:48 UTC
  • mto: (1610.1.8 bzr.mbp.integration)
  • mto: This revision was merged to the branch mainline in revision 1616.
  • Revision ID: michael@ellerman.id.au-20060309002448-70cce15e3d605130
Make the "ignore line" in the commit message editor the "right" width, so
that if you make your message that wide it won't wrap in bzr log output.
Just as a visual aid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from bzrlib.tests import TestCase
 
2
from bzrlib.diff import internal_diff
 
3
from cStringIO import StringIO
 
4
def udiff_lines(old, new):
 
5
    output = StringIO()
 
6
    internal_diff('old', old, 'new', new, output)
 
7
    output.seek(0, 0)
 
8
    return output.readlines()
 
9
 
 
10
class TestDiff(TestCase):
 
11
    def test_add_nl(self):
 
12
        """diff generates a valid diff for patches that add a newline"""
 
13
        lines = udiff_lines(['boo'], ['boo\n'])
 
14
        self.check_patch(lines)
 
15
        self.assertEquals(lines[4], '\\ No newline at end of file\n')
 
16
            ## "expected no-nl, got %r" % lines[4]
 
17
 
 
18
    def test_add_nl_2(self):
 
19
        """diff generates a valid diff for patches that change last line and
 
20
        add a newline.
 
21
        """
 
22
        lines = udiff_lines(['boo'], ['goo\n'])
 
23
        self.check_patch(lines)
 
24
        self.assertEquals(lines[4], '\\ No newline at end of file\n')
 
25
            ## "expected no-nl, got %r" % lines[4]
 
26
 
 
27
    def test_remove_nl(self):
 
28
        """diff generates a valid diff for patches that change last line and
 
29
        add a newline.
 
30
        """
 
31
        lines = udiff_lines(['boo\n'], ['boo'])
 
32
        self.check_patch(lines)
 
33
        self.assertEquals(lines[5], '\\ No newline at end of file\n')
 
34
            ## "expected no-nl, got %r" % lines[5]
 
35
 
 
36
    def check_patch(self, lines):
 
37
        self.assert_(len(lines) > 1)
 
38
            ## "Not enough lines for a file header for patch:\n%s" % "".join(lines)
 
39
        self.assert_(lines[0].startswith ('---'))
 
40
            ## 'No orig line for patch:\n%s' % "".join(lines)
 
41
        self.assert_(lines[1].startswith ('+++'))
 
42
            ## 'No mod line for patch:\n%s' % "".join(lines)
 
43
        self.assert_(len(lines) > 2)
 
44
            ## "No hunks for patch:\n%s" % "".join(lines)
 
45
        self.assert_(lines[2].startswith('@@'))
 
46
            ## "No hunk header for patch:\n%s" % "".join(lines)
 
47
        self.assert_('@@' in lines[2][2:])
 
48
            ## "Unterminated hunk header for patch:\n%s" % "".join(lines)
 
49