|
6 | 6 | use PHPUnit\Framework\TestCase;
|
7 | 7 | use LanguageServer\Tests\MockProtocolStream;
|
8 | 8 | use LanguageServer\{Server, Client, LanguageClient};
|
9 |
| -use LanguageServer\Protocol\{TextDocumentItem, TextDocumentIdentifier, SymbolKind, DiagnosticSeverity}; |
| 9 | +use LanguageServer\Protocol\{TextDocumentItem, TextDocumentIdentifier, SymbolKind, DiagnosticSeverity, FormattingOptions}; |
10 | 10 | use AdvancedJsonRpc\{Request as RequestBody, Response as ResponseBody};
|
11 | 11 |
|
12 | 12 | class TextDocumentTest extends TestCase
|
@@ -197,4 +197,34 @@ public function publishDiagnostics(string $uri, array $diagnostics)
|
197 | 197 | ]]
|
198 | 198 | ], json_decode(json_encode($args), true));
|
199 | 199 | }
|
| 200 | + |
| 201 | + public function testFormatting() |
| 202 | + { |
| 203 | + $textDocument = new Server\TextDocument(new LanguageClient(new MockProtocolStream())); |
| 204 | + // Trigger parsing of source |
| 205 | + $textDocumentItem = new TextDocumentItem(); |
| 206 | + $textDocumentItem->uri = 'whatever'; |
| 207 | + $textDocumentItem->languageId = 'php'; |
| 208 | + $textDocumentItem->version = 1; |
| 209 | + $textDocumentItem->text = file_get_contents(__DIR__ . '/../../fixtures/format.php'); |
| 210 | + $textDocument->didOpen($textDocumentItem); |
| 211 | + |
| 212 | + // how code should look after formatting |
| 213 | + $expected = file_get_contents(__DIR__ . '/../../fixtures/format_expected.php'); |
| 214 | + // Request formatting |
| 215 | + $result = $textDocument->formatting(new TextDocumentIdentifier('whatever'), new FormattingOptions()); |
| 216 | + $this->assertEquals([0 => [ |
| 217 | + 'range' => [ |
| 218 | + 'start' => [ |
| 219 | + 'line' => 0, |
| 220 | + 'character' => 0 |
| 221 | + ], |
| 222 | + 'end' => [ |
| 223 | + 'line' => PHP_INT_MAX, |
| 224 | + 'character' => PHP_INT_MAX |
| 225 | + ] |
| 226 | + ], |
| 227 | + 'newText' => $expected |
| 228 | + ]], json_decode(json_encode($result), true)); |
| 229 | + } |
200 | 230 | }
|
0 commit comments