1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-25 09:34:08 +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)
setDefaultIntelliJSettings(fixture.editor) // Note: Change to coroutines
ApplicationManager.getApplication().invokeAndWait {
setDefaultIntelliJSettings(fixture.editor)
}
NeovimTesting.setupEditor(fixture.editor, testInfo) NeovimTesting.setupEditor(fixture.editor, testInfo)
setEditorVisibleSize(screenWidth, screenHeight) // Note: Change to coroutines
ApplicationManager.getApplication().invokeAndWait {
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,8 +612,10 @@ abstract class VimNoWriteActionTestCase {
) )
} }
assertEquals(expectedOffsets.size, carets.size, "Wrong amount of carets") assertEquals(expectedOffsets.size, carets.size, "Wrong amount of carets")
for (i in expectedOffsets.indices) { ApplicationManager.getApplication().runReadAction {
assertEquals(expectedOffsets[i], carets[i].offset) for (i in expectedOffsets.indices) {
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)
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() ApplicationManager.getApplication().invokeAndWait {
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) {
val end = System.currentTimeMillis() + timeInMillis ApplicationManager.getApplication().invokeAndWait {
while (end > System.currentTimeMillis()) { val end = System.currentTimeMillis() + timeInMillis
Thread.sleep(10) while (end > System.currentTimeMillis()) {
IdeEventQueue.getInstance().flushQueue() Thread.sleep(10)
if (condition()) return IdeEventQueue.getInstance().flushQueue()
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,14 +75,16 @@ fun assertHappened(timeInMillis: Int = 1000, precision: Int, condition: () -> Bo
} }
fun assertDoesntChange(timeInMillis: Int = 1000, condition: () -> Boolean) { fun assertDoesntChange(timeInMillis: Int = 1000, condition: () -> Boolean) {
val end = System.currentTimeMillis() + timeInMillis ApplicationManager.getApplication().invokeAndWait {
while (end > System.currentTimeMillis()) { val end = System.currentTimeMillis() + timeInMillis
if (!condition()) { while (end > System.currentTimeMillis()) {
fail() if (!condition()) {
} fail()
}
Thread.sleep(10) Thread.sleep(10)
IdeEventQueue.getInstance().flushQueue() IdeEventQueue.getInstance().flushQueue()
}
} }
} }

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,12 +136,24 @@ and some text after""",
and some text after and some text after
""".trimIndent(), """.trimIndent(),
) )
CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor) ApplicationManager.getApplication().invokeAndWait {
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, true) ApplicationManager.getApplication().runWriteAction {
CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor)
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, true)
}
}
typeText(injector.parser.parseKeys("za")) typeText(injector.parser.parseKeys("za"))
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, false) ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runWriteAction {
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, false)
}
}
typeText(injector.parser.parseKeys("za")) typeText(injector.parser.parseKeys("za"))
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, true) ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runWriteAction {
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, true)
}
}
} }
// VIM-287 |zc| |o| // VIM-287 |zc| |o|
@ -158,9 +171,11 @@ and some text after""",
""".trimIndent(), """.trimIndent(),
) )
fixture.editor.foldingModel.runBatchFoldingOperation { ApplicationManager.getApplication().invokeAndWait {
CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor) fixture.editor.foldingModel.runBatchFoldingOperation {
FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded = false CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor)
FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded = false
}
} }
typeText(injector.parser.parseKeys("o")) typeText(injector.parser.parseKeys("o"))

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,9 +31,11 @@ bar
""", """,
) )
fixture.editor.foldingModel.runBatchFoldingOperation { ApplicationManager.getApplication().invokeAndWait {
CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor) fixture.editor.foldingModel.runBatchFoldingOperation {
FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded = false CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor)
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>"))

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()
) )
val foldingModel = fixture.editor.foldingModel ApplicationManager.getApplication().invokeAndWait {
foldingModel.runBatchFoldingOperation { val foldingModel = fixture.editor.foldingModel
val foldRegion = foldingModel.addFoldRegion(61, 71, "pupa") foldingModel.runBatchFoldingOperation {
foldRegion!!.isExpanded = false val foldRegion = foldingModel.addFoldRegion(61, 71, "pupa")
foldRegion!!.isExpanded = false
}
assertEquals(2, fixture.editor.vim.getVisualLineCount())
} }
assertEquals(2, fixture.editor.vim.getVisualLineCount())
typeText("/pupa<CR>") typeText("/pupa<CR>")
assertEquals(4, fixture.editor.vim.getVisualLineCount()) ApplicationManager.getApplication().invokeAndWait {
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())
val foldingModel = fixture.editor.foldingModel ApplicationManager.getApplication().invokeAndWait {
foldingModel.runBatchFoldingOperation { val foldingModel = fixture.editor.foldingModel
val foldRegion = foldingModel.addFoldRegion(61, 71, "pupa") foldingModel.runBatchFoldingOperation {
foldRegion!!.isExpanded = false val foldRegion = foldingModel.addFoldRegion(61, 71, "pupa")
foldRegion!!.isExpanded = false
}
assertEquals(2, fixture.editor.vim.getVisualLineCount())
} }
assertEquals(2, fixture.editor.vim.getVisualLineCount())
typeText("gg" + "$" + "j") typeText("gg" + "$" + "j")
assertEquals(2, fixture.editor.vim.getVisualLineCount()) ApplicationManager.getApplication().invokeAndWait {
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,15 +178,17 @@ class MapCommandJavaTest : VimJavaTestCase() {
typeText(commandToKeys("map kk l")) typeText(commandToKeys("map kk l"))
typeText(injector.parser.parseKeys("k")) typeText(injector.parser.parseKeys("k"))
checkDelayedMapping( ApplicationManager.getApplication().invokeAndWait {
text, checkDelayedMapping(
""" text,
"""
-$c---- -$c----
12345 12345
abcde abcde
----- -----
""".trimIndent(), """.trimIndent(),
) )
}
} }
@TestWithoutNeovim(reason = SkipNeovimReason.DIFFERENT) @TestWithoutNeovim(reason = SkipNeovimReason.DIFFERENT)
@ -204,15 +206,17 @@ class MapCommandJavaTest : VimJavaTestCase() {
typeText(commandToKeys("map kk l")) typeText(commandToKeys("map kk l"))
typeText(injector.parser.parseKeys("k")) typeText(injector.parser.parseKeys("k"))
checkDelayedMapping( ApplicationManager.getApplication().invokeAndWait {
text, checkDelayedMapping(
""" text,
"""
----- -----
12345 12345
a${c}bcde a${c}bcde
----- -----
""".trimIndent(), """.trimIndent(),
) )
}
} }
@TestWithoutNeovim(SkipNeovimReason.DIFFERENT) @TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@ -233,15 +237,17 @@ class MapCommandJavaTest : VimJavaTestCase() {
typeText(commandToKeys("map jz w")) typeText(commandToKeys("map jz w"))
typeText(injector.parser.parseKeys("k")) typeText(injector.parser.parseKeys("k"))
checkDelayedMapping( ApplicationManager.getApplication().invokeAndWait {
text, checkDelayedMapping(
""" text,
"""
----- -----
${c}12345 ${c}12345
abcde abcde
----- -----
""".trimIndent(), """.trimIndent(),
) )
}
} }
@Test @Test
@ -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,15 +380,17 @@ class MapCommandJavaTest : VimJavaTestCase() {
typeText(commandToKeys("map kk h")) typeText(commandToKeys("map kk h"))
typeText(injector.parser.parseKeys("kk")) typeText(injector.parser.parseKeys("kk"))
checkDelayedMapping( ApplicationManager.getApplication().invokeAndWait {
text, checkDelayedMapping(
""" text,
"""
----- -----
${c}12345 ${c}12345
abcde abcde
----- -----
""".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(),
) )
doInlineRename(VariableInplaceRenameHandler(), "myNewVar", fixture) ApplicationManager.getApplication().invokeAndWait {
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))
LookupManager.hideActiveLookup(fixture.project) ApplicationManager.getApplication().invokeAndWait {
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))
LookupManager.hideActiveLookup(fixture.project) ApplicationManager.getApplication().invokeAndWait {
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))
LookupManager.hideActiveLookup(fixture.project) ApplicationManager.getApplication().invokeAndWait {
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))
LookupManager.hideActiveLookup(fixture.project) ApplicationManager.getApplication().invokeAndWait {
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)
manager.startTemplate(fixture.editor, template) ApplicationManager.getApplication().invokeAndWait {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() ApplicationManager.getApplication().runWriteAction {
manager.startTemplate(fixture.editor, template)
}
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()
fixture.finishLookup(Lookup.NORMAL_SELECT_CHAR) ApplicationManager.getApplication().invokeAndWait {
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
} }