1
# Copyright (C) 2009 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Tests for eol conversion."""
24
from bzrlib.filters import _get_filter_stack_for
25
from bzrlib.filters.eol import (
29
from bzrlib.tests import TestCase
33
_sample_file1 = """hello\nworld\r\n"""
36
class TestEolFilters(TestCase):
39
result = _to_lf_converter([_sample_file1])
40
self.assertEqual(["hello\nworld\n"], result)
42
def test_to_crlf(self):
43
result = _to_crlf_converter([_sample_file1])
44
self.assertEqual(["hello\r\nworld\r\n"], result)
47
class TestEolRulesSpecifications(TestCase):
49
def test_exact_value(self):
50
"""'eol = exact' should have no content filters"""
51
prefs = (('eol','exact'),)
52
self.assertEqual([], _get_filter_stack_for(prefs))
54
def test_other_known_values(self):
55
"""These known eol values have corresponding filters."""
56
known_values = ('lf', 'crlf', 'native',
57
'native-with-crlf-in-repo', 'lf-with-crlf-in-repo',
58
'crlf-with-crlf-in-repo')
59
for value in known_values:
60
prefs = (('eol',value),)
61
self.assertNotEqual([], _get_filter_stack_for(prefs))
63
def test_unknown_value(self):
65
Unknown eol values should raise an error.
67
prefs = (('eol','unknown-value'),)
68
self.assertRaises(errors.BzrError, _get_filter_stack_for, prefs)
70
def test_eol_missing_altogether_is_ok(self):
72
Not having eol in the set of preferences should be ok.
74
# In this case, 'eol' is looked up with a value of None.
75
prefs = (('eol', None),)
76
self.assertEqual([], _get_filter_stack_for(prefs))