Skip to content

Commit 42ac545

Browse files
committed
Added rename test cases
1 parent b27f35f commit 42ac545

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ abstract class LanguageServerTestFixture(relativeWorkspaceRoot: String) : Langua
5454
println("Memory after test: ${total - free} MB used / $total MB total")
5555
}
5656

57+
fun renameParams(relativePath: String, line: Int, column: Int, newName: String): RenameParams =
58+
textDocumentPosition(relativePath, line, column).run { RenameParams(textDocument, position, newName) }
59+
5760
fun completionParams(relativePath: String, line: Int, column: Int): CompletionParams {
5861
val file = workspaceRoot.resolve(relativePath)
5962
val fileId = TextDocumentIdentifier(file.toUri().toString())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.javacs.kt
2+
3+
import org.eclipse.lsp4j.Position
4+
import org.eclipse.lsp4j.Range
5+
import org.hamcrest.Matchers.containsString
6+
import org.hamcrest.Matchers.equalTo
7+
import org.hamcrest.Matchers.hasItem
8+
import org.hamcrest.Matchers.hasProperty
9+
import org.hamcrest.Matchers.hasSize
10+
import org.junit.Assert.assertThat
11+
import org.junit.Test
12+
13+
class RenameReferenceTest : SingleFileTestFixture("rename", "SomeClass.kt") {
14+
15+
@Test
16+
fun `rename in the reference`() {
17+
val edits = languageServer.textDocumentService.rename(renameParams(file, 4, 26, "NewClassName")).get()!!
18+
val changes = edits.documentChanges
19+
20+
assertThat(changes.size, equalTo(3))
21+
assertThat(changes[0].left.textDocument.uri, containsString("SomeOtherClass.kt"))
22+
23+
assertThat(changes[0].left.edits[0].newText, equalTo("NewClassName"))
24+
assertThat(changes[0].left.edits[0].range.start, equalTo(Position(2, 6)))
25+
assertThat(changes[0].left.edits[0].range.end, equalTo(Position(2, 20)))
26+
}
27+
}
28+
29+
class RenameDefinitionTest : SingleFileTestFixture("rename", "SomeOtherClass.kt") {
30+
31+
@Test
32+
fun `rename in the definition`() {
33+
val edits = languageServer.textDocumentService.rename(renameParams(file, 2, 15, "NewClassName")).get()!!
34+
val changes = edits.documentChanges
35+
36+
println(changes)
37+
38+
assertThat(changes.size, equalTo(3))
39+
assertThat(changes[0].left.textDocument.uri, containsString("SomeOtherClass.kt"))
40+
41+
assertThat(changes[0].left.edits[0].newText, equalTo("NewClassName"))
42+
assertThat(changes[0].left.edits[0].range.start, equalTo(Position(2, 6)))
43+
assertThat(changes[0].left.edits[0].range.end, equalTo(Position(2, 20)))
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package rename
2+
3+
class SomeClass {
4+
5+
val something: SomeOtherClass = SomeOtherClass()
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package rename
2+
3+
class SomeOtherClass {
4+
}

0 commit comments

Comments
 (0)