Debian Codegraph @

lib/tests/test_diffview.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008 Lukáš Lalinský <[email protected]om>
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 QBrz plugin."""
20
21 from breezy.tests import TestCase
22 from breezy.plugins.qbrz.lib.diffview import insert_intraline_changes
23
24
25 class FakeCursor(object):
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.assertEqual('<n>foo</n>', cursor1.text)
41 self.assertEqual('<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.assertEqual('<del>foo</del>', cursor1.text)
48 self.assertEqual('<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.assertEqual('<n>fo</n><del>o</del>', cursor1.text)
55 self.assertEqual('<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.assertEqual('<n>fo</n>', cursor1.text)
62 self.assertEqual('<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.assertEqual('<n>fo</n><del>o</del><n>b</n><del>a</del><n>r</n>', cursor1.text)
69 self.assertEqual('<n>fo</n><ins>O</ins><n>b</n><ins>A</ins><n>r</n>', cursor2.text)