Skip to content

Commit 88785db

Browse files
committed
[Completion] Add test case for code-completion position adjustment
1 parent f99b707 commit 88785db

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Tests/SourceKitTests/LocalSwiftTests.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,35 @@ final class LocalSwiftTests: XCTestCase {
220220
XCTAssertNotEqual(after, selfDot)
221221
}
222222

223+
func testCompletionPosition() {
224+
let url = URL(fileURLWithPath: "/a.swift")
225+
sk.allowUnexpectedNotification = true
226+
227+
sk.send(DidOpenTextDocument(textDocument: TextDocumentItem(
228+
url: url,
229+
language: .swift,
230+
version: 12,
231+
text: "foo")))
232+
233+
for col in 0 ... 3 {
234+
let inOrAfterFoo = try! sk.sendSync(CompletionRequest(
235+
textDocument: TextDocumentIdentifier(url),
236+
position: Position(line: 0, utf16index: col)))
237+
XCTAssertFalse(inOrAfterFoo.isIncomplete)
238+
XCTAssertFalse(inOrAfterFoo.items.isEmpty)
239+
}
240+
241+
let outOfRange1 = try! sk.sendSync(CompletionRequest(
242+
textDocument: TextDocumentIdentifier(url),
243+
position: Position(line: 0, utf16index: 4)))
244+
XCTAssertTrue(outOfRange1.isIncomplete)
245+
246+
let outOfRange2 = try! sk.sendSync(CompletionRequest(
247+
textDocument: TextDocumentIdentifier(url),
248+
position: Position(line: 1, utf16index: 0)))
249+
XCTAssertTrue(outOfRange2.isIncomplete)
250+
}
251+
223252
func testXMLToMarkdownDeclaration() {
224253
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
225254
<Declaration>func foo(_ bar: <Type usr="fake">Baz</Type>)</Declaration>

0 commit comments

Comments
 (0)