1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-06-01 19:34:05 +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

@ -24,7 +24,7 @@ import org.jetbrains.plugins.ideavim.VimTestCase
class ShiftRightTest : VimTestCase() {
fun `test shift till new line`() {
val file = """
val file = """
A Discovery
I found it in a legendary l${c}and
@ -32,8 +32,8 @@ class ShiftRightTest : VimTestCase() {
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
typeTextInFile(StringHelper.parseKeys(">W"), file)
assertState("""
typeTextInFile(StringHelper.parseKeys(">W"), file)
assertState("""
A Discovery
${c}I found it in a legendary land
@ -45,80 +45,80 @@ class ShiftRightTest : VimTestCase() {
// VIM-407
fun testShiftShiftsOneCharacterSingleLine() {
myFixture.configureByText("a.txt", "<caret>w\n")
typeText(StringHelper.parseKeys(">>"))
assertState(" 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")
typeText(StringHelper.parseKeys(">>"))
assertState("Hello\n 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")
typeText(StringHelper.parseKeys(">>"))
assertState(" 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")
typeText(StringHelper.parseKeys("j>>"))
assertState("Hello,\n world!\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")
typeText(StringHelper.parseKeys("jv$>>"))
assertState("Hello,\n world!\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")
typeText(StringHelper.parseKeys("vj$>>"))
assertState(" Hello,\n world!\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")
typeText(StringHelper.parseKeys("vG$>>"))
assertState(" Hello,\n world!\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")
typeText(StringHelper.parseKeys("lVG>"))
assertState(" Hello,\n\n world!\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")
typeText(StringHelper.parseKeys("lVG>"))
assertState(" Hello,\n \n world!\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")
typeText(StringHelper.parseKeys("Vj>."))
assertState(" a\n b\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")
typeText(StringHelper.parseKeys("<C-V>jjl>"))
assertState("foo foo\nfoo bar\nfoo baz\n")
configureByText("foo<caret>foo\nfoobar\nfoobaz\n")
typeText(StringHelper.parseKeys("<C-V>jjl>"))
assertState("foo foo\nfoo bar\nfoo baz\n")
}
fun `test shift right positions caret at first non-blank char`() {
val file = """
val file = """
|A Discovery
|
| I found it in a legendary l${c}and
@ -126,8 +126,8 @@ class ShiftRightTest : VimTestCase() {
| where it was settled on some sodden sand
| hard by the torrent of a mountain pass.
""".trimMargin()
typeTextInFile(StringHelper.parseKeys(">>"), file)
assertState("""
typeTextInFile(StringHelper.parseKeys(">>"), file)
assertState("""
|A Discovery
| ${c}I found it in a legendary land
@ -138,8 +138,8 @@ class ShiftRightTest : VimTestCase() {
}
fun `test shift right does not move caret with nostartofline`() {
OptionsManager.startofline.reset()
val file = """
OptionsManager.startofline.reset()
val file = """
|A Discovery
|
| I found it in a ${c}legendary land
@ -147,8 +147,8 @@ class ShiftRightTest : VimTestCase() {
| where it was settled on some sodden sand
| hard by the torrent of a mountain pass.
""".trimMargin()
typeTextInFile(StringHelper.parseKeys(">>"), file)
assertState("""
typeTextInFile(StringHelper.parseKeys(">>"), file)
assertState("""
|A Discovery
| I found it i${c}n a legendary land
@ -159,7 +159,7 @@ class ShiftRightTest : VimTestCase() {
}
fun `test shift ctrl-t`() {
val file = """
val file = """
A Discovery
I found it in a legendary l${c}and
@ -167,8 +167,8 @@ class ShiftRightTest : VimTestCase() {
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
typeTextInFile(StringHelper.parseKeys("i<C-T>"), file)
assertState("""
typeTextInFile(StringHelper.parseKeys("i<C-T>"), file)
assertState("""
A Discovery
I found it in a legendary land

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
@ -32,7 +31,7 @@ import org.jetbrains.plugins.ideavim.VimTestCase
class SelectExtendVariousMotionsTest : VimTestCase() {
fun `test with tabs`() {
val code = """
val code = """
class Scratch {
.public static void main(String[] args) {
..try {
@ -46,11 +45,11 @@ 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)))
typeText(parseKeys("g<C-H>", "<S-UP>".repeat(2), "<S-Right>".repeat(2)))
assertState("""
assertState("""
class Scratch {
.public static void main(String[] args) {
..try {
@ -64,9 +63,9 @@ class SelectExtendVariousMotionsTest : VimTestCase() {
${s}}${c}${se}
""".trimIndent().dotToTab())
typeText(parseKeys("<S-UP>".repeat(7), "<S-Right>".repeat(3)))
typeText(parseKeys("<S-UP>".repeat(7), "<S-Right>".repeat(3)))
assertState("""
assertState("""
class Scratch {
${s}.pu${c}${se}blic static void main(String[] args) {
${s}.${c}${se}.try {
@ -80,9 +79,9 @@ class SelectExtendVariousMotionsTest : VimTestCase() {
${s}}${c}${se}
""".trimIndent().dotToTab())
typeText(parseKeys("<S-Right>".repeat(2)))
typeText(parseKeys("<S-Right>".repeat(2)))
assertState("""
assertState("""
class Scratch {
${s}.publ${c}${se}ic static void main(String[] args) {
${s}..${c}${se}try {

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
@ -31,7 +30,7 @@ import org.jetbrains.plugins.ideavim.VimTestCase
class VisualVariousMotionsTest : VimTestCase() {
fun `test with tabs`() {
val code = """
val code = """
class Scratch {
.public static void main(String[] args) {
..try {
@ -45,11 +44,11 @@ class VisualVariousMotionsTest : VimTestCase() {
${c}}
""".trimIndent().dotToTab()
myFixture.configureByText(PlainTextFileType.INSTANCE, code)
configureByText(code)
typeText(parseKeys("<C-V>", "k".repeat(2), "l".repeat(2)))
typeText(parseKeys("<C-V>", "k".repeat(2), "l".repeat(2)))
assertState("""
assertState("""
class Scratch {
.public static void main(String[] args) {
..try {
@ -63,10 +62,10 @@ class VisualVariousMotionsTest : VimTestCase() {
${s}${c}}${se}
""".trimIndent().dotToTab())
typeText(parseKeys("k".repeat(7), "l".repeat(3)))
typeText(parseKeys("k".repeat(7), "l".repeat(3)))
// Carets 2-4 have 0 column as logical position, but ${se} - 1 column as visual position
assertState("""
// Carets 2-4 have 0 column as logical position, but ${se} - 1 column as visual position
assertState("""
class Scratch {
${s}.pu${c}b${se}lic static void main(String[] args) {
${s}${c}.${se}.try {
@ -80,13 +79,13 @@ class VisualVariousMotionsTest : VimTestCase() {
${s}${c}}${se}
""".trimIndent().dotToTab())
TestCase.assertEquals(3, myFixture.editor.caretModel.allCarets[1].visualPosition.column)
TestCase.assertEquals(3, myFixture.editor.caretModel.allCarets[2].visualPosition.column)
TestCase.assertEquals(3, myFixture.editor.caretModel.allCarets[3].visualPosition.column)
TestCase.assertEquals(3, myFixture.editor.caretModel.allCarets[1].visualPosition.column)
TestCase.assertEquals(3, myFixture.editor.caretModel.allCarets[2].visualPosition.column)
TestCase.assertEquals(3, myFixture.editor.caretModel.allCarets[3].visualPosition.column)
typeText(parseKeys("l".repeat(2)))
typeText(parseKeys("l".repeat(2)))
assertState("""
assertState("""
class Scratch {
${s}.publ${c}i${se}c static void main(String[] args) {
${s}..${c}t${se}ry {
@ -99,6 +98,6 @@ class VisualVariousMotionsTest : VimTestCase() {
${s}.retu${c}r${se}n anything
${s}${c}}${se}
""".trimIndent().dotToTab())
TestCase.assertEquals(7, myFixture.editor.caretModel.allCarets[2].visualPosition.column)
TestCase.assertEquals(7, myFixture.editor.caretModel.allCarets[2].visualPosition.column)
}
}

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()