Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared tests #981

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ dependencies {
testFixturesImplementation("org.junit.jupiter:junit-jupiter-api:5.10.3")
testFixturesImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.3")
testFixturesImplementation("org.junit.jupiter:junit-jupiter-params:5.10.3")
testImplementation(project(":vim-engine", "testArtifacts"))
testFixturesImplementation(project(":vim-engine", "testArtifacts"))

// Temp workaround suggested in https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-faq.html#junit5-test-framework-refers-to-junit4
// Can be removed when IJPL-159134 is fixed
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/com/maddyhome/idea/vim/newapi/IjVimSearchGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,25 @@ import com.intellij.openapi.editor.event.DocumentEvent
import com.intellij.openapi.editor.event.DocumentListener
import com.intellij.openapi.editor.markup.RangeHighlighter
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
import com.intellij.openapi.util.Ref
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.Options
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.VimSearchGroupBase
import com.maddyhome.idea.vim.api.globalOptions
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.Direction
import com.maddyhome.idea.vim.common.Direction.Companion.fromInt
import com.maddyhome.idea.vim.diagnostic.vimLogger
import com.maddyhome.idea.vim.helper.MessageHelper
import com.maddyhome.idea.vim.helper.TestInputModel.Companion.getInstance
import com.maddyhome.idea.vim.helper.addSubstitutionConfirmationHighlight
import com.maddyhome.idea.vim.helper.highlightSearchResults
import com.maddyhome.idea.vim.helper.isCloseKeyStroke
import com.maddyhome.idea.vim.helper.shouldIgnoreCase
import com.maddyhome.idea.vim.helper.updateSearchHighlights
import com.maddyhome.idea.vim.helper.vimLastHighlighters
import com.maddyhome.idea.vim.options.GlobalOptionChangeListener
import com.maddyhome.idea.vim.ui.ModalEntry
import com.maddyhome.idea.vim.vimscript.model.functions.handlers.SubmatchFunctionHandler
import org.jdom.Element
import org.jetbrains.annotations.Contract
import org.jetbrains.annotations.TestOnly
import javax.swing.KeyStroke

@State(
name = "VimSearchSettings",
Expand Down Expand Up @@ -112,21 +104,6 @@ open class IjVimSearchGroup : VimSearchGroupBase(), PersistentStateComponent<Ele
return IjSearchHighlight(ijEditor, highlighter)
}

override fun setLatestMatch(match: String) {
SubmatchFunctionHandler.getInstance().latestMatch = match
}

override fun replaceString(
editor: VimEditor,
startOffset: Int,
endOffset: Int,
newString: String,
) {
ApplicationManager.getApplication().runWriteAction {
(editor as IjVimEditor).editor.document.replaceString(startOffset, endOffset, newString)
}
}

@TestOnly
override fun resetState() {
super.resetState()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"col": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.ColFunctionHandler",
"has": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.HasFunctionHandler",
"line": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.LineFunctionHandler",
"submatch": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.SubmatchFunctionHandler"
"has": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.HasFunctionHandler"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2003-2024 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/

package org.jetbrains.plugins.ideavim

import com.maddyhome.idea.vim.model.SharedTestCase
import com.maddyhome.idea.vim.SharedTestCaseList
import org.jetbrains.plugins.ideavim.action.change.delete.DeleteVisualLinesActionTestImpl
import org.jetbrains.plugins.ideavim.action.change.insert.InsertDeleteActionTestImpl

@Suppress("unused")
class IjSharedTestCaseList : SharedTestCaseList {
override val insertDeleteActionTest: SharedTestCase = InsertDeleteActionTestImpl()
override val deleteVisualLinesActionTest: SharedTestCase = DeleteVisualLinesActionTestImpl()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.jetbrains.plugins.ideavim.impl.OptionTest
import org.jetbrains.plugins.ideavim.impl.VimOption
import org.junit.jupiter.api.Test

class RegisterActionsTest : VimTestCase() {
class RegisterActionsTest : VimTestCaseBase() {
@OptionTest(
VimOption(TestOptionConstants.virtualedit, doesntAffectTest = true),
VimOption(TestOptionConstants.whichwrap, doesntAffectTest = true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ package org.jetbrains.plugins.ideavim.action
import com.intellij.idea.TestFor
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Test

class ActionsTest : VimTestCase() {
class ActionsTest : VimTestCaseBase() {
@Test
@TestFor(issues = ["VIM-3203"])
@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import com.maddyhome.idea.vim.state.mode.SelectionType
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

/**
* @author vlan
*/
class ChangeActionTest : VimTestCase() {
class ChangeActionTest : VimTestCaseBase() {
// VIM-620 |i_CTRL-O|
@Test
fun testInsertSingleCommandAndInserting() {
Expand Down Expand Up @@ -662,7 +662,7 @@ quux
}

// |r|
@VimBehaviorDiffers(originalVimAfter = "foXX${c}Xr\n")
@VimBehaviorDiffers(originalVimAfter = "foXX<caret>Xr\n")
@Test
fun testReplaceMultipleCharsWithCount() {
doTest("3rX", "fo${c}obar\n", "fo${c}XXXr\n", Mode.NORMAL())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ package org.jetbrains.plugins.ideavim.action

import com.google.common.collect.Lists
import com.maddyhome.idea.vim.state.mode.Mode
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Test

class ChangeNumberActionTest : VimTestCase() {
class ChangeNumberActionTest : VimTestCaseBase() {
@Test
fun testIncrementDecimalZero() {
doTest("<C-A>", "0", "1", Mode.NORMAL())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ package org.jetbrains.plugins.ideavim.action
import com.maddyhome.idea.vim.api.injector
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Test

class CommandCountTest : VimTestCase() {
class CommandCountTest : VimTestCaseBase() {
@Test
fun `test count operator motion`() {
configureByText("${c}1234567890")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import com.intellij.idea.TestFor
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.state.mode.Mode
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.jetbrains.plugins.ideavim.waitAndAssert
import org.junit.jupiter.api.Test
import kotlin.test.assertNotNull
Expand All @@ -24,7 +25,7 @@ import kotlin.test.assertTrue
* @author vlan
*/
@Suppress("SpellCheckingInspection")
class CopyActionTest : VimTestCase() {
class CopyActionTest : VimTestCaseBase() {
// |y| |p| |count|
@Test
fun testYankPutCharacters() {
Expand Down Expand Up @@ -184,7 +185,7 @@ class CopyActionTest : VimTestCase() {

""".trimIndent(),
)
kotlin.test.assertEquals(0, editor.caretModel.offset)
kotlin.test.assertEquals(0, editor.ij.caretModel.offset)
}

// VIM-632 |CTRL-V| |v_y| |p|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ package org.jetbrains.plugins.ideavim.action
import com.intellij.idea.TestFor
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Test

class EscapeTest : VimTestCase() {
class EscapeTest : VimTestCaseBase() {
@Test
@TestFor(issues = ["VIM-3190"])
@TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ package org.jetbrains.plugins.ideavim.action
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import org.jetbrains.plugins.ideavim.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Test

class FileGetLocationInfoActionTest : VimTestCase() {
class FileGetLocationInfoActionTest : VimTestCaseBase() {
@VimBehaviorDiffers(originalVimAfter = "Col 1 of 11; Line 1 of 6; Word 1 of 32; Byte 1 of 166")
@Test
fun `test get file info`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.state.mode.Mode
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow

class GuardedBlocksTest : VimTestCase() {
class GuardedBlocksTest : VimTestCaseBase() {
@TestWithoutNeovim(reason = SkipNeovimReason.GUARDED_BLOCKS)
@Test
fun `test delete char with block`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.jetbrains.plugins.ideavim.ExceptionHandler
import org.jetbrains.plugins.ideavim.OnlyThrowLoggedErrorProcessor
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.jetbrains.plugins.ideavim.exceptionMappingOwner
import org.jetbrains.plugins.ideavim.rangeOf
import org.jetbrains.plugins.ideavim.waitAndAssert
Expand All @@ -32,7 +32,7 @@ import kotlin.test.assertTrue
/**
* @author vlan
*/
class MacroActionTest : VimTestCase() {
class MacroActionTest : VimTestCaseBase() {

@AfterEach
fun tearDown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.jetbrains.plugins.ideavim.waitAndAssert
import org.junit.jupiter.api.Test

class MacroWithEditingTest : VimTestCase() {
class MacroWithEditingTest : VimTestCaseBase() {
@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
fun `test print macro`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.state.mode.Mode
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Test
import kotlin.test.assertNotNull

@Suppress("SpellCheckingInspection")
class MarkTest : VimTestCase() {
class MarkTest : VimTestCaseBase() {
// |m|
@Test
fun testLocalMark() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import com.maddyhome.idea.vim.state.mode.SelectionType
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

/**
* @author vlan
*/
class MotionActionTest : VimTestCase() {
class MotionActionTest : VimTestCaseBase() {
@Test
fun testDoubleToggleVisual() {
val contents = "one tw${c}o\n"
Expand Down Expand Up @@ -382,7 +382,7 @@ class MotionActionTest : VimTestCase() {
// VIM-1287 |d| |v_i{|
@Test
@VimBehaviorDiffers(
originalVimAfter = "{\"{foo, ${c}bar\", baz}}",
originalVimAfter = "{\"{foo, <caret>bar\", baz}}",
description = "We have PSI and can resolve this case correctly. I'm not sure if it should be fixed"
)
fun testBadlyNestedBlockInsideString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ import com.maddyhome.idea.vim.action.motion.search.SearchWholeWordForwardAction
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.SelectionType
import org.jetbrains.plugins.ideavim.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Test
import kotlin.test.assertNotNull

/**
* @author Vasily Alferov
*/
class MultipleCaretsTest : VimTestCase() {
class MultipleCaretsTest : VimTestCaseBase() {
// com.maddyhome.idea.vim.action.visual.leftright
@Test
fun testMotionLeftAction() {
Expand All @@ -40,7 +41,7 @@ class MultipleCaretsTest : VimTestCase() {
@Test
fun testMovementMerging() {
val editor = typeTextInFile(injector.parser.parseKeys("2h"), "o${c}n${c}e")
kotlin.test.assertEquals(1, editor.caretModel.caretCount)
kotlin.test.assertEquals(1, editor.ij.caretModel.caretCount)
assertState("${c}one")
}

Expand Down Expand Up @@ -1842,7 +1843,7 @@ $c five six se${c}ven eight
)
}

@VimBehaviorDiffers(originalVimAfter = "${c}\n${c}\nabcde\n${c}\n${c}\nabcde\n")
@VimBehaviorDiffers(originalVimAfter = "<caret>\n<caret>\nabcde\n<caret>\n<caret>\nabcde\n")
@Test
fun testInsertNewLineAboveActionWithMultipleCaretsInLine() {
typeTextInFile(
Expand Down Expand Up @@ -2173,7 +2174,7 @@ rtyfg${c}hzxc"""
val editor = configureByText(before)
injector.registerGroup.storeText('*', "fgh")
VimPlugin.getRegister()
.storeText(IjVimEditor(editor), editor.vim.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false)
.storeText(editor, editor.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false)
typeText(injector.parser.parseKeys("\"*P"))
val after = "fg${c}hqfg${c}hwe asd zxc rty fg${c}hfgh vbn"
assertState(after)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

package org.jetbrains.plugins.ideavim.action

import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Test

class RedrawActionTest : VimTestCase() {
class RedrawActionTest : VimTestCaseBase() {
@Test
fun `test redraw action clears status line`() {
configureByText("lorem ipsum")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.key.MappingOwner
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.VimTestCaseBase
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

class RepeatActionTest : VimTestCase() {
class RepeatActionTest : VimTestCaseBase() {

@Test
fun testSimpleRepeatLastCommand() {
Expand Down
Loading
Loading