1
# Copyright (C) 2009, 2011 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."""
23
from bzrlib.filters import _get_filter_stack_for
24
from bzrlib.filters.eol import (
28
from bzrlib.tests import TestCase
32
_sample_file1 = """hello\nworld\r\n"""
35
class TestEolFilters(TestCase):
38
result = _to_lf_converter([_sample_file1])
39
self.assertEqual(["hello\nworld\n"], result)
41
def test_to_crlf(self):
42
result = _to_crlf_converter([_sample_file1])
43
self.assertEqual(["hello\r\nworld\r\n"], result)
46
class TestEolRulesSpecifications(TestCase):
48
def test_exact_value(self):
49
"""'eol = exact' should have no content filters"""
50
prefs = (('eol','exact'),)
51
self.assertEqual([], _get_filter_stack_for(prefs))
53
def test_other_known_values(self):
54
"""These known eol values have corresponding filters."""
55
known_values = ('lf', 'crlf', 'native',
56
'native-with-crlf-in-repo', 'lf-with-crlf-in-repo',
57
'crlf-with-crlf-in-repo')
58
for value in known_values:
59
prefs = (('eol',value),)
60
self.assertNotEqual([], _get_filter_stack_for(prefs))
62
def test_unknown_value(self):
64
Unknown eol values should raise an error.
66
prefs = (('eol','unknown-value'),)
67
self.assertRaises(errors.BzrError, _get_filter_stack_for, prefs)
69
def test_eol_missing_altogether_is_ok(self):
71
Not having eol in the set of preferences should be ok.
73
# In this case, 'eol' is looked up with a value of None.
74
prefs = (('eol', None),)
75
self.assertEqual([], _get_filter_stack_for(prefs))