mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-25 00:34:09 +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 keyHandler = KeyHandler.getInstance()
|
||||||
val dataContext = injector.executionContextManager.getEditorExecutionContext(editor.vim)
|
val dataContext = injector.executionContextManager.getEditorExecutionContext(editor.vim)
|
||||||
TestInputModel.getInstance(editor).setKeyStrokes(keys.filterNotNull())
|
TestInputModel.getInstance(editor).setKeyStrokes(keys.filterNotNull())
|
||||||
injector.actionExecutor.executeCommand(
|
ApplicationManager.getApplication().invokeAndWait {
|
||||||
editor.vim,
|
injector.actionExecutor.executeCommand(
|
||||||
Runnable {
|
editor.vim,
|
||||||
val inputModel = TestInputModel.getInstance(editor)
|
Runnable {
|
||||||
var key = inputModel.nextKeyStroke()
|
val inputModel = TestInputModel.getInstance(editor)
|
||||||
while (key != null) {
|
var key = inputModel.nextKeyStroke()
|
||||||
keyHandler.handleKey(editor.vim, key, dataContext, keyHandler.keyHandlerState)
|
while (key != null) {
|
||||||
key = inputModel.nextKeyStroke()
|
keyHandler.handleKey(editor.vim, key, dataContext, keyHandler.keyHandlerState)
|
||||||
}
|
key = inputModel.nextKeyStroke()
|
||||||
},
|
}
|
||||||
null,
|
},
|
||||||
null,
|
null,
|
||||||
)
|
null,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
package org.jetbrains.plugins.ideavim.propertybased
|
package org.jetbrains.plugins.ideavim.propertybased
|
||||||
|
|
||||||
import com.intellij.ide.IdeEventQueue
|
import com.intellij.ide.IdeEventQueue
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.testFramework.PlatformTestUtil
|
import com.intellij.testFramework.PlatformTestUtil
|
||||||
import com.maddyhome.idea.vim.KeyHandler
|
import com.maddyhome.idea.vim.KeyHandler
|
||||||
@ -36,12 +37,16 @@ class RandomActionsPropertyTest : VimPropertyTestBase() {
|
|||||||
PropertyChecker.checkScenarios {
|
PropertyChecker.checkScenarios {
|
||||||
ImperativeCommand { env ->
|
ImperativeCommand { env ->
|
||||||
val editor = configureByText(text)
|
val editor = configureByText(text)
|
||||||
KeyHandler.getInstance().fullReset(editor.vim)
|
ApplicationManager.getApplication().invokeAndWait {
|
||||||
|
KeyHandler.getInstance().fullReset(editor.vim)
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
moveCaretToRandomPlace(env, editor)
|
moveCaretToRandomPlace(env, editor)
|
||||||
env.executeCommands(Generator.sampledFrom(AvailableActions(editor)))
|
env.executeCommands(Generator.sampledFrom(AvailableActions(editor)))
|
||||||
} finally {
|
} finally {
|
||||||
reset(editor)
|
ApplicationManager.getApplication().invokeAndWait {
|
||||||
|
reset(editor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,12 +57,16 @@ class RandomActionsPropertyTest : VimPropertyTestBase() {
|
|||||||
PropertyChecker.checkScenarios {
|
PropertyChecker.checkScenarios {
|
||||||
ImperativeCommand { env ->
|
ImperativeCommand { env ->
|
||||||
val editor = configureByText(loremText)
|
val editor = configureByText(loremText)
|
||||||
KeyHandler.getInstance().fullReset(editor.vim)
|
ApplicationManager.getApplication().invokeAndWait {
|
||||||
|
KeyHandler.getInstance().fullReset(editor.vim)
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
moveCaretToRandomPlace(env, editor)
|
moveCaretToRandomPlace(env, editor)
|
||||||
env.executeCommands(Generator.sampledFrom(AvailableActions(editor)))
|
env.executeCommands(Generator.sampledFrom(AvailableActions(editor)))
|
||||||
} finally {
|
} finally {
|
||||||
reset(editor)
|
ApplicationManager.getApplication().invokeAndWait {
|
||||||
|
reset(editor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,12 +77,16 @@ class RandomActionsPropertyTest : VimPropertyTestBase() {
|
|||||||
PropertyChecker.checkScenarios {
|
PropertyChecker.checkScenarios {
|
||||||
ImperativeCommand { env ->
|
ImperativeCommand { env ->
|
||||||
val editor = configureByJavaText(javaText)
|
val editor = configureByJavaText(javaText)
|
||||||
KeyHandler.getInstance().fullReset(editor.vim)
|
ApplicationManager.getApplication().invokeAndWait {
|
||||||
|
KeyHandler.getInstance().fullReset(editor.vim)
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
moveCaretToRandomPlace(env, editor)
|
moveCaretToRandomPlace(env, editor)
|
||||||
env.executeCommands(Generator.sampledFrom(AvailableActions(editor)))
|
env.executeCommands(Generator.sampledFrom(AvailableActions(editor)))
|
||||||
} finally {
|
} 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 ""}")
|
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)
|
VimTestCase.typeText(listOf(usedKey), editor, editor.project)
|
||||||
|
|
||||||
IdeEventQueue.getInstance().flushQueue()
|
ApplicationManager.getApplication().invokeAndWait {
|
||||||
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
|
IdeEventQueue.getInstance().flushQueue()
|
||||||
|
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val esc = key("<Esc>")
|
private val esc = key("<Esc>")
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
package org.jetbrains.plugins.ideavim.propertybased
|
package org.jetbrains.plugins.ideavim.propertybased
|
||||||
|
|
||||||
import com.intellij.ide.highlighter.JavaFileType
|
import com.intellij.ide.highlighter.JavaFileType
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.maddyhome.idea.vim.KeyHandler
|
import com.maddyhome.idea.vim.KeyHandler
|
||||||
import com.maddyhome.idea.vim.VimPlugin
|
import com.maddyhome.idea.vim.VimPlugin
|
||||||
@ -20,7 +21,11 @@ import org.jetbrains.plugins.ideavim.VimTestCase
|
|||||||
abstract class VimPropertyTestBase : VimTestCase() {
|
abstract class VimPropertyTestBase : VimTestCase() {
|
||||||
protected fun moveCaretToRandomPlace(env: ImperativeCommand.Environment, editor: Editor) {
|
protected fun moveCaretToRandomPlace(env: ImperativeCommand.Environment, editor: Editor) {
|
||||||
val pos = env.generateValue(Generator.integers(0, editor.document.textLength - 1), "Put caret at position %s")
|
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) {
|
protected fun reset(editor: Editor) {
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
package org.jetbrains.plugins.ideavim.propertybased
|
package org.jetbrains.plugins.ideavim.propertybased
|
||||||
|
|
||||||
import com.intellij.ide.IdeEventQueue
|
import com.intellij.ide.IdeEventQueue
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.testFramework.PlatformTestUtil
|
import com.intellij.testFramework.PlatformTestUtil
|
||||||
import com.maddyhome.idea.vim.api.injector
|
import com.maddyhome.idea.vim.api.injector
|
||||||
@ -29,7 +30,9 @@ class YankDeletePropertyTest : VimPropertyTestBase() {
|
|||||||
moveCaretToRandomPlace(env, editor)
|
moveCaretToRandomPlace(env, editor)
|
||||||
env.executeCommands(Generator.sampledFrom(YankDeleteActions(editor)))
|
env.executeCommands(Generator.sampledFrom(YankDeleteActions(editor)))
|
||||||
} finally {
|
} 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")
|
env.logMessage("Use command: $key")
|
||||||
VimTestCase.typeText(injector.parser.parseKeys(key), editor, editor.project)
|
VimTestCase.typeText(injector.parser.parseKeys(key), editor, editor.project)
|
||||||
|
|
||||||
IdeEventQueue.getInstance().flushQueue()
|
ApplicationManager.getApplication().invokeAndWait {
|
||||||
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
|
IdeEventQueue.getInstance().flushQueue()
|
||||||
|
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user