mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
tests(lsp/java): run Java LSP tests with Robolectric
This commit is contained in:
+5
-1
@@ -22,8 +22,11 @@ import com.itsaky.androidide.lsp.models.CompletionParams
|
||||
import com.itsaky.androidide.progress.ICancelChecker
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
/** @author Akash Yadav */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class JavaCompletionProviderTest {
|
||||
|
||||
@Before
|
||||
@@ -82,7 +85,8 @@ class JavaCompletionProviderTest {
|
||||
|
||||
private fun completionTitles(pos: com.itsaky.androidide.models.Position): List<CharSequence> {
|
||||
return JavaLSPTest.server
|
||||
.complete(CompletionParams(pos, JavaLSPTest.file!!).apply { prefix = "" }, ICancelChecker.Default())
|
||||
.complete(CompletionParams(pos, JavaLSPTest.file!!).apply { prefix = "" },
|
||||
ICancelChecker.Default())
|
||||
.items
|
||||
.map { it.label }
|
||||
}
|
||||
|
||||
+9
-4
@@ -27,22 +27,27 @@ import io.github.rosemoe.sora.text.Content
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
/** @author Akash Yadav */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class JavaSelectionProviderTest {
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
JavaLSPTest.setup()
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testSimpleSelectionExpansion() {
|
||||
JavaLSPTest.apply {
|
||||
openFile("selection/SimpleSelectionExpansionTest")
|
||||
cursor = requireCursor()
|
||||
deleteCursorText()
|
||||
dispatchEvent(DocumentChangeEvent(file!!, contents.toString(), contents.toString(),1, NEW_TEXT, 0, Range.NONE))
|
||||
dispatchEvent(
|
||||
DocumentChangeEvent(file!!, contents.toString(), contents.toString(), 1, NEW_TEXT, 0,
|
||||
Range.NONE))
|
||||
|
||||
val range = findRange()
|
||||
val expanded = runBlocking { server.expandSelection(ExpandSelectionParams(file!!, range)) }
|
||||
@@ -75,7 +80,7 @@ class JavaSelectionProviderTest {
|
||||
val end = Position(8, 9)
|
||||
val range = Range(start, end)
|
||||
|
||||
val expanded = runBlocking{ server.expandSelection(ExpandSelectionParams(file!!, range)) }
|
||||
val expanded = runBlocking { server.expandSelection(ExpandSelectionParams(file!!, range)) }
|
||||
assertThat(expanded).isEqualTo(Range(Position(4, 8), Position(10, 9)))
|
||||
}
|
||||
}
|
||||
@@ -90,7 +95,7 @@ class JavaSelectionProviderTest {
|
||||
val end = Position(10, 9)
|
||||
val range = Range(start, end)
|
||||
|
||||
val expanded = runBlocking{ server.expandSelection(ExpandSelectionParams(file!!, range)) }
|
||||
val expanded = runBlocking { server.expandSelection(ExpandSelectionParams(file!!, range)) }
|
||||
assertThat(expanded).isEqualTo(Range(Position(4, 8), Position(10, 9)))
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -196,7 +196,7 @@ class DefaultApiVersionsRegistry : ApiVersionsRegistry {
|
||||
|
||||
private fun XmlPullParser.readInt(name: String, default: Int = -1): Int {
|
||||
return read(this, name) {
|
||||
if (it == null || it.isBlank()) {
|
||||
if (it.isNullOrBlank()) {
|
||||
return@read default
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ class DefaultApiVersionsRegistry : ApiVersionsRegistry {
|
||||
|
||||
private fun XmlPullParser.readString(name: String, default: String = ""): String {
|
||||
return read(this, name) {
|
||||
if (it == null || it.isBlank()) {
|
||||
if (it.isNullOrBlank()) {
|
||||
return@read default
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user