~kvilhaugsvik/qbzr/qshelve_all

« back to all changes in this revision

Viewing changes to lib/test_diffview.py

  • Committer: Lukáš Lalinský
  • Date: 2008-07-25 06:55:25 UTC
  • Revision ID: lalinsky@gmail.com-20080725065525-zfavwh00vtm1xn4y
Use patience diff for intraline changes highlighting

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Copyright (C) 2008 Alexander Belchenko
 
4
#
 
5
# This program is free software; you can redistribute it and/or
 
6
# modify it under the terms of the GNU General Public License
 
7
# as published by the Free Software Foundation; either version 2
 
8
# of the License, or (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
18
 
 
19
"""Tests for QBzr plugin."""
 
20
 
 
21
from bzrlib.tests import TestCase
 
22
from bzrlib.plugins.qbzr.lib.diffview import insert_intraline_changes
 
23
 
 
24
 
 
25
class FakeCursor:
 
26
 
 
27
    def __init__(self):
 
28
        self.text = ''
 
29
 
 
30
    def insertText(self, text, format):
 
31
        self.text += '<%s>%s</%s>' % (format, text, format)
 
32
 
 
33
 
 
34
class TestInsertIntralineChanges(TestCase):
 
35
 
 
36
    def test_no_change(self):
 
37
        cursor1 = FakeCursor()
 
38
        cursor2 = FakeCursor()
 
39
        insert_intraline_changes(cursor1, cursor2, 'foo', 'foo', 'n', 'ins', 'del')
 
40
        self.assertEquals('<n>foo</n>', cursor1.text)
 
41
        self.assertEquals('<n>foo</n>', cursor2.text)
 
42
 
 
43
    def test_whole_line_changed(self):
 
44
        cursor1 = FakeCursor()
 
45
        cursor2 = FakeCursor()
 
46
        insert_intraline_changes(cursor1, cursor2, 'foo', 'bar', 'n', 'ins', 'del')
 
47
        self.assertEquals('<del>foo</del>', cursor1.text)
 
48
        self.assertEquals('<ins>bar</ins>', cursor2.text)
 
49
 
 
50
    def test_delete_char(self):
 
51
        cursor1 = FakeCursor()
 
52
        cursor2 = FakeCursor()
 
53
        insert_intraline_changes(cursor1, cursor2, 'foo', 'fo', 'n', 'ins', 'del')
 
54
        self.assertEquals('<n>fo</n><del>o</del>', cursor1.text)
 
55
        self.assertEquals('<n>fo</n>', cursor2.text)
 
56
 
 
57
    def test_insert_char(self):
 
58
        cursor1 = FakeCursor()
 
59
        cursor2 = FakeCursor()
 
60
        insert_intraline_changes(cursor1, cursor2, 'fo', 'foo', 'n', 'ins', 'del')
 
61
        self.assertEquals('<n>fo</n>', cursor1.text)
 
62
        self.assertEquals('<n>fo</n><ins>o</ins>', cursor2.text)
 
63
 
 
64
    def test_replace_2_chars(self):
 
65
        cursor1 = FakeCursor()
 
66
        cursor2 = FakeCursor()
 
67
        insert_intraline_changes(cursor1, cursor2, 'foobar', 'foObAr', 'n', 'ins', 'del')
 
68
        self.assertEquals('<n>fo</n><del>o</del><n>b</n><del>a</del><n>r</n>', cursor1.text)
 
69
        self.assertEquals('<n>fo</n><ins>O</ins><n>b</n><ins>A</ins><n>r</n>', cursor2.text)