1
 
# -*- coding: utf-8 -*-
 
2
 
# Copyright (C) 2007 Adeodato Simó <dato@net.com.org.es>
 
4
 
# This program is free software; you can redistribute it and/or modify
 
5
 
# it under the terms of the GNU General Public License as published by
 
6
 
# the Free Software Foundation; either version 2 of the License, or
 
7
 
# (at your option) any later version.
 
9
 
# This program is distributed in the hope that it will be useful,
 
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 
# GNU General Public License for more details.
 
14
 
# You should have received a copy of the GNU General Public License
 
15
 
# along with this program; if not, write to the Free Software
 
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
from cStringIO import StringIO
 
21
 
from bzrlib import tests
 
23
 
from bzrlib.plugins.gtk.diff import DiffView, iter_changes_to_status
 
26
 
class TestDiffViewSimple(tests.TestCase):
 
28
 
    def test_parse_colordiffrc(self):
 
32
 
# now a comment and a blank line
 
35
 
  # another comment preceded by whitespace
 
40
 
                'diffstuff': '#ffff00',
 
42
 
        parsed_colors = DiffView.parse_colordiffrc(StringIO(colordiffrc))
 
43
 
        self.assertEqual(colors, parsed_colors)
 
46
 
class TestDiffView(tests.TestCaseWithTransport):
 
48
 
    def test_unicode(self):
 
49
 
        from bzrlib.tests.test_diff import UnicodeFilename
 
50
 
        self.requireFeature(UnicodeFilename)
 
52
 
        tree = self.make_branch_and_tree('tree')
 
53
 
        self.build_tree([u'tree/\u03a9'])
 
54
 
        tree.add([u'\u03a9'], ['omega-id'])
 
57
 
        view.set_trees(tree, tree.basis_tree())
 
60
 
        start, end = buf.get_bounds()
 
61
 
        text = buf.get_text(start, end)
 
62
 
        self.assertContainsRe(text,
 
63
 
            "=== added file '\xce\xa9'\n"
 
64
 
            '--- .*\t1970-01-01 00:00:00 \\+0000\n'
 
65
 
            r'\+\+\+ .*\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d\n'
 
67
 
            '\\+contents of tree/\xce\xa9\n'
 
72
 
class Test_IterChangesToStatus(tests.TestCaseWithTransport):
 
74
 
    def assertStatusEqual(self, expected, tree):
 
75
 
        values = iter_changes_to_status(tree.basis_tree(), tree)
 
76
 
        self.assertEqual(expected, values)
 
78
 
    def test_status_added(self):
 
79
 
        tree = self.make_branch_and_tree('tree')
 
80
 
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
 
81
 
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
 
83
 
        self.assertStatusEqual(
 
84
 
            [('a-id', 'a', 'added', 'a'),
 
85
 
             ('b-id', 'b', 'added', 'b/'),
 
86
 
             ('c-id', 'b/c', 'added', 'b/c'),
 
89
 
    def test_status_renamed(self):
 
90
 
        tree = self.make_branch_and_tree('tree')
 
91
 
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
 
92
 
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
 
93
 
        rev_id1 = tree.commit('one')
 
95
 
        tree.rename_one('b', 'd')
 
96
 
        tree.rename_one('a', 'd/a')
 
98
 
        self.assertStatusEqual(
 
99
 
            [('b-id', 'd', 'renamed', 'b/ => d/'),
 
100
 
             ('a-id', 'd/a', 'renamed', 'a => d/a'),
 
103
 
    def test_status_modified(self):
 
104
 
        tree = self.make_branch_and_tree('tree')
 
105
 
        self.build_tree(['tree/a'])
 
106
 
        tree.add(['a'], ['a-id'])
 
107
 
        rev_id1 = tree.commit('one')
 
109
 
        self.build_tree_contents([('tree/a', 'new contents for a\n')])
 
111
 
        self.assertStatusEqual(
 
112
 
            [('a-id', 'a', 'modified', 'a'),
 
115
 
    def test_status_renamed_and_modified(self):
 
116
 
        tree = self.make_branch_and_tree('tree')
 
117
 
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
 
118
 
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
 
119
 
        rev_id1 = tree.commit('one')
 
121
 
        tree.rename_one('b', 'd')
 
122
 
        tree.rename_one('a', 'd/a')
 
123
 
        self.build_tree_contents([('tree/d/a', 'new contents for a\n'),
 
124
 
                                  ('tree/d/c', 'new contents for c\n'),
 
126
 
        # 'c' is not considered renamed, because only its parent was moved, it
 
127
 
        # stayed in the same directory
 
129
 
        self.assertStatusEqual(
 
130
 
            [('b-id', 'd', 'renamed', 'b/ => d/'),
 
131
 
             ('a-id', 'd/a', 'renamed and modified', 'a => d/a'),
 
132
 
             ('c-id', 'd/c', 'modified', 'd/c'),
 
135
 
    def test_status_kind_changed(self):
 
136
 
        tree = self.make_branch_and_tree('tree')
 
137
 
        self.build_tree(['tree/a', 'tree/b'])
 
138
 
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
142
 
        self.build_tree(['tree/a/'])
 
143
 
        # XXX:  This is technically valid, and the file list handles it fine,
 
144
 
        #       but 'show_diff_trees()' does not, so we skip this part of the
 
146
 
        # tree.rename_one('b', 'c')
 
147
 
        # os.remove('tree/c')
 
148
 
        # self.build_tree(['tree/c/'])
 
150
 
        self.assertStatusEqual(
 
151
 
            [('a-id', 'a', 'kind changed', 'a => a/'),
 
152
 
            # ('b-id', 'c', True, 'b => c/', 'renamed and modified'),
 
155
 
    def test_status_removed(self):
 
156
 
        tree = self.make_branch_and_tree('tree')
 
157
 
        self.build_tree(['tree/a', 'tree/b/'])
 
158
 
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
162
 
        tree.remove('b', force=True)
 
164
 
        self.assertStatusEqual(
 
165
 
            [('a-id', 'a', 'removed', 'a'),
 
166
 
             ('b-id', 'b', 'removed', 'b/'),