8000 Test that we preserve line endings when formatting CRLF documents · python-lsp/python-lsp-black@0c82bf8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c82bf8

Browse files
committed
Test that we preserve line endings when formatting CRLF documents
1 parent 450ce31 commit 0c82bf8

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") # noqa

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") # noqa

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"
@@ -225,3 +243,17 @@ def test_entry_point():
225243

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

0 commit comments

Comments
 (0)
0