Skip to content

Commit

Permalink
Merge pull request #33 from replit/dstewart/DX-511/feat/formatting-ls…
Browse files Browse the repository at this point in the history
…p-tests

Adding formatting LSP tests
  • Loading branch information
blast-hardcheese authored Mar 18, 2024
2 parents 8d88f77 + fd22bcc commit 4334e90
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/pyright_extended_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from lsprotocol.types import (
CompletionParams,
CompletionList,
DocumentFormattingParams,
FormattingOptions,
InitializeParams,
Position,
TextDocumentIdentifier,
Expand Down Expand Up @@ -127,3 +129,53 @@ async def test_linter(client: LanguageClient):
assert (
diagnostics[1].code == "ruff[F401]"
), f"Expected second warning to be unused import: {fileuri}"


@pytest.mark.asyncio
async def test_formatting(client: LanguageClient):
fileuri = f"file://{testroot}/cases/3.py"
contents = dedent(
"""\
import os
x = "this is\\na test"
print(os.getenv( "PATH", x))
if True:
pass
"""
)
expected = dedent(
"""\
import os
x = "this is\\na test"
print(os.getenv("PATH", x))
if True:
pass
"""
)
print(repr(contents))
result = client.text_document_did_open(
DidOpenTextDocumentParams(
text_document=TextDocumentItem(
uri=fileuri,
language_id="python",
text=contents,
version=0,
)
)
)

result = await client.text_document_formatting_async(
params=DocumentFormattingParams(
text_document=TextDocumentIdentifier(uri=fileuri),
options=FormattingOptions(
tab_size=4,
insert_spaces=True,
trim_trailing_whitespace=True,
)
)
)

assert isinstance(result, list), result
assert len(result) > 0
assert result[0].new_text == expected

0 comments on commit 4334e90

Please sign in to comment.