1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-06-08 13:34:03 +02:00

Migrate java tests to VimNoWriteActionTestCase

This commit is contained in:
Alex Plate 2025-02-20 18:46:50 +02:00
parent 96a1456dcd
commit e18035b729
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
10 changed files with 162 additions and 75 deletions
src/testFixtures/kotlin/org/jetbrains/plugins/ideavim
tests/java-tests/src/test/kotlin/org/jetbrains/plugins/ideavim

View File

@ -8,7 +8,6 @@
package org.jetbrains.plugins.ideavim package org.jetbrains.plugins.ideavim
import com.intellij.testFramework.LoggedErrorProcessor import com.intellij.testFramework.LoggedErrorProcessor
import com.intellij.testFramework.TestLoggerFactory.TestLoggerAssertionError
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.fail import org.junit.jupiter.api.fail
@ -32,7 +31,7 @@ object OnlyThrowLoggedErrorProcessor : LoggedErrorProcessor() {
* Asserts that [T] was thrown via `LOG.error("message", e)` call where `e` has a type of [T]. * Asserts that [T] was thrown via `LOG.error("message", e)` call where `e` has a type of [T].
*/ */
inline fun <reified T : Throwable> assertThrowsLogError(crossinline action: () -> Unit): T { inline fun <reified T : Throwable> assertThrowsLogError(crossinline action: () -> Unit): T {
val exception = assertThrows<TestLoggerAssertionError> { val exception = assertThrows<Throwable> {
LoggedErrorProcessor.executeWith<Throwable>(OnlyThrowLoggedErrorProcessor) { LoggedErrorProcessor.executeWith<Throwable>(OnlyThrowLoggedErrorProcessor) {
action() action()
} }

View File

@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
import com.intellij.openapi.actionSystem.ex.ActionUtil import com.intellij.openapi.actionSystem.ex.ActionUtil
import com.intellij.openapi.actionSystem.impl.SimpleDataContext import com.intellij.openapi.actionSystem.impl.SimpleDataContext
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.PathManager import com.intellij.openapi.application.PathManager
import com.intellij.openapi.application.WriteAction import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.diagnostic.thisLogger
@ -350,9 +351,15 @@ abstract class VimNoWriteActionTestCase {
protected fun configureByText(fileType: FileType, content: String): Editor { protected fun configureByText(fileType: FileType, content: String): Editor {
fixture.configureByText(fileType, content) fixture.configureByText(fileType, content)
// Note: Change to coroutines
ApplicationManager.getApplication().invokeAndWait {
setDefaultIntelliJSettings(fixture.editor) setDefaultIntelliJSettings(fixture.editor)
}
NeovimTesting.setupEditor(fixture.editor, testInfo) NeovimTesting.setupEditor(fixture.editor, testInfo)
// Note: Change to coroutines
ApplicationManager.getApplication().invokeAndWait {
setEditorVisibleSize(screenWidth, screenHeight) setEditorVisibleSize(screenWidth, screenHeight)
}
return fixture.editor return fixture.editor
} }
@ -444,7 +451,11 @@ abstract class VimNoWriteActionTestCase {
protected fun typeText(vararg keys: String) = typeText(keys.flatMap { injector.parser.parseKeys(it) }) protected fun typeText(vararg keys: String) = typeText(keys.flatMap { injector.parser.parseKeys(it) })
protected fun typeText(keys: List<KeyStroke?>): Editor { protected fun typeText(keys: List<KeyStroke?>): Editor {
return typeText(fixture.editor, keys) var editor: Editor? = null
ApplicationManager.getApplication().invokeAndWait {
editor = typeText(fixture.editor, keys)
}
return editor!!
} }
protected fun typeText(editor: Editor, keys: List<KeyStroke?>): Editor { protected fun typeText(editor: Editor, keys: List<KeyStroke?>): Editor {
@ -601,9 +612,11 @@ abstract class VimNoWriteActionTestCase {
) )
} }
assertEquals(expectedOffsets.size, carets.size, "Wrong amount of carets") assertEquals(expectedOffsets.size, carets.size, "Wrong amount of carets")
ApplicationManager.getApplication().runReadAction {
for (i in expectedOffsets.indices) { for (i in expectedOffsets.indices) {
assertEquals(expectedOffsets[i], carets[i].offset) assertEquals(expectedOffsets[i], carets[i].offset)
} }
}
NeovimTesting.assertState(fixture.editor, testInfo) NeovimTesting.assertState(fixture.editor, testInfo)
} }
@ -700,7 +713,12 @@ abstract class VimNoWriteActionTestCase {
} }
fun assertSelection(expected: String?) { fun assertSelection(expected: String?) {
val selected = fixture.editor.selectionModel.selectedText var selected: String? = null
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
selected = fixture.editor.selectionModel.selectedText
}
}
assertEquals(expected, selected) assertEquals(expected, selected)
} }
@ -890,7 +908,9 @@ abstract class VimNoWriteActionTestCase {
protected fun performTest(keys: String, after: String, modeAfter: Mode) { protected fun performTest(keys: String, after: String, modeAfter: Mode) {
typeText(keys) typeText(keys)
ApplicationManager.getApplication().invokeAndWait {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
}
assertState(after) assertState(after)
assertState(modeAfter) assertState(modeAfter)
} }

View File

@ -9,6 +9,7 @@
package org.jetbrains.plugins.ideavim package org.jetbrains.plugins.ideavim
import com.intellij.ide.IdeEventQueue import com.intellij.ide.IdeEventQueue
import com.intellij.openapi.application.ApplicationManager
import com.intellij.testFramework.fixtures.CodeInsightTestFixture import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.util.containers.toArray import com.intellij.util.containers.toArray
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
@ -55,14 +56,16 @@ annotation class VimBehaviorDiffers(
val shouldBeFixed: Boolean = true, val shouldBeFixed: Boolean = true,
) )
inline fun waitAndAssert(timeInMillis: Int = 1000, condition: () -> Boolean) { inline fun waitAndAssert(timeInMillis: Int = 1000, crossinline condition: () -> Boolean) {
ApplicationManager.getApplication().invokeAndWait {
val end = System.currentTimeMillis() + timeInMillis val end = System.currentTimeMillis() + timeInMillis
while (end > System.currentTimeMillis()) { while (end > System.currentTimeMillis()) {
Thread.sleep(10) Thread.sleep(10)
IdeEventQueue.getInstance().flushQueue() IdeEventQueue.getInstance().flushQueue()
if (condition()) return if (condition()) return@invokeAndWait
} }
fail() fail()
}
} }
fun assertHappened(timeInMillis: Int = 1000, precision: Int, condition: () -> Boolean) { fun assertHappened(timeInMillis: Int = 1000, precision: Int, condition: () -> Boolean) {
@ -72,6 +75,7 @@ fun assertHappened(timeInMillis: Int = 1000, precision: Int, condition: () -> Bo
} }
fun assertDoesntChange(timeInMillis: Int = 1000, condition: () -> Boolean) { fun assertDoesntChange(timeInMillis: Int = 1000, condition: () -> Boolean) {
ApplicationManager.getApplication().invokeAndWait {
val end = System.currentTimeMillis() + timeInMillis val end = System.currentTimeMillis() + timeInMillis
while (end > System.currentTimeMillis()) { while (end > System.currentTimeMillis()) {
if (!condition()) { if (!condition()) {
@ -81,6 +85,7 @@ fun assertDoesntChange(timeInMillis: Int = 1000, condition: () -> Boolean) {
Thread.sleep(10) Thread.sleep(10)
IdeEventQueue.getInstance().flushQueue() IdeEventQueue.getInstance().flushQueue()
} }
}
} }
internal fun <T, S, V> Collection<T>.cartesianProduct( internal fun <T, S, V> Collection<T>.cartesianProduct(

View File

@ -10,6 +10,6 @@ package org.jetbrains.plugins.ideavim
import com.intellij.ide.highlighter.JavaFileType import com.intellij.ide.highlighter.JavaFileType
abstract class VimJavaTestCase : VimTestCase() { abstract class VimJavaTestCase : VimNoWriteActionTestCase() {
protected fun configureByJavaText(content: String) = configureByText(JavaFileType.INSTANCE, content) protected fun configureByJavaText(content: String) = configureByText(JavaFileType.INSTANCE, content)
} }

View File

@ -10,6 +10,7 @@ package org.jetbrains.plugins.ideavim.action
import com.intellij.codeInsight.folding.CodeFoldingManager import com.intellij.codeInsight.folding.CodeFoldingManager
import com.intellij.codeInsight.folding.impl.FoldingUtil import com.intellij.codeInsight.folding.impl.FoldingUtil
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import org.jetbrains.plugins.ideavim.SkipNeovimReason import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim import org.jetbrains.plugins.ideavim.TestWithoutNeovim
@ -135,13 +136,25 @@ and some text after""",
and some text after and some text after
""".trimIndent(), """.trimIndent(),
) )
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runWriteAction {
CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor) CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor)
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, true) assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, true)
}
}
typeText(injector.parser.parseKeys("za")) typeText(injector.parser.parseKeys("za"))
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runWriteAction {
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, false) assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, false)
}
}
typeText(injector.parser.parseKeys("za")) typeText(injector.parser.parseKeys("za"))
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runWriteAction {
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, true) assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, true)
} }
}
}
// VIM-287 |zc| |o| // VIM-287 |zc| |o|
@TestWithoutNeovim(SkipNeovimReason.FOLDING) @TestWithoutNeovim(SkipNeovimReason.FOLDING)
@ -158,10 +171,12 @@ and some text after""",
""".trimIndent(), """.trimIndent(),
) )
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.foldingModel.runBatchFoldingOperation { fixture.editor.foldingModel.runBatchFoldingOperation {
CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor) CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor)
FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded = false FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded = false
} }
}
typeText(injector.parser.parseKeys("o")) typeText(injector.parser.parseKeys("o"))
assertState( assertState(

View File

@ -10,6 +10,7 @@ package org.jetbrains.plugins.ideavim.action.change.insert
import com.intellij.codeInsight.folding.CodeFoldingManager import com.intellij.codeInsight.folding.CodeFoldingManager
import com.intellij.codeInsight.folding.impl.FoldingUtil import com.intellij.codeInsight.folding.impl.FoldingUtil
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import org.jetbrains.plugins.ideavim.SkipNeovimReason import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim import org.jetbrains.plugins.ideavim.TestWithoutNeovim
@ -30,10 +31,12 @@ bar
""", """,
) )
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.foldingModel.runBatchFoldingOperation { fixture.editor.foldingModel.runBatchFoldingOperation {
CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor) CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor)
FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded = false FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded = false
} }
}
typeText(injector.parser.parseKeys("j" + "<C-V>" + "j" + "I" + "X" + "<Esc>")) typeText(injector.parser.parseKeys("j" + "<C-V>" + "j" + "I" + "X" + "<Esc>"))
assertState( assertState(

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.motion.search package org.jetbrains.plugins.ideavim.action.motion.search
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.getVisualLineCount import com.maddyhome.idea.vim.api.getVisualLineCount
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
import org.jetbrains.plugins.ideavim.VimJavaTestCase import org.jetbrains.plugins.ideavim.VimJavaTestCase
@ -26,14 +27,18 @@ class SearchAgainNextActionJavaTest : VimJavaTestCase() {
""".trimIndent() """.trimIndent()
) )
ApplicationManager.getApplication().invokeAndWait {
val foldingModel = fixture.editor.foldingModel val foldingModel = fixture.editor.foldingModel
foldingModel.runBatchFoldingOperation { foldingModel.runBatchFoldingOperation {
val foldRegion = foldingModel.addFoldRegion(61, 71, "pupa") val foldRegion = foldingModel.addFoldRegion(61, 71, "pupa")
foldRegion!!.isExpanded = false foldRegion!!.isExpanded = false
} }
assertEquals(2, fixture.editor.vim.getVisualLineCount()) assertEquals(2, fixture.editor.vim.getVisualLineCount())
}
typeText("/pupa<CR>") typeText("/pupa<CR>")
ApplicationManager.getApplication().invokeAndWait {
assertEquals(4, fixture.editor.vim.getVisualLineCount()) assertEquals(4, fixture.editor.vim.getVisualLineCount())
} }
}
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.motion.updown package org.jetbrains.plugins.ideavim.action.motion.updown
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.getVisualLineCount import com.maddyhome.idea.vim.api.getVisualLineCount
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
import org.jetbrains.plugins.ideavim.VimJavaTestCase import org.jetbrains.plugins.ideavim.VimJavaTestCase
@ -24,14 +25,18 @@ class MotionDownActionJavaTest : VimJavaTestCase() {
*/ */
""".trimIndent()) """.trimIndent())
ApplicationManager.getApplication().invokeAndWait {
val foldingModel = fixture.editor.foldingModel val foldingModel = fixture.editor.foldingModel
foldingModel.runBatchFoldingOperation { foldingModel.runBatchFoldingOperation {
val foldRegion = foldingModel.addFoldRegion(61, 71, "pupa") val foldRegion = foldingModel.addFoldRegion(61, 71, "pupa")
foldRegion!!.isExpanded = false foldRegion!!.isExpanded = false
} }
assertEquals(2, fixture.editor.vim.getVisualLineCount()) assertEquals(2, fixture.editor.vim.getVisualLineCount())
}
typeText("gg" + "$" + "j") typeText("gg" + "$" + "j")
ApplicationManager.getApplication().invokeAndWait {
assertEquals(2, fixture.editor.vim.getVisualLineCount()) assertEquals(2, fixture.editor.vim.getVisualLineCount())
} }
}
} }

View File

@ -9,9 +9,9 @@
package org.jetbrains.plugins.ideavim.ex.implementation.commands package org.jetbrains.plugins.ideavim.ex.implementation.commands
import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.textarea.TextComponentEditorImpl import com.intellij.openapi.editor.textarea.TextComponentEditorImpl
import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.Disposer
import com.intellij.testFramework.TestLoggerFactory
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.ex.ExException import com.maddyhome.idea.vim.ex.ExException
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
@ -178,6 +178,7 @@ class MapCommandJavaTest : VimJavaTestCase() {
typeText(commandToKeys("map kk l")) typeText(commandToKeys("map kk l"))
typeText(injector.parser.parseKeys("k")) typeText(injector.parser.parseKeys("k"))
ApplicationManager.getApplication().invokeAndWait {
checkDelayedMapping( checkDelayedMapping(
text, text,
""" """
@ -188,6 +189,7 @@ class MapCommandJavaTest : VimJavaTestCase() {
""".trimIndent(), """.trimIndent(),
) )
} }
}
@TestWithoutNeovim(reason = SkipNeovimReason.DIFFERENT) @TestWithoutNeovim(reason = SkipNeovimReason.DIFFERENT)
@Test @Test
@ -204,6 +206,7 @@ class MapCommandJavaTest : VimJavaTestCase() {
typeText(commandToKeys("map kk l")) typeText(commandToKeys("map kk l"))
typeText(injector.parser.parseKeys("k")) typeText(injector.parser.parseKeys("k"))
ApplicationManager.getApplication().invokeAndWait {
checkDelayedMapping( checkDelayedMapping(
text, text,
""" """
@ -214,6 +217,7 @@ class MapCommandJavaTest : VimJavaTestCase() {
""".trimIndent(), """.trimIndent(),
) )
} }
}
@TestWithoutNeovim(SkipNeovimReason.DIFFERENT) @TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test @Test
@ -233,6 +237,7 @@ class MapCommandJavaTest : VimJavaTestCase() {
typeText(commandToKeys("map jz w")) typeText(commandToKeys("map jz w"))
typeText(injector.parser.parseKeys("k")) typeText(injector.parser.parseKeys("k"))
ApplicationManager.getApplication().invokeAndWait {
checkDelayedMapping( checkDelayedMapping(
text, text,
""" """
@ -243,6 +248,7 @@ class MapCommandJavaTest : VimJavaTestCase() {
""".trimIndent(), """.trimIndent(),
) )
} }
}
@Test @Test
fun `test execute mapping with a delay and second mapping and another starting mappings with another key`() { fun `test execute mapping with a delay and second mapping and another starting mappings with another key`() {
@ -349,10 +355,10 @@ class MapCommandJavaTest : VimJavaTestCase() {
indicateErrors = true, indicateErrors = true,
null, null,
) )
val exception = assertThrowsLogError<TestLoggerFactory.TestLoggerAssertionError> { val exception = assertThrowsLogError<Throwable> {
typeText(injector.parser.parseKeys("t")) typeText(injector.parser.parseKeys("t"))
} }
assertIs<ExException>(exception.cause) // Exception is wrapped into LOG.error twice assertIs<ExException>(exception.cause!!.cause) // Exception is wrapped into LOG.error twice
assertPluginError(true) assertPluginError(true)
assertPluginErrorMessageContains("E121: Undefined variable: s:mapping") assertPluginErrorMessageContains("E121: Undefined variable: s:mapping")
@ -374,6 +380,7 @@ class MapCommandJavaTest : VimJavaTestCase() {
typeText(commandToKeys("map kk h")) typeText(commandToKeys("map kk h"))
typeText(injector.parser.parseKeys("kk")) typeText(injector.parser.parseKeys("kk"))
ApplicationManager.getApplication().invokeAndWait {
checkDelayedMapping( checkDelayedMapping(
text, text,
""" """
@ -383,6 +390,7 @@ class MapCommandJavaTest : VimJavaTestCase() {
----- -----
""".trimIndent(), """.trimIndent(),
) )
}
assertMode(Mode.NORMAL()) assertMode(Mode.NORMAL())
} }
@ -397,10 +405,11 @@ class MapCommandJavaTest : VimJavaTestCase() {
""".trimIndent() """.trimIndent()
configureByJavaText(text) configureByJavaText(text)
assertThrowsLogError<ExException> { val exception = assertThrowsLogError<Throwable> {
typeText(commandToKeys("inoremap <expr> <cr> unknownFunction() ? '\\<C-y>' : '\\<C-g>u\\<CR>'")) typeText(commandToKeys("inoremap <expr> <cr> unknownFunction() ? '\\<C-y>' : '\\<C-g>u\\<CR>'"))
typeText(injector.parser.parseKeys("i<CR>")) typeText(injector.parser.parseKeys("i<CR>"))
} }
assertIs<ExException>(exception.cause)
assertPluginError(true) assertPluginError(true)
assertPluginErrorMessageContains("E117: Unknown function: unknownFunction") assertPluginErrorMessageContains("E117: Unknown function: unknownFunction")

View File

@ -16,7 +16,9 @@ import com.intellij.codeInsight.template.TemplateManager
import com.intellij.codeInsight.template.impl.TemplateManagerImpl import com.intellij.codeInsight.template.impl.TemplateManagerImpl
import com.intellij.ide.DataManager import com.intellij.ide.DataManager
import com.intellij.injected.editor.EditorWindow import com.intellij.injected.editor.EditorWindow
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler
import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.fixtures.CodeInsightTestUtil.doInlineRename import com.intellij.testFramework.fixtures.CodeInsightTestUtil.doInlineRename
@ -65,7 +67,9 @@ class TemplateTest : VimJavaTestCase() {
} }
""".trimIndent(), """.trimIndent(),
) )
ApplicationManager.getApplication().invokeAndWait {
doInlineRename(VariableInplaceRenameHandler(), "myNewVar", fixture) doInlineRename(VariableInplaceRenameHandler(), "myNewVar", fixture)
}
assertState( assertState(
""" """
class Hello { class Hello {
@ -143,7 +147,9 @@ class TemplateTest : VimJavaTestCase() {
waitAndAssertMode(fixture, Mode.SELECT(SelectionType.CHARACTER_WISE)) waitAndAssertMode(fixture, Mode.SELECT(SelectionType.CHARACTER_WISE))
assertState(Mode.SELECT(SelectionType.CHARACTER_WISE)) assertState(Mode.SELECT(SelectionType.CHARACTER_WISE))
ApplicationManager.getApplication().invokeAndWait {
LookupManager.hideActiveLookup(fixture.project) LookupManager.hideActiveLookup(fixture.project)
}
typeText(injector.parser.parseKeys("<Left>")) typeText(injector.parser.parseKeys("<Left>"))
assertState(Mode.INSERT) assertState(Mode.INSERT)
typeText(injector.parser.parseKeys("pre" + "<CR>")) typeText(injector.parser.parseKeys("pre" + "<CR>"))
@ -176,7 +182,9 @@ class TemplateTest : VimJavaTestCase() {
waitAndAssertMode(fixture, Mode.SELECT(SelectionType.CHARACTER_WISE)) waitAndAssertMode(fixture, Mode.SELECT(SelectionType.CHARACTER_WISE))
assertState(Mode.SELECT(SelectionType.CHARACTER_WISE)) assertState(Mode.SELECT(SelectionType.CHARACTER_WISE))
ApplicationManager.getApplication().invokeAndWait {
LookupManager.hideActiveLookup(fixture.project) LookupManager.hideActiveLookup(fixture.project)
}
typeText(injector.parser.parseKeys("<Right>")) typeText(injector.parser.parseKeys("<Right>"))
assertState(Mode.INSERT) assertState(Mode.INSERT)
assertState( assertState(
@ -206,7 +214,9 @@ class TemplateTest : VimJavaTestCase() {
waitAndAssertMode(fixture, Mode.SELECT(SelectionType.CHARACTER_WISE)) waitAndAssertMode(fixture, Mode.SELECT(SelectionType.CHARACTER_WISE))
assertState(Mode.SELECT(SelectionType.CHARACTER_WISE)) assertState(Mode.SELECT(SelectionType.CHARACTER_WISE))
ApplicationManager.getApplication().invokeAndWait {
LookupManager.hideActiveLookup(fixture.project) LookupManager.hideActiveLookup(fixture.project)
}
typeText(injector.parser.parseKeys("<Left>")) typeText(injector.parser.parseKeys("<Left>"))
assertState(Mode.INSERT) assertState(Mode.INSERT)
assertState( assertState(
@ -236,7 +246,9 @@ class TemplateTest : VimJavaTestCase() {
waitAndAssertMode(fixture, Mode.SELECT(SelectionType.CHARACTER_WISE)) waitAndAssertMode(fixture, Mode.SELECT(SelectionType.CHARACTER_WISE))
assertState(Mode.SELECT(SelectionType.CHARACTER_WISE)) assertState(Mode.SELECT(SelectionType.CHARACTER_WISE))
ApplicationManager.getApplication().invokeAndWait {
LookupManager.hideActiveLookup(fixture.project) LookupManager.hideActiveLookup(fixture.project)
}
typeText(injector.parser.parseKeys("<Right>")) typeText(injector.parser.parseKeys("<Right>"))
assertState(Mode.INSERT) assertState(Mode.INSERT)
assertState( assertState(
@ -527,8 +539,12 @@ class TemplateTest : VimJavaTestCase() {
template.addVariable("V1", "", "\"123\"", true) template.addVariable("V1", "", "\"123\"", true)
template.addVariable("V2", "", "\"239\"", true) template.addVariable("V2", "", "\"239\"", true)
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runWriteAction {
manager.startTemplate(fixture.editor, template) manager.startTemplate(fixture.editor, template)
}
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
}
assertMode(Mode.NORMAL()) assertMode(Mode.NORMAL())
assertOffset(2) assertOffset(2)
@ -555,7 +571,9 @@ class TemplateTest : VimJavaTestCase() {
) )
startRenaming(VariableInplaceRenameHandler()) startRenaming(VariableInplaceRenameHandler())
val lookupValue = fixture.lookupElementStrings?.get(0) ?: kotlin.test.fail() val lookupValue = fixture.lookupElementStrings?.get(0) ?: kotlin.test.fail()
ApplicationManager.getApplication().invokeAndWait {
fixture.finishLookup(Lookup.NORMAL_SELECT_CHAR) fixture.finishLookup(Lookup.NORMAL_SELECT_CHAR)
}
assertState( assertState(
""" """
class Hello { class Hello {
@ -570,7 +588,15 @@ class TemplateTest : VimJavaTestCase() {
private fun startRenaming(handler: VariableInplaceRenameHandler): Editor { private fun startRenaming(handler: VariableInplaceRenameHandler): Editor {
val editor = if (fixture.editor is EditorWindow) (fixture.editor as EditorWindow).delegate else fixture.editor val editor = if (fixture.editor is EditorWindow) (fixture.editor as EditorWindow).delegate else fixture.editor
handler.doRename(fixture.elementAtCaret, editor, dataContext) var elementToRename: PsiElement? = null
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
elementToRename = fixture.elementAtCaret
}
ApplicationManager.getApplication().runWriteAction {
handler.doRename(elementToRename!!, editor, dataContext)
}
}
return editor return editor
} }