1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-07-30 00:59:08 +02:00

Use wrapper functions around myFixture

This commit is contained in:
Alex Plate 2021-05-30 15:18:03 +03:00
parent 91139005dc
commit b32befe5df
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
11 changed files with 88 additions and 81 deletions

View File

@ -9,7 +9,6 @@
<JavaCodeStyleSettings>
<option name="FIELD_NAME_PREFIX" value="my" />
<option name="STATIC_FIELD_NAME_PREFIX" value="our" />
<option name="USE_EXTERNAL_ANNOTATIONS" value="true" />
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />

View File

@ -38,12 +38,19 @@
<constraint name="editor" within="" contains="" />
<constraint name="expr" minCount="0" maxCount="2147483647" within="" contains="" />
</replaceConfiguration>
<replaceConfiguration name="Use assertState instead of fixture" description="Use assertState function instead of myFixture.checkResult.&#10;This function also preformes assertion in neovim" suppressId="IdeaVimAssertState" problemDescriptor="Use assertState function" text="$fixture$.$check$($data$)" recursive="false" caseInsensitive="false" type="Kotlin" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="false" replacement="assertState($data$)">
<replaceConfiguration name="Use IdeaVim method instead of the fixture" uuid="0f74da52-7360-33ae-9b40-d771aa128de6" description="Use assertState and other functions instead of myFixture.checkResult.&#10;This function also preformes assertion in neovim" suppressId="IdeaVimAssertState" problemDescriptor="Use IdeaVim testing methods" text="$fixture$.$check$($data$)" recursive="false" caseInsensitive="false" type="Kotlin" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="false" replacement="assertState($data$)">
<constraint name="__context__" within="" contains="" />
<constraint name="fixture" regexp="myFixture" nameOfExprType="CodeInsightTestFixture" within="" contains="" />
<constraint name="check" regexp="checkResult" within="" contains="" />
<constraint name="data" within="" contains="" />
</replaceConfiguration>
<replaceConfiguration name="Use IdeaVim method instead of the fixture" uuid="0f74da52-7360-33ae-9b40-d771aa128de6" text="$fixture$.$check$($fileName$, $text$)" recursive="false" caseInsensitive="false" type="Kotlin" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="false" replacement="configureByText($text$)">
<constraint name="__context__" within="" contains="" />
<constraint name="fixture" regexp="myFixture" nameOfExprType="CodeInsightTestFixture" within="" contains="" />
<constraint name="check" regexp="configureByText" within="" contains="" />
<constraint name="text" within="" contains="" />
<constraint name="fileName" within="" contains="" />
</replaceConfiguration>
</inspection_tool>
<inspection_tool class="UnstableApiUsage" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>

View File

@ -21,6 +21,7 @@ import com.intellij.ide.bookmarks.Bookmark
import com.intellij.ide.bookmarks.BookmarkManager
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.ide.highlighter.XmlFileType
import com.intellij.json.JsonFileType
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.editor.Caret
@ -163,8 +164,10 @@ abstract class VimTestCase : UsefulTestCase() {
protected fun configureByText(content: String) = configureByText(PlainTextFileType.INSTANCE, content)
protected fun configureByJavaText(content: String) = configureByText(JavaFileType.INSTANCE, content)
protected fun configureByXmlText(content: String) = configureByText(XmlFileType.INSTANCE, content)
protected fun configureByJsonText(content: String) = configureByText(JsonFileType.INSTANCE, content)
private fun configureByText(fileType: FileType, content: String): Editor {
@Suppress("IdeaVimAssertState")
myFixture.configureByText(fileType, content)
NeovimTesting.setupEditor(myFixture.editor, this)
setEditorVisibleSize(screenWidth, screenHeight)
@ -172,6 +175,7 @@ abstract class VimTestCase : UsefulTestCase() {
}
protected fun configureByFileName(fileName: String): Editor {
@Suppress("IdeaVimAssertState")
myFixture.configureByText(fileName, "\n")
setEditorVisibleSize(screenWidth, screenHeight)
return myFixture.editor

View File

@ -17,7 +17,6 @@
*/
package org.jetbrains.plugins.ideavim.action
import com.intellij.json.JsonFileType
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.helper.StringHelper
@ -592,7 +591,7 @@ class MotionActionTest : VimTestCase() {
// VIM-965 |[m|
@TestWithoutNeovim(reason = SkipNeovimReason.DIFFERENT, "File type specific")
fun testMethodMovingInNonJavaFile() {
myFixture.configureByText(JsonFileType.INSTANCE, "{\"foo\": \"${c}bar\"}\n")
configureByJsonText("{\"foo\": \"${c}bar\"}\n")
typeText(parseKeys("[m"))
assertState("{\"foo\": \"${c}bar\"}\n")
}

View File

@ -45,74 +45,74 @@ class ShiftRightTest : VimTestCase() {
// VIM-407
fun testShiftShiftsOneCharacterSingleLine() {
myFixture.configureByText("a.txt", "<caret>w\n")
configureByText("<caret>w\n")
typeText(StringHelper.parseKeys(">>"))
assertState(" w\n")
}
// VIM-407
fun testShiftShiftsOneCharacterMultiLine() {
myFixture.configureByText("a.txt", "Hello\n<caret>w\nWorld")
configureByText("Hello\n<caret>w\nWorld")
typeText(StringHelper.parseKeys(">>"))
assertState("Hello\n w\nWorld")
}
fun testShiftShiftsMultipleCharactersOneLine() {
myFixture.configureByText("a.txt", "<caret>Hello, world!\n")
configureByText("<caret>Hello, world!\n")
typeText(StringHelper.parseKeys(">>"))
assertState(" Hello, world!\n")
}
fun testShiftShiftsMultipleCharactersMultipleLines() {
myFixture.configureByText("a.txt", "<caret>Hello,\nworld!\n")
configureByText("<caret>Hello,\nworld!\n")
typeText(StringHelper.parseKeys("j>>"))
assertState("Hello,\n world!\n")
}
fun testShiftsSingleLineSelection() {
myFixture.configureByText("a.txt", "<caret>Hello,\nworld!\n")
configureByText("<caret>Hello,\nworld!\n")
typeText(StringHelper.parseKeys("jv$>>"))
assertState("Hello,\n world!\n")
}
fun testShiftsMultiLineSelection() {
myFixture.configureByText("a.txt", "<caret>Hello,\nworld!\n")
configureByText("<caret>Hello,\nworld!\n")
typeText(StringHelper.parseKeys("vj$>>"))
assertState(" Hello,\n world!\n")
}
fun testShiftsMultiLineSelectionSkipsNewline() {
myFixture.configureByText("a.txt", "<caret>Hello,\nworld!\n\n")
configureByText("<caret>Hello,\nworld!\n\n")
typeText(StringHelper.parseKeys("vG$>>"))
assertState(" Hello,\n world!\n\n")
}
fun testShiftsMultiLineSelectionSkipsNewlineWhenCursorNotInFirstColumn() {
myFixture.configureByText("a.txt", "<caret>Hello,\n\nworld!\n")
configureByText("<caret>Hello,\n\nworld!\n")
typeText(StringHelper.parseKeys("lVG>"))
assertState(" Hello,\n\n world!\n")
}
fun testShiftsMultiLineSelectionAddsTrailingWhitespaceIfTherePreviouslyWas() {
myFixture.configureByText("a.txt", "<caret>Hello,\n \nworld!\n")
configureByText("<caret>Hello,\n \nworld!\n")
typeText(StringHelper.parseKeys("lVG>"))
assertState(" Hello,\n \n world!\n")
}
// VIM-705 repeating a multiline indent would only affect last line
fun testShiftsMultiLineSelectionRepeat() {
myFixture.configureByText("a.txt", "<caret>a\nb\n")
configureByText("<caret>a\nb\n")
typeText(StringHelper.parseKeys("Vj>."))
assertState(" a\n b\n")
}
fun testShiftsDontCrashKeyHandler() {
myFixture.configureByText("a.txt", "\n")
configureByText("\n")
typeText(StringHelper.parseKeys("<I<>", "<I<>"))
}
fun testShiftsVisualBlockMode() {
myFixture.configureByText("a.txt", "foo<caret>foo\nfoobar\nfoobaz\n")
configureByText("foo<caret>foo\nfoobar\nfoobaz\n")
typeText(StringHelper.parseKeys("<C-V>jjl>"))
assertState("foo foo\nfoo bar\nfoo baz\n")
}

View File

@ -20,7 +20,6 @@
package org.jetbrains.plugins.ideavim.action.motion.select.motion
import com.intellij.openapi.fileTypes.PlainTextFileType
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import org.jetbrains.plugins.ideavim.VimTestCase
@ -46,7 +45,7 @@ class SelectExtendVariousMotionsTest : VimTestCase() {
${c}}
""".trimIndent().dotToTab()
myFixture.configureByText(PlainTextFileType.INSTANCE, code)
configureByText(code)
typeText(parseKeys("g<C-H>", "<S-UP>".repeat(2), "<S-Right>".repeat(2)))

View File

@ -20,7 +20,6 @@
package org.jetbrains.plugins.ideavim.action.motion.updown
import com.intellij.openapi.fileTypes.PlainTextFileType
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import junit.framework.TestCase
import org.jetbrains.plugins.ideavim.VimTestCase
@ -45,7 +44,7 @@ class VisualVariousMotionsTest : VimTestCase() {
${c}}
""".trimIndent().dotToTab()
myFixture.configureByText(PlainTextFileType.INSTANCE, code)
configureByText(code)
typeText(parseKeys("<C-V>", "k".repeat(2), "l".repeat(2)))

View File

@ -27,7 +27,7 @@ import org.jetbrains.plugins.ideavim.VimTestCase
class PutHandlerTest : VimTestCase() {
// VIM-550 |:put|
fun `test put creates new line`() {
myFixture.configureByText("a.txt", "Test\n" + "Hello <caret>World!\n")
configureByText("Test\n" + "Hello <caret>World!\n")
typeText(parseKeys("\"ayw"))
typeText(commandToKeys("put a"))
assertState("Test\n" +
@ -37,7 +37,7 @@ class PutHandlerTest : VimTestCase() {
// VIM-551 |:put|
fun `test put default`() {
myFixture.configureByText("a.txt", "<caret>Hello World!\n")
configureByText("<caret>Hello World!\n")
typeText(parseKeys("yw"))
typeText(commandToKeys("put"))
assertState("Hello World!\n" + "<caret>Hello \n")

View File

@ -291,7 +291,7 @@ class SubstituteHandlerTest : VimOptionTestCase(SmartCaseOptionsData.name, Ignor
@VimOptionDefaultAll
@TestWithoutNeovim(reason = SkipNeovimReason.OPTION)
fun `test visual substitute doesnt change visual marks`() {
myFixture.configureByText("a.java", "foo\nbar\nbaz\n")
configureByText("foo\nbar\nbaz\n")
typeText(parseKeys("V", "j", ":'<,'>s/foo/fuu/<Enter>", "gv", "~"))
assertState("FUU\nBAR\nbaz\n")
}

View File

@ -303,7 +303,7 @@ n ,f <Plug>Foo
// VIM-700 |:map|
fun testRemappingZero() {
configureByText("x${c}yz\n")
VimScriptParser.executeText(listOf("map 0 ~"))
typeText(commandToKeys("map 0 ~"))
typeText(StringHelper.parseKeys("0"))
assertState("xYz\n")
}
@ -319,7 +319,7 @@ n ,f <Plug>Foo
// VIM-700 |:map|
fun testRemappingDeleteOverridesRemovingLastDigitFromCount() {
configureByText("a${c}bcdefghijklmnop\n")
VimScriptParser.executeText(listOf("map <Del> ~"))
typeText(commandToKeys("map <Del> ~"))
typeText(StringHelper.parseKeys("10<Del>"))
assertState("aBCDEFGHIJKlmnop\n")
}

View File

@ -1420,7 +1420,7 @@ class SearchGroupTest : VimTestCase() {
// TODO: Remove these search methods and test by invoking VIM commands rather than calling APIs
private fun search(pattern: String, input: String, expectedLocation: Int): Int {
myFixture.configureByText("a.java", input)
configureByText(input)
val editor = myFixture.editor
val project = myFixture.project
val searchGroup = VimPlugin.getSearch()
@ -1444,7 +1444,7 @@ class SearchGroupTest : VimTestCase() {
}
private fun search(pattern: String, input: String): Int {
myFixture.configureByText("a.java", input)
configureByText(input)
val editor = myFixture.editor
val project = myFixture.project
val searchGroup = VimPlugin.getSearch()