1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
"""Tests for roundtripping text parsing."""
21
from __future__ import absolute_import
23
from ...tests import TestCase
25
from ..roundtrip import (
27
deserialize_fileid_map,
29
generate_roundtripping_metadata,
31
parse_roundtripping_metadata,
36
class RoundtripTests(TestCase):
39
md = parse_roundtripping_metadata(b"revision-id: foo\n")
40
self.assertEqual(b"foo", md.revision_id)
42
def test_parent_ids(self):
43
md = parse_roundtripping_metadata(b"parent-ids: foo bar\n")
44
self.assertEqual((b"foo", b"bar"), md.explicit_parent_ids)
46
def test_properties(self):
47
md = parse_roundtripping_metadata(b"property-foop: blar\n")
48
self.assertEqual({b"foop": b"blar"}, md.properties)
51
class FormatTests(TestCase):
54
metadata = CommitSupplement()
55
metadata.revision_id = b"bla"
56
self.assertEqual(b"revision-id: bla\n",
57
generate_roundtripping_metadata(metadata, "utf-8"))
59
def test_parent_ids(self):
60
metadata = CommitSupplement()
61
metadata.explicit_parent_ids = (b"foo", b"bar")
62
self.assertEqual(b"parent-ids: foo bar\n",
63
generate_roundtripping_metadata(metadata, "utf-8"))
65
def test_properties(self):
66
metadata = CommitSupplement()
67
metadata.properties = {b"foo": b"bar"}
68
self.assertEqual(b"property-foo: bar\n",
69
generate_roundtripping_metadata(metadata, "utf-8"))
72
metadata = CommitSupplement()
74
generate_roundtripping_metadata(metadata, "utf-8"))
77
class ExtractMetadataTests(TestCase):
79
def test_roundtrip(self):
80
(msg, metadata) = extract_bzr_metadata(b"""Foo
84
self.assertEqual(b"Foo", msg)
85
self.assertEqual(b"foo", metadata.revision_id)
88
class GenerateMetadataTests(TestCase):
90
def test_roundtrip(self):
91
metadata = CommitSupplement()
92
metadata.revision_id = b"myrevid"
93
msg = inject_bzr_metadata(b"Foo", metadata, "utf-8")
94
self.assertEqual(b"""Foo
99
def test_no_metadata(self):
100
metadata = CommitSupplement()
101
msg = inject_bzr_metadata(b"Foo", metadata, "utf-8")
102
self.assertEqual(b"Foo", msg)
105
class FileIdRoundTripTests(TestCase):
107
def test_deserialize(self):
108
self.assertEqual({"bar/bla": b"fid"},
109
deserialize_fileid_map(b"bar/bla\0fid\n"))
111
def test_serialize(self):
112
self.assertEqual([b"bar/bla\0fid\n"],
113
serialize_fileid_map({"bar/bla": b"fid"}))