~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testdiff.py

  • Committer: Martin Pool
  • Date: 2005-08-25 05:58:05 UTC
  • mfrom: (974.1.36)
  • Revision ID: mbp@sourcefrog.net-20050825055805-8c892bc3c2d75131
- merge aaron's merge improvements:

  * When merging, pull in all missing revisions from the source
    branch. 

  * Detect common ancestors by looking at the whole ancestry graph, 
    rather than just mainline history.

  Some changes to reconcile this with parallel updates to the test and
  trace code.

aaron.bentley@utoronto.ca-20050823052551-f3401a8b57d9126f

Show diffs side-by-side

added added

removed removed

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