mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-06 21:34:02 +02:00
Reinstate showmode tests
This commit is contained in:
parent
dc5ef487d2
commit
8b8ef80a5e
src
main/java/com/maddyhome/idea/vim/ui/widgets/mode
test/java/org/jetbrains/plugins/ideavim/command
@ -31,7 +31,7 @@ import javax.swing.JComponent
|
||||
import kotlin.math.max
|
||||
|
||||
class VimModeWidget(val project: Project) : CustomStatusBarWidget, VimStatusBarWidget {
|
||||
private companion object {
|
||||
companion object {
|
||||
private const val INSERT = "INSERT"
|
||||
private const val NORMAL = "NORMAL"
|
||||
private const val INSERT_NORMAL = "(insert)"
|
||||
@ -46,6 +46,50 @@ class VimModeWidget(val project: Project) : CustomStatusBarWidget, VimStatusBarW
|
||||
private const val SELECT = "SELECT"
|
||||
private const val SELECT_LINE = "S-LINE"
|
||||
private const val SELECT_BLOCK = "S-BLOCK"
|
||||
|
||||
fun getModeText(mode: Mode?): String? {
|
||||
return when (mode) {
|
||||
Mode.INSERT -> INSERT
|
||||
Mode.REPLACE -> REPLACE
|
||||
is Mode.NORMAL -> getNormalModeText(mode)
|
||||
is Mode.CMD_LINE -> COMMAND
|
||||
is Mode.VISUAL -> getVisualModeText(mode)
|
||||
is Mode.SELECT -> getSelectModeText(mode)
|
||||
is Mode.OP_PENDING, null -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun getNormalModeText(mode: Mode.NORMAL) = when {
|
||||
mode.isInsertPending -> INSERT_NORMAL
|
||||
mode.isReplacePending -> REPLACE_NORMAL
|
||||
else -> NORMAL
|
||||
}
|
||||
|
||||
private fun getVisualModeText(mode: Mode.VISUAL): String {
|
||||
val prefix = when {
|
||||
mode.isInsertPending -> INSERT_PENDING_PREFIX
|
||||
mode.isReplacePending -> REPLACE_PENDING_PREFIX
|
||||
else -> ""
|
||||
}
|
||||
return prefix + when (mode.selectionType) {
|
||||
SelectionType.CHARACTER_WISE -> VISUAL
|
||||
SelectionType.LINE_WISE -> VISUAL_LINE
|
||||
SelectionType.BLOCK_WISE -> VISUAL_BLOCK
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSelectModeText(mode: Mode.SELECT): String {
|
||||
val prefix = when {
|
||||
mode.isInsertPending -> INSERT_PENDING_PREFIX
|
||||
mode.isReplacePending -> REPLACE_PENDING_PREFIX
|
||||
else -> ""
|
||||
}
|
||||
return prefix + when (mode.selectionType) {
|
||||
SelectionType.CHARACTER_WISE -> SELECT
|
||||
SelectionType.LINE_WISE -> SELECT_LINE
|
||||
SelectionType.BLOCK_WISE -> SELECT_BLOCK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val label = JBLabelWiderThan(setOf(REPLACE)).apply { isOpaque = true }
|
||||
@ -97,50 +141,6 @@ class VimModeWidget(val project: Project) : CustomStatusBarWidget, VimStatusBarW
|
||||
return fileEditorManager.selectedTextEditor
|
||||
}
|
||||
|
||||
private fun getModeText(mode: Mode?): String? {
|
||||
return when (mode) {
|
||||
Mode.INSERT -> INSERT
|
||||
Mode.REPLACE -> REPLACE
|
||||
is Mode.NORMAL -> getNormalModeText(mode)
|
||||
is Mode.CMD_LINE -> COMMAND
|
||||
is Mode.VISUAL -> getVisualModeText(mode)
|
||||
is Mode.SELECT -> getSelectModeText(mode)
|
||||
is Mode.OP_PENDING, null -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun getNormalModeText(mode: Mode.NORMAL) = when {
|
||||
mode.isInsertPending -> INSERT_NORMAL
|
||||
mode.isReplacePending -> REPLACE_NORMAL
|
||||
else -> NORMAL
|
||||
}
|
||||
|
||||
private fun getVisualModeText(mode: Mode.VISUAL): String {
|
||||
val prefix = when {
|
||||
mode.isInsertPending -> INSERT_PENDING_PREFIX
|
||||
mode.isReplacePending -> REPLACE_PENDING_PREFIX
|
||||
else -> ""
|
||||
}
|
||||
return prefix + when (mode.selectionType) {
|
||||
SelectionType.CHARACTER_WISE -> VISUAL
|
||||
SelectionType.LINE_WISE -> VISUAL_LINE
|
||||
SelectionType.BLOCK_WISE -> VISUAL_BLOCK
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSelectModeText(mode: Mode.SELECT): String {
|
||||
val prefix = when {
|
||||
mode.isInsertPending -> INSERT_PENDING_PREFIX
|
||||
mode.isReplacePending -> REPLACE_PENDING_PREFIX
|
||||
else -> ""
|
||||
}
|
||||
return prefix + when (mode.selectionType) {
|
||||
SelectionType.CHARACTER_WISE -> SELECT
|
||||
SelectionType.LINE_WISE -> SELECT_LINE
|
||||
SelectionType.BLOCK_WISE -> SELECT_BLOCK
|
||||
}
|
||||
}
|
||||
|
||||
private class JBLabelWiderThan(private val words: Collection<String>): JBLabel("", CENTER) {
|
||||
private val wordWidth: Int
|
||||
get() {
|
||||
|
@ -8,162 +8,184 @@
|
||||
|
||||
package org.jetbrains.plugins.ideavim.command
|
||||
|
||||
import com.intellij.openapi.wm.WindowManager
|
||||
import com.maddyhome.idea.vim.ui.widgets.mode.ModeWidgetFactory
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.ui.widgets.mode.VimModeWidget
|
||||
import org.jetbrains.plugins.ideavim.SkipNeovimReason
|
||||
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
// TODO it would be cool to test widget, but status bar is not initialized
|
||||
@TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
class VimShowModeTest : VimTestCase() {
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in normal`() {
|
||||
// configureByText("123")
|
||||
// val widget = getModeWidget()
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in insert`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("i"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- INSERT --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in replace`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("R"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- REPLACE --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in visual`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("v"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- VISUAL --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in visual line`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("V"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- VISUAL LINE --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in visual block`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("<C-V>"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- VISUAL BLOCK --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in select`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("gh"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- SELECT --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in select line`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("gH"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- SELECT LINE --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in select block`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("g<C-H>"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- SELECT BLOCK --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in one command`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("i<C-O>"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- (insert) --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in one command visual`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("i<C-O>v"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- (insert) VISUAL --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in one command visual block`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("i<C-O><C-V>"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- (insert) VISUAL BLOCK --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in one command visual line`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("i<C-O>V"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- (insert) VISUAL LINE --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in one command select`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("i<C-O>gh"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- (insert) SELECT --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in one command select block`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("i<C-O>g<C-H>"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- (insert) SELECT BLOCK --", statusString)
|
||||
// }
|
||||
//
|
||||
// @TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
// @Test
|
||||
// fun `test status string in one command select line`() {
|
||||
// configureByText("123")
|
||||
// typeText(injector.parser.parseKeys("i<C-O>gH"))
|
||||
// val statusString = fixture.editor.vim.getStatusString()
|
||||
// kotlin.test.assertEquals("-- (insert) SELECT LINE --", statusString)
|
||||
// }
|
||||
//
|
||||
@Test
|
||||
fun `test status string in normal`() {
|
||||
configureByText("123")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("NORMAL", statusString)
|
||||
}
|
||||
|
||||
// Always return null
|
||||
private fun getModeWidget(): VimModeWidget? {
|
||||
val project = fixture.editor?.project ?: return null
|
||||
val statusBar = WindowManager.getInstance()?.getStatusBar(project) ?: return null
|
||||
return statusBar.getWidget(ModeWidgetFactory.ID) as? VimModeWidget
|
||||
@Test
|
||||
fun `test status string in insert`() {
|
||||
configureByText("123")
|
||||
typeText("i")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("INSERT", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in replace`() {
|
||||
configureByText("123")
|
||||
typeText("R")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("REPLACE", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in visual`() {
|
||||
configureByText("123")
|
||||
typeText("v")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("VISUAL", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in visual line`() {
|
||||
configureByText("123")
|
||||
typeText("V")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("V-LINE", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in visual block`() {
|
||||
configureByText("123")
|
||||
typeText("<C-V>")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("V-BLOCK", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in select`() {
|
||||
configureByText("123")
|
||||
typeText("gh")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("SELECT", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in select line`() {
|
||||
configureByText("123")
|
||||
typeText("gH")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("S-LINE", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in select block`() {
|
||||
configureByText("123")
|
||||
typeText("g<C-H>")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("S-BLOCK", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string for Insert Normal mode`() {
|
||||
configureByText("123")
|
||||
typeText("i<C-O>")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(insert)", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string for Replace pending Normal mode`() {
|
||||
configureByText("123")
|
||||
typeText("R<C-O>")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(replace)", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in Insert Visual mode`() {
|
||||
configureByText("123")
|
||||
typeText("i<C-O>v")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(insert) VISUAL", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in Replace pending Visual mode`() {
|
||||
configureByText("123")
|
||||
typeText("R<C-O>v")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(replace) VISUAL", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in Insert Visual block mode`() {
|
||||
configureByText("123")
|
||||
typeText("i<C-O><C-V>")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(insert) V-BLOCK", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in Replace pending Visual block mode`() {
|
||||
configureByText("123")
|
||||
typeText("R<C-O><C-V>")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(replace) V-BLOCK", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in Insert Visual line mode`() {
|
||||
configureByText("123")
|
||||
typeText("i<C-O>V")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(insert) V-LINE", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in Replace pending Visual line mode`() {
|
||||
configureByText("123")
|
||||
typeText("R<C-O>V")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(replace) V-LINE", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in Insert Select mode`() {
|
||||
configureByText("123")
|
||||
typeText("i<C-O>gh")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(insert) SELECT", statusString)
|
||||
}
|
||||
|
||||
// TODO: Not currently working
|
||||
@Disabled
|
||||
@Test
|
||||
fun `test status string in Insert Select mode 2`() {
|
||||
configureByText("123")
|
||||
enterCommand("set selectmode=key keymodel=startsel")
|
||||
typeText("i<S-Right>")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(insert) SELECT", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in Insert Select block mode`() {
|
||||
configureByText("123")
|
||||
typeText("i<C-O>g<C-H>")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(insert) S-BLOCK", statusString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test status string in Insert Select line mode`() {
|
||||
configureByText("123")
|
||||
typeText("i<C-O>gH")
|
||||
val statusString = VimModeWidget.getModeText(fixture.editor.vim.mode)
|
||||
assertEquals("(insert) S-LINE", statusString)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user