|
| 1 | +import os |
| 2 | +from pathlib import Path |
| 3 | + |
1 | 4 | import pytest |
| 5 | + |
| 6 | +from robotidy.app import Robotidy |
2 | 7 | from robotidy.utils import ( |
3 | 8 | decorate_diff_with_color, |
4 | | - split_args_from_name_or_path |
| 9 | + split_args_from_name_or_path, |
| 10 | + GlobalFormattingConfig |
5 | 11 | ) |
6 | 12 |
|
7 | 13 |
|
| 14 | +@pytest.fixture |
| 15 | +def app(): |
| 16 | + formatting_config = GlobalFormattingConfig( |
| 17 | + space_count=4, |
| 18 | + line_sep="auto", |
| 19 | + start_line=None, |
| 20 | + separator="space", |
| 21 | + end_line=None, |
| 22 | + ) |
| 23 | + return Robotidy( |
| 24 | + transformers=[], |
| 25 | + transformers_config=[], |
| 26 | + src=('.',), |
| 27 | + exclude=None, |
| 28 | + extend_exclude=None, |
| 29 | + overwrite=False, |
| 30 | + show_diff=False, |
| 31 | + formatting_config=formatting_config, |
| 32 | + verbose=False, |
| 33 | + check=False, |
| 34 | + output=None, |
| 35 | + force_order=False |
| 36 | + ) |
| 37 | + |
| 38 | + |
8 | 39 | class TestUtils: |
9 | 40 | def test_not_changed_lines_not_colorized(self): |
10 | 41 | lines = [ |
@@ -49,3 +80,27 @@ def test_split_args_from_name_or_path(self, name_or_path, expected_name, expecte |
49 | 80 | name, args = split_args_from_name_or_path(name_or_path) |
50 | 81 | assert name == expected_name |
51 | 82 | assert args == expected_args |
| 83 | + |
| 84 | + @pytest.mark.parametrize("line_sep, source_file, expected", [ |
| 85 | + ("auto", "lf.robot", "\n"), |
| 86 | + ("auto", "crlf.robot", "\r\n"), |
| 87 | + ("auto", "cr.robot", "\r"), |
| 88 | + ("auto", "crlf_mixed.robot", "\n"), |
| 89 | + ("auto", "empty.robot", os.linesep), |
| 90 | + ("native", "lf.robot", os.linesep), |
| 91 | + ("native", "crlf.robot", os.linesep), |
| 92 | + ("windows", "lf.robot", "\r\n"), |
| 93 | + ("windows", "crlf.robot", "\r\n"), |
| 94 | + ("unix", "lf.robot", "\n"), |
| 95 | + ("unix", "crlf.robot", "\n") |
| 96 | + ]) |
| 97 | + def test_get_line_ending(self, line_sep, source_file, expected, app): |
| 98 | + source = str(Path(__file__).parent / 'testdata' / 'auto_line_sep' / source_file) |
| 99 | + app.formatting_config = GlobalFormattingConfig( |
| 100 | + space_count=4, |
| 101 | + line_sep=line_sep, |
| 102 | + start_line=None, |
| 103 | + separator="space", |
| 104 | + end_line=None, |
| 105 | + ) |
| 106 | + assert app.get_line_ending(source) == expected |
0 commit comments