1
# Copyright (C) 2010 Jelmer Vernooij
 
 
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
 
 
19
"""Tests for ref handling."""
 
 
21
from bzrlib import tests
 
 
23
from bzrlib.plugins.git import refs
 
 
26
class BranchNameRefConversionTests(tests.TestCase):
 
 
29
        self.assertEquals("HEAD", refs.ref_to_branch_name("HEAD"))
 
 
30
        self.assertEquals("HEAD", refs.branch_name_to_ref("HEAD"))
 
 
31
        self.assertEquals(None, refs.branch_name_to_ref(None))
 
 
34
        self.assertRaises(ValueError, refs.ref_to_branch_name, "refs/tags/FOO")
 
 
36
    def test_branch(self):
 
 
37
        self.assertEquals("frost", refs.ref_to_branch_name("refs/heads/frost"))
 
 
38
        self.assertEquals("refs/heads/frost", refs.branch_name_to_ref("frost"))
 
 
40
    def test_default(self):
 
 
41
        self.assertEquals("mydefault",
 
 
42
            refs.branch_name_to_ref(None, "mydefault"))
 
 
43
        self.assertEquals(None,
 
 
44
            refs.branch_name_to_ref(None))
 
 
47
class ExtractTagTests(tests.TestCase):
 
 
49
    def test_ignore_branch(self):
 
 
52
                "HEAD": "ref: foo", "refs/branches/blala": "la"}))
 
 
55
        self.assertEquals({"mytag": "mysha"},
 
 
57
                "HEAD": "ref: foo", "refs/tags/mytag": "mysha"}))
 
 
59
    def test_ignores_peels(self):
 
 
60
        self.assertEquals({"mytag": "actualsha"},
 
 
63
                "refs/tags/mytag": "mysha",
 
 
64
                "refs/tags/mytag^{}": "actualsha"}))
 
 
66
    def test_non_ascii_name(self):
 
 
67
        self.assertEquals({u'myt\xe2g': "actualsha"},
 
 
70
                "refs/tags/myt\xc3\xa2g": "actualsha"}))
 
 
72
    def test_non_utf8_name(self):
 
 
75
                'refs/tags/LIBGEE_0_2_\xc20': "actualsha"}))