Skip to content

Commit ab68f06

Browse files
committed
Add unit test for trailing lambda completions
1 parent acb6574 commit ab68f06

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

server/src/test/kotlin/org/javacs/kt/CompletionsTest.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class EditCallTest : SingleFileTestFixture("completions", "EditCall.kt") {
253253
val labels = completions.items.map { it.label }
254254

255255
assertThat(labels, hasItem(startsWith("println")))
256-
assertThat(completions.items.filter { it.label.startsWith("println") }.firstOrNull(), hasProperty("insertText", equalTo("println")))
256+
assertThat(completions.items.find { it.label.startsWith("println") }, hasProperty("insertText", equalTo("println")))
257257
}
258258
}
259259

@@ -265,3 +265,21 @@ class EnumWithCompanionObjectTest : SingleFileTestFixture("completions", "Enum.k
265265
assertThat(labels, hasItem("ILLEGAL"))
266266
}
267267
}
268+
269+
class TrailingLambdaTest : SingleFileTestFixture("completions", "TrailingLambda.kt") {
270+
@Test fun `complete function with single lambda parameter`() {
271+
val completions = languageServer.textDocumentService.completion(completionParams(file, 6, 9)).get().right!!
272+
val labels = completions.items.map { it.label }
273+
274+
assertThat(labels, hasItem(startsWith("lambdaParameter")))
275+
assertThat(completions.items.find { it.label.startsWith("lambdaParameter") }, hasProperty("insertText", equalTo("lambdaParameter { \${1:x} }")))
276+
}
277+
278+
@Test fun `complete function with mixed parameters`() {
279+
val completions = languageServer.textDocumentService.completion(completionParams(file, 7, 8)).get().right!!
280+
val labels = completions.items.map { it.label }
281+
282+
assertThat(labels, hasItem(startsWith("mixedParameters")))
283+
assertThat(completions.items.find { it.label.startsWith("mixedParameters") }, hasProperty("insertText", equalTo("mixedParameters(\${1:a}) { \${2:b} }")))
284+
}
285+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fun lambdaParameter(x: () -> Unit) {}
2+
3+
fun mixedParameters(a: Int, b: (Int) -> Unit) {}
4+
5+
fun main(args: Array<String>) {
6+
lamb
7+
mix
8+
}

0 commit comments

Comments
 (0)