Skip to content

Commit

Permalink
Remove IdeaVimTestCase and replace it with VimTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPl292 committed Feb 21, 2025
1 parent 564ab7d commit 3866565
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import com.maddyhome.idea.vim.vimscript.model.datatypes.VimInt
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.IdeaVimTestCase
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.waitUntil
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
Expand All @@ -46,7 +46,7 @@ private const val defaultValue = "defaultValue"
private const val defaultNumberValue = 10

@TestWithoutNeovim(reason = SkipNeovimReason.OPTION)
class EffectiveOptionChangeListenerTest : IdeaVimTestCase() {
class EffectiveOptionChangeListenerTest : VimTestCase() {
private val optionName = "test"
private lateinit var manager: FileEditorManagerImpl
private lateinit var otherBufferWindow: Editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.maddyhome.idea.vim.options.StringOption
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.IdeaVimTestCase
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.waitUntil
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
Expand All @@ -43,7 +43,7 @@ import kotlin.test.assertEquals

// Tests the implementation of global, local to buffer, local to window and global-local
@TestWithoutNeovim(reason = SkipNeovimReason.OPTION)
class OptionDeclaredScopeTest : IdeaVimTestCase() {
class OptionDeclaredScopeTest : VimTestCase() {
private val optionName = "test"
private val defaultValue = VimString("defaultValue")
private val setValue = VimString("setValue")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
import com.intellij.testFramework.replaceService
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.IdeaVimTestCase
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.waitUntil
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
Expand All @@ -38,7 +38,7 @@ import javax.swing.SwingConstants
import kotlin.test.assertEquals

@TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
class TextWidthOptionMapperTest : IdeaVimTestCase() {
class TextWidthOptionMapperTest : VimTestCase() {

// IntelliJ can have a margin set, but not act on it. We want to maintain this, not least because the right margin
// visual guide is shown by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,42 +111,11 @@ import kotlin.test.assertTrue
* To plugin writers: this class is internal, thus not allowed to be used by third-party plugins.
* This is done as we have no mechanism to guarantee compatibility as we update this test case.
* Feel free to copy this class into your plugin, or copy just needed functions.
*
* The tests are started on non-EDT thread without any locks.
*/
@ApiStatus.Internal
abstract class VimTestCase : IdeaVimTestCase() {
object Checks {
var caretShape: Boolean = true

val neoVim = NeoVim()

var keyHandler = KeyHandlerMethod.VIA_IDE

fun reset() {
caretShape = true

neoVim.reset()
keyHandler = KeyHandlerMethod.VIA_IDE
}

class NeoVim {
var ignoredRegisters: Set<Char> = setOf()
var exitOnTearDown = true

fun reset() {
ignoredRegisters = setOf()
exitOnTearDown = true
}
}

enum class KeyHandlerMethod {
VIA_IDE,
DIRECT_TO_VIM,
}
}
}

@ApiStatus.Internal
abstract class IdeaVimTestCase {
abstract class VimTestCase {
protected lateinit var fixture: CodeInsightTestFixture

lateinit var testInfo: TestInfo
Expand Down Expand Up @@ -1055,6 +1024,36 @@ abstract class IdeaVimTestCase {
class EditorAction(val name: String) : CharType
}

object Checks {
var caretShape: Boolean = true

val neoVim = NeoVim()

var keyHandler = KeyHandlerMethod.VIA_IDE

fun reset() {
caretShape = true

neoVim.reset()
keyHandler = KeyHandlerMethod.VIA_IDE
}

class NeoVim {
var ignoredRegisters: Set<Char> = setOf()
var exitOnTearDown = true

fun reset() {
ignoredRegisters = setOf()
exitOnTearDown = true
}
}

enum class KeyHandlerMethod {
VIA_IDE,
DIRECT_TO_VIM,
}
}

companion object {
const val c = EditorTestUtil.CARET_TAG
const val s = EditorTestUtil.SELECTION_START_TAG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ package org.jetbrains.plugins.ideavim

import com.intellij.ide.highlighter.JavaFileType

abstract class VimJavaTestCase : IdeaVimTestCase() {
abstract class VimJavaTestCase : VimTestCase() {
protected fun configureByJavaText(content: String) = configureByText(JavaFileType.INSTANCE, content)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import org.jetbrains.jetCheck.PropertyChecker
import org.jetbrains.plugins.ideavim.NeovimTesting
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.IdeaVimTestCase
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
import kotlin.math.absoluteValue
Expand Down Expand Up @@ -76,7 +75,7 @@ private class IncrementDecrementActions(private val editor: Editor, val test: Vi
val key = env.generateValue(generator, null)
val action = injector.parser.parseKeys(key).single()
env.logMessage("Use command: ${injector.parser.toKeyNotation(action)}.")
IdeaVimTestCase.typeText(listOf(action), editor, editor.project)
VimTestCase.typeText(listOf(action), editor, editor.project)
NeovimTesting.typeCommand(key, test.testInfo, editor)

IdeEventQueue.getInstance().flushQueue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.maddyhome.idea.vim.newapi.vim
import org.jetbrains.jetCheck.Generator
import org.jetbrains.jetCheck.ImperativeCommand
import org.jetbrains.jetCheck.PropertyChecker
import org.jetbrains.plugins.ideavim.IdeaVimTestCase
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.propertybased.samples.javaText
import org.jetbrains.plugins.ideavim.propertybased.samples.loremText
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -108,7 +108,7 @@ private class AvailableActions(private val editor: Editor) : ImperativeCommand {
val usedKey = env.generateValue(keyGenerator, null)
val node = trie.getTrieNode(currentKeys + usedKey)
env.logMessage("Use command: ${injector.parser.toKeyNotation(currentKeys + usedKey)}. ${if (node?.data != null) "Action: ${node.data!!.actionId}" else ""}")
IdeaVimTestCase.typeText(listOf(usedKey), editor, editor.project)
VimTestCase.typeText(listOf(usedKey), editor, editor.project)

IdeEventQueue.getInstance().flushQueue()
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.maddyhome.idea.vim.api.injector
import org.jetbrains.jetCheck.Generator
import org.jetbrains.jetCheck.ImperativeCommand
import org.jetbrains.jetCheck.PropertyChecker
import org.jetbrains.plugins.ideavim.IdeaVimTestCase
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.propertybased.samples.loremText
import org.junit.jupiter.api.Test

Expand All @@ -41,7 +41,7 @@ private class YankDeleteActions(private val editor: Editor) : ImperativeCommand
val key = env.generateValue(Generator.sampledFrom(keysList), null)

env.logMessage("Use command: $key")
IdeaVimTestCase.typeText(injector.parser.parseKeys(key), editor, editor.project)
VimTestCase.typeText(injector.parser.parseKeys(key), editor, editor.project)

IdeEventQueue.getInstance().flushQueue()
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
Expand Down

0 comments on commit 3866565

Please sign in to comment.