1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-04-30 22:34:04 +02:00

Refactor some moved tests

This commit is contained in:
Matt Ellis 2025-02-18 22:41:33 +00:00 committed by Alex Pláte
parent 4453862ea0
commit ffdd6716f5
6 changed files with 63 additions and 70 deletions
src
main/resources/dictionaries
test/java/org/jetbrains/plugins/ideavim/ex/implementation/functions

View File

@ -166,11 +166,14 @@ lmapclear
cmapclear
tmapclear
funcref
getcmdtype
getreg
getregtype
tolower
toupper
delfunction
endfunction
consectetur

View File

@ -9,48 +9,44 @@
package org.jetbrains.plugins.ideavim.ex.implementation.functions
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInfo
class GetFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test get with dictionary`() {
configureByText("\n")
typeText(commandToKeys("echo get({1: 'one', 2: 'two', 3: 'three'}, '2')"))
assertExOutput("two")
assertCommandOutput("echo get({1: 'one', 2: 'two', 3: 'three'}, '2')", "two")
}
@Test
fun `test get by nonexistent key in dictionary`() {
configureByText("\n")
typeText(commandToKeys("echo get({1: 'one', 2: 'two', 3: 'three'}, '10')"))
assertExOutput("0")
assertCommandOutput("echo get({1: 'one', 2: 'two', 3: 'three'}, '10')", "0")
}
@Test
fun `test get by nonexistent key in dictionary with default value`() {
configureByText("\n")
typeText(commandToKeys("echo get({1: 'one', 2: 'two', 3: 'three'}, '10', 'null')"))
assertExOutput("null")
assertCommandOutput("echo get({1: 'one', 2: 'two', 3: 'three'}, '10', 'null')", "null")
}
@Test
fun `test get with list`() {
configureByText("\n")
typeText(commandToKeys("echo get(['one', 'two', 'three'], 1)"))
assertExOutput("two")
assertCommandOutput("echo get(['one', 'two', 'three'], 1)", "two")
}
@Test
fun `test get by nonexistent index in list`() {
configureByText("\n")
typeText(commandToKeys("echo get(['one', 'two', 'three'], 10)"))
assertExOutput("-1")
assertCommandOutput("echo get(['one', 'two', 'three'], 10)", "-1")
}
@Test
fun `test get by nonexistent index in list with default value`() {
configureByText("\n")
typeText(commandToKeys("echo get(['one', 'two', 'three'], 10, 'null')"))
assertExOutput("null")
assertCommandOutput("echo get(['one', 'two', 'three'], 10, 'null')", "null")
}
}

View File

@ -11,14 +11,20 @@ package org.jetbrains.plugins.ideavim.ex.implementation.functions.commandLineFun
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInfo
import kotlin.test.assertEquals
class GetCmdTypeFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test getcmdtype() for a regular command`() {
configureByText("\n")
enterCommand("cmap <expr> z getcmdtype()")
typeText(":fooz")
assertEquals("foo:", (injector.commandLine.getActiveCommandLine() as ExEntryPanel).visibleText)
@ -26,7 +32,6 @@ class GetCmdTypeFunctionTest : VimTestCase() {
@Test
fun `test getcmdtype() for a forward search`() {
configureByText("\n")
enterCommand("cmap <expr> z getcmdtype()")
typeText("/fooz")
assertEquals("foo/", (injector.commandLine.getActiveCommandLine() as ExEntryPanel).visibleText)
@ -34,7 +39,6 @@ class GetCmdTypeFunctionTest : VimTestCase() {
@Test
fun `test getcmdtype() for a backward search`() {
configureByText("\n")
enterCommand("cmap <expr> z getcmdtype()")
typeText("?fooz")
assertEquals("foo?", (injector.commandLine.getActiveCommandLine() as ExEntryPanel).visibleText)
@ -42,10 +46,8 @@ class GetCmdTypeFunctionTest : VimTestCase() {
@Test
fun `test getcmdtype() for an expression command`() {
configureByText("\n")
enterCommand("cmap <expr> z getcmdtype()")
typeText("i<C-r>=fooz")
assertEquals("foo=", (injector.commandLine.getActiveCommandLine() as ExEntryPanel).visibleText)
}
}

View File

@ -9,34 +9,34 @@
package org.jetbrains.plugins.ideavim.ex.implementation.functions.listFunctions
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInfo
class SplitFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test split with default delimiter`() {
configureByText("\n")
typeText(commandToKeys("echo split('Hello world')"))
assertExOutput("['Hello', 'world']")
assertCommandOutput("echo split('Hello world')", "['Hello', 'world']")
}
@Test
fun `test split comma separated text`() {
configureByText("\n")
typeText(commandToKeys("echo split('a,b,c,d', ',')"))
assertExOutput("['a', 'b', 'c', 'd']")
assertCommandOutput("echo split('a,b,c,d', ',')", "['a', 'b', 'c', 'd']")
}
@Test
fun `test split comma separated text 2`() {
configureByText("\n")
typeText(commandToKeys("echo split(',a,b,c,d,', ',')"))
assertExOutput("['a', 'b', 'c', 'd']")
assertCommandOutput("echo split(',a,b,c,d,', ',')", "['a', 'b', 'c', 'd']")
}
@Test
fun `test split comma separated text with keepempty flag`() {
configureByText("\n")
typeText(commandToKeys("echo split(',a,b,c,,d,', ',', 1)"))
assertExOutput("['', 'a', 'b', 'c', '', 'd', '']")
assertCommandOutput("echo split(',a,b,c,,d,', ',', 1)", "['', 'a', 'b', 'c', '', 'd', '']")
}
}

View File

@ -9,58 +9,50 @@
package org.jetbrains.plugins.ideavim.ex.implementation.functions.stringFunctions
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInfo
class EscapeFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test escape windows path with spaces`() {
configureByText("\n")
typeText(commandToKeys("""echo escape('c:\program files\vim', ' \')"""))
assertExOutput("""c:\\program\ files\\vim""")
assertCommandOutput("""echo escape('c:\program files\vim', ' \')""", """c:\\program\ files\\vim""")
}
@Test
fun `test escape multiple special characters`() {
configureByText("\n")
typeText(commandToKeys("""echo escape('special chars: #$^', '#$^')"""))
assertExOutput("""special chars: \#\$\^""")
assertCommandOutput("""echo escape('special chars: #$^', '#$^')""", """special chars: \#\$\^""")
}
@Test
fun `test escape when no escaping needed`() {
configureByText("\n")
typeText(commandToKeys("""echo escape('no escaping needed', 'xyz')"""))
assertExOutput("no escaping needed")
assertCommandOutput("""echo escape('no escaping needed', 'xyz')""", "no escaping needed")
}
@Test
fun `test escape empty strings`() {
configureByText("\n")
typeText(commandToKeys("""echo escape('', '')"""))
assertExOutput("")
assertCommandOutput("""echo escape('', '')""", "")
}
@Test
fun `test escape consecutive special characters`() {
configureByText("\n")
typeText(commandToKeys("""echo escape('$$$$', '$')"""))
assertExOutput("""\$\$\$\$""")
assertCommandOutput("""echo escape('$$$$', '$')""", """\$\$\$\$""")
}
@Test
fun `test escape with double backslashes`() {
configureByText("\n")
typeText(commandToKeys("""echo escape('test\\here', '\\')"""))
assertExOutput("""test\\\\here""")
assertCommandOutput("""echo escape('test\\here', '\\')""", """test\\\\here""")
}
@Test
fun `test escape with unicode characters`() {
configureByText("\n")
typeText(commandToKeys("""echo escape('Hello 👋 #world', '#')"""))
assertExOutput("""Hello 👋 \#world""")
typeText(commandToKeys("""echo escape('🎉$🎊$', '$')"""))
assertExOutput("""🎉\$🎊\$""")
assertCommandOutput("""echo escape('Hello 👋 #world', '#')""", """Hello 👋 \#world""")
assertCommandOutput("""echo escape('🎉$🎊$', '$')""", """🎉\$🎊\$""")
}
}

View File

@ -11,36 +11,36 @@ package org.jetbrains.plugins.ideavim.ex.implementation.functions.variousFunctio
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInfo
class HasFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test has for supported feature`() {
configureByText("\n")
typeText(commandToKeys("echo has('ide')"))
assertExOutput("1")
assertCommandOutput("echo has('ide')", "1")
}
@Test
fun `test has for unsupported feature`() {
configureByText("\n")
typeText(commandToKeys("echo has('autocmd')"))
assertExOutput("0")
assertCommandOutput("echo has('autocmd')", "0")
}
@Test
fun `test has for int as an argument`() {
configureByText("\n")
typeText(commandToKeys("echo has(42)"))
assertExOutput("0")
assertCommandOutput("echo has(42)", "0")
}
@TestWithoutNeovim(SkipNeovimReason.PLUGIN_ERROR)
@Test
fun `test has for list as an argument`() {
configureByText("\n")
typeText(commandToKeys("echo has([])"))
enterCommand("echo has([])")
assertPluginError(true)
assertPluginErrorMessageContains("E730: Using a List as a String")
}