1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2008 Alexander Belchenko
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.
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.
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.
19
"""Tests for QBzr plugin."""
21
from bzrlib.tests import TestCase
22
from bzrlib.plugins.qbzr.lib.diffview import insert_intraline_changes
30
def insertText(self, text, format):
31
self.text += '<%s>%s</%s>' % (format, text, format)
34
class TestInsertIntralineChanges(TestCase):
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)
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)
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)
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)
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)