~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_eol_filters.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2011 Canonical Ltd
2
 
#
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.
7
 
#
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.
12
 
#
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
16
 
 
17
 
"""Tests for eol conversion."""
18
 
 
19
 
 
20
 
from bzrlib import (
21
 
    errors,
22
 
    )
23
 
from bzrlib.filters import _get_filter_stack_for
24
 
from bzrlib.filters.eol import (
25
 
    _to_crlf_converter,
26
 
    _to_lf_converter,
27
 
    )
28
 
from bzrlib.tests import TestCase
29
 
 
30
 
 
31
 
# Sample files
32
 
_sample_file1 = """hello\nworld\r\n"""
33
 
 
34
 
 
35
 
class TestEolFilters(TestCase):
36
 
 
37
 
    def test_to_lf(self):
38
 
        result = _to_lf_converter([_sample_file1])
39
 
        self.assertEqual(["hello\nworld\n"], result)
40
 
 
41
 
    def test_to_crlf(self):
42
 
        result = _to_crlf_converter([_sample_file1])
43
 
        self.assertEqual(["hello\r\nworld\r\n"], result)
44
 
 
45
 
 
46
 
class TestEolRulesSpecifications(TestCase):
47
 
 
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))
52
 
 
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))
61
 
 
62
 
    def test_unknown_value(self):
63
 
        """
64
 
        Unknown eol values should raise an error.
65
 
        """
66
 
        prefs = (('eol','unknown-value'),)
67
 
        self.assertRaises(errors.BzrError, _get_filter_stack_for,  prefs)
68
 
 
69
 
    def test_eol_missing_altogether_is_ok(self):
70
 
        """
71
 
        Not having eol in the set of preferences should be ok.
72
 
        """
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))