mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-04-07 11:15:47 +02:00
Fix threading for property tests
This commit is contained in:
parent
ce01318032
commit
cf49c0b76f
src/testFixtures/kotlin/org/jetbrains/plugins/ideavim
tests/property-tests/src/test/kotlin/org/jetbrains/plugins/ideavim/propertybased
@ -1062,19 +1062,21 @@ abstract class VimTestCase {
|
||||
val keyHandler = KeyHandler.getInstance()
|
||||
val dataContext = injector.executionContextManager.getEditorExecutionContext(editor.vim)
|
||||
TestInputModel.getInstance(editor).setKeyStrokes(keys.filterNotNull())
|
||||
injector.actionExecutor.executeCommand(
|
||||
editor.vim,
|
||||
Runnable {
|
||||
val inputModel = TestInputModel.getInstance(editor)
|
||||
var key = inputModel.nextKeyStroke()
|
||||
while (key != null) {
|
||||
keyHandler.handleKey(editor.vim, key, dataContext, keyHandler.keyHandlerState)
|
||||
key = inputModel.nextKeyStroke()
|
||||
}
|
||||
},
|
||||
null,
|
||||
null,
|
||||
)
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
injector.actionExecutor.executeCommand(
|
||||
editor.vim,
|
||||
Runnable {
|
||||
val inputModel = TestInputModel.getInstance(editor)
|
||||
var key = inputModel.nextKeyStroke()
|
||||
while (key != null) {
|
||||
keyHandler.handleKey(editor.vim, key, dataContext, keyHandler.keyHandlerState)
|
||||
key = inputModel.nextKeyStroke()
|
||||
}
|
||||
},
|
||||
null,
|
||||
null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
@ -9,6 +9,7 @@
|
||||
package org.jetbrains.plugins.ideavim.propertybased
|
||||
|
||||
import com.intellij.ide.IdeEventQueue
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.testFramework.PlatformTestUtil
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
@ -36,12 +37,16 @@ class RandomActionsPropertyTest : VimPropertyTestBase() {
|
||||
PropertyChecker.checkScenarios {
|
||||
ImperativeCommand { env ->
|
||||
val editor = configureByText(text)
|
||||
KeyHandler.getInstance().fullReset(editor.vim)
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
KeyHandler.getInstance().fullReset(editor.vim)
|
||||
}
|
||||
try {
|
||||
moveCaretToRandomPlace(env, editor)
|
||||
env.executeCommands(Generator.sampledFrom(AvailableActions(editor)))
|
||||
} finally {
|
||||
reset(editor)
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
reset(editor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,12 +57,16 @@ class RandomActionsPropertyTest : VimPropertyTestBase() {
|
||||
PropertyChecker.checkScenarios {
|
||||
ImperativeCommand { env ->
|
||||
val editor = configureByText(loremText)
|
||||
KeyHandler.getInstance().fullReset(editor.vim)
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
KeyHandler.getInstance().fullReset(editor.vim)
|
||||
}
|
||||
try {
|
||||
moveCaretToRandomPlace(env, editor)
|
||||
env.executeCommands(Generator.sampledFrom(AvailableActions(editor)))
|
||||
} finally {
|
||||
reset(editor)
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
reset(editor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -68,12 +77,16 @@ class RandomActionsPropertyTest : VimPropertyTestBase() {
|
||||
PropertyChecker.checkScenarios {
|
||||
ImperativeCommand { env ->
|
||||
val editor = configureByJavaText(javaText)
|
||||
KeyHandler.getInstance().fullReset(editor.vim)
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
KeyHandler.getInstance().fullReset(editor.vim)
|
||||
}
|
||||
try {
|
||||
moveCaretToRandomPlace(env, editor)
|
||||
env.executeCommands(Generator.sampledFrom(AvailableActions(editor)))
|
||||
} finally {
|
||||
reset(editor)
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
reset(editor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,8 +123,10 @@ private class AvailableActions(private val editor: Editor) : ImperativeCommand {
|
||||
env.logMessage("Use command: ${injector.parser.toKeyNotation(currentKeys + usedKey)}. ${if (node?.data != null) "Action: ${node.data!!.actionId}" else ""}")
|
||||
VimTestCase.typeText(listOf(usedKey), editor, editor.project)
|
||||
|
||||
IdeEventQueue.getInstance().flushQueue()
|
||||
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
IdeEventQueue.getInstance().flushQueue()
|
||||
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
|
||||
}
|
||||
}
|
||||
|
||||
private val esc = key("<Esc>")
|
||||
|
@ -9,6 +9,7 @@
|
||||
package org.jetbrains.plugins.ideavim.propertybased
|
||||
|
||||
import com.intellij.ide.highlighter.JavaFileType
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
@ -20,7 +21,11 @@ import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
abstract class VimPropertyTestBase : VimTestCase() {
|
||||
protected fun moveCaretToRandomPlace(env: ImperativeCommand.Environment, editor: Editor) {
|
||||
val pos = env.generateValue(Generator.integers(0, editor.document.textLength - 1), "Put caret at position %s")
|
||||
editor.caretModel.currentCaret.vim.moveToOffset(pos)
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
ApplicationManager.getApplication().runReadAction {
|
||||
editor.caretModel.currentCaret.vim.moveToOffset(pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected fun reset(editor: Editor) {
|
||||
|
@ -9,6 +9,7 @@
|
||||
package org.jetbrains.plugins.ideavim.propertybased
|
||||
|
||||
import com.intellij.ide.IdeEventQueue
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.testFramework.PlatformTestUtil
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
@ -29,7 +30,9 @@ class YankDeletePropertyTest : VimPropertyTestBase() {
|
||||
moveCaretToRandomPlace(env, editor)
|
||||
env.executeCommands(Generator.sampledFrom(YankDeleteActions(editor)))
|
||||
} finally {
|
||||
reset(editor)
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
reset(editor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -43,8 +46,10 @@ private class YankDeleteActions(private val editor: Editor) : ImperativeCommand
|
||||
env.logMessage("Use command: $key")
|
||||
VimTestCase.typeText(injector.parser.parseKeys(key), editor, editor.project)
|
||||
|
||||
IdeEventQueue.getInstance().flushQueue()
|
||||
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
IdeEventQueue.getInstance().flushQueue()
|
||||
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user