Skip to content

Commit 94995ac

Browse files
committed
Test that we preserve line endings when formatting CRLF documents
1 parent d1bd462 commit 94995ac

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

tests/fixtures/formatted-crlf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if True:
2+
print("foo")
3+
4+
print("bar")

tests/fixtures/unformatted-crlf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if True:
2+
print("foo")
3+
4+
print("bar")

tests/test_plugin.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ def unformatted_pyi_document(workspace):
3939
return Document(uri, workspace)
4040

4141

42+
@pytest.fixture
43+
def unformatted_crlf_document(workspace):
44+
path = fixtures_dir / "unformatted-crlf.py"
45+
uri = f"file:/{path}"
46+
with open(path, 'r', newline='') as f:
47+
source = f.read()
48+
return Document(uri, workspace, source=source)
49+
50+
4251
@pytest.fixture
4352
def formatted_document(workspace):
4453
path = fixtures_dir / "formatted.txt"
@@ -53,6 +62,15 @@ def formatted_pyi_document(workspace):
5362
return Document(uri, workspace)
5463

5564

65+
@pytest.fixture
66+
def formatted_crlf_document(workspace):
67+
path = fixtures_dir / "formatted-crlf.py"
68+
uri = f"file:/{path}"
69+
with open(path, 'r', newline='') as f:
70+
source = f.read()
71+
return Document(uri, workspace, source=source)
72+
73+
5674
@pytest.fixture
5775
def invalid_document(workspace):
5876
path = fixtures_dir / "invalid.txt"
@@ -224,3 +242,17 @@ def test_entry_point():
224242

225243
module = entry_point.load()
226244
assert isinstance(module, types.ModuleType)
245+
246+
247+
def test_pylsp_format_crlf_document(unformatted_crlf_document, formatted_crlf_document):
248+
result = pylsp_format_document(unformatted_crlf_document)
249+
250+
assert result == [
251+
{
252+
"range": {
253+
"start": {"line": 0, "character": 0},
254+
"end": {"line": 4, "character": 0},
255+
},
256+
"newText": formatted_crlf_document.source,
257+
}
258+
]

0 commit comments

Comments
 (0)