1
# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
 
 
2
# -*- encoding: utf-8 -*-
 
 
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 roundtripping text parsing."""
 
 
22
from bzrlib.tests import TestCase
 
 
24
from bzrlib.plugins.git.roundtrip import (
 
 
25
    BzrGitRevisionMetadata,
 
 
26
    deserialize_fileid_map,
 
 
28
    generate_roundtripping_metadata,
 
 
30
    parse_roundtripping_metadata,
 
 
35
class RoundtripTests(TestCase):
 
 
38
        md = parse_roundtripping_metadata("revision-id: foo\n")
 
 
39
        self.assertEquals("foo", md.revision_id)
 
 
41
    def test_parent_ids(self):
 
 
42
        md = parse_roundtripping_metadata("parent-ids: foo bar\n")
 
 
43
        self.assertEquals(("foo", "bar"), md.explicit_parent_ids)
 
 
45
    def test_properties(self):
 
 
46
        md = parse_roundtripping_metadata("property-foop: blar\n")
 
 
47
        self.assertEquals({"foop": "blar"}, md.properties)
 
 
50
class FormatTests(TestCase):
 
 
53
        metadata = BzrGitRevisionMetadata()
 
 
54
        metadata.revision_id = "bla"
 
 
55
        self.assertEquals("revision-id: bla\n",
 
 
56
            generate_roundtripping_metadata(metadata, "utf-8"))
 
 
58
    def test_parent_ids(self):
 
 
59
        metadata = BzrGitRevisionMetadata()
 
 
60
        metadata.explicit_parent_ids = ("foo", "bar")
 
 
61
        self.assertEquals("parent-ids: foo bar\n",
 
 
62
            generate_roundtripping_metadata(metadata, "utf-8"))
 
 
64
    def test_properties(self):
 
 
65
        metadata = BzrGitRevisionMetadata()
 
 
66
        metadata.properties = {"foo": "bar"}
 
 
67
        self.assertEquals("property-foo: bar\n",
 
 
68
            generate_roundtripping_metadata(metadata, "utf-8"))
 
 
71
class ExtractMetadataTests(TestCase):
 
 
73
    def test_roundtrip(self):
 
 
74
        (msg, metadata) = extract_bzr_metadata("""Foo
 
 
78
        self.assertEquals("Foo", msg)
 
 
79
        self.assertEquals("foo", metadata.revision_id)
 
 
82
class GenerateMetadataTests(TestCase):
 
 
84
    def test_roundtrip(self):
 
 
85
        metadata = BzrGitRevisionMetadata()
 
 
86
        metadata.revision_id = "myrevid"
 
 
87
        msg = inject_bzr_metadata("Foo", metadata, "utf-8")
 
 
88
        self.assertEquals("""Foo
 
 
94
class FileIdRoundTripTests(TestCase):
 
 
96
    def test_deserialize(self):
 
 
97
        self.assertEquals({"bar/bla": "fid"},
 
 
98
            deserialize_fileid_map("bar/bla\0fid\n"))
 
 
100
    def test_serialize(self):
 
 
101
        self.assertEquals(["bar/bla\0fid\n"],
 
 
102
            serialize_fileid_map({"bar/bla": "fid"}))