1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-04-16 02:15:43 +02:00

Extract function tests

This commit is contained in:
Matt Ellis 2025-02-18 22:31:08 +00:00 committed by Alex Pláte
parent c631d0738e
commit 4453862ea0
22 changed files with 419 additions and 255 deletions
src
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/functions/handlers

View File

@ -168,6 +168,8 @@ tmapclear
getreg
getregtype
tolower
toupper
endfunction

View File

@ -83,10 +83,14 @@ E545=E545: Missing colon: {0}
E546=E546: Illegal mode: {0}
E548=E548: Digit expected: {0}
E549=E549: Illegal percentage: {0}
E701=E701: Invalid type for len()
E730=E730: Using a List as a String
E731=E731: Using a Dictionary as a String
E774=E774: 'operatorfunc' is empty
E805=E805: Using a Float as a Number
e841.reserved.name.cannot.be.used.for.user.defined.command=E841: Reserved name, cannot be used for user defined command
E939=E939: Positive count required
E1211=E1211: List required for argument {0}
E1214=E1214: Digraph must be just two characters: {0}
message.search.hit.bottom=search hit BOTTOM, continuing at TOP

View File

@ -1,51 +0,0 @@
/*
* Copyright 2003-2023 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.ex.implementation.functions
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
class BasicStringFunctions : VimTestCase() {
@Test
fun `test toupper`() {
configureByText("\n")
typeText(commandToKeys("echo toupper('Vim is awesome')"))
assertExOutput("VIM IS AWESOME")
}
@Test
fun `test tolower`() {
configureByText("\n")
typeText(commandToKeys("echo tolower('Vim is awesome')"))
assertExOutput("vim is awesome")
}
@Test
fun `test join`() {
configureByText("\n")
typeText(commandToKeys("echo join(['Vim', 'is', 'awesome'], '_')"))
assertExOutput("Vim_is_awesome")
}
@Test
fun `test join without second argument`() {
configureByText("\n")
typeText(commandToKeys("echo join(['Vim', 'is', 'awesome'])"))
assertExOutput("Vim is awesome")
}
@Test
fun `test join with wrong first argument type`() {
configureByText("\n")
typeText(commandToKeys("echo join('Vim is awesome')"))
assertPluginError(true)
assertPluginErrorMessageContains("E714: List required")
}
}

View File

@ -1,180 +0,0 @@
/*
* Copyright 2003-2023 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.ex.implementation.functions
import com.maddyhome.idea.vim.api.injector
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
class BuiltInFunctionTest : VimTestCase() {
@Test
fun `test abs`() {
configureByText("\n")
typeText(commandToKeys("echo abs(-123) abs(2)"))
assertExOutput("123 2")
}
@Test
fun `test sin`() {
configureByText("\n")
typeText(commandToKeys("echo sin(0) sin(1)"))
assertExOutput("0.0 0.841471")
}
@Test
fun `test empty`() {
configureByText("\n")
typeText(commandToKeys("echo empty(0) empty(1)"))
assertExOutput("1 0")
typeText(commandToKeys("echo empty(\"123\") empty(\"\")"))
assertExOutput("0 1")
typeText(commandToKeys("echo empty([1, 2]) empty([])"))
assertExOutput("0 1")
typeText(commandToKeys("echo empty({1:2}) empty({})"))
assertExOutput("0 1")
}
@Test
fun `test line`() {
configureByText("1\n2\n${c}3\n4\n5")
typeText(commandToKeys("echo line('.')"))
assertExOutput("3")
typeText(commandToKeys("echo line('$')"))
assertExOutput("5")
typeText(injector.parser.parseKeys("ma"))
typeText(commandToKeys("""echo line("'a") line("'x")"""))
assertExOutput("3 0")
setEditorVisibleSize(screenWidth, 3)
setPositionAndScroll(2, 2)
typeText(commandToKeys("""echo line("w0") line("w$")"""))
assertExOutput("3 5")
// Without selection - current line
typeText(commandToKeys("""echo line("v")"""))
assertExOutput("3")
// With selection - make sure to delete the '<,'> that is automatically prepended when entering Command-line mode
// with a selection
typeText(injector.parser.parseKeys("vj"))
typeText(injector.parser.parseKeys(""":<BS><BS><BS><BS><BS>echo line("v")<CR>"""))
assertExOutput("3")
// Remove selection and check again - note that exiting Command-line mode removes selection and switches back to
// Normal. This <esc> does nothing
typeText(injector.parser.parseKeys("<esc>"))
typeText(commandToKeys("""echo line("v")"""))
assertExOutput("3")
typeText(commandToKeys("""echo line("abs") line(1) line([])"""))
assertExOutput("0 0 0")
typeText(commandToKeys("""echo line([1, 1]) line(['.', '$']) line(['$', '$'])"""))
assertExOutput("1 0 0")
typeText(commandToKeys("""echo line([0, 1]) line([1, 1]) line([5, 1]) line([6, 1]) line([5, 2]) line([5, 3])"""))
assertExOutput("0 1 5 0 5 0")
}
// XXX virtualedit is not tested
@Test
fun `test col`() {
configureByText(
"""
1
2
1234${c}567890
4
5
""".trimIndent(),
)
typeText(commandToKeys("echo col('.')"))
assertExOutput("5")
typeText(commandToKeys("echo col('$')"))
assertExOutput("10")
typeText(injector.parser.parseKeys("ma"))
typeText(commandToKeys("""echo col("'a") col("'z")"""))
assertExOutput("5 0")
// Without selection - current line
typeText(commandToKeys("""echo col("v")"""))
assertExOutput("5")
// With selection - make sure to delete the '<,'> that is automatically prepended when entering Command-line mode
// with a selection
typeText(injector.parser.parseKeys("vll"))
typeText(injector.parser.parseKeys(""":<BS><BS><BS><BS><BS>echo col("v")<CR>"""))
assertExOutput("5")
// Remove selection and check again - note that exiting Command-line mode removes selection and switches back to
// Normal. This <esc> does nothing
typeText(injector.parser.parseKeys("<esc>"))
typeText(commandToKeys("""echo col("v")"""))
assertExOutput("5")
typeText(commandToKeys("echo col('$')"))
assertExOutput("10")
typeText(commandToKeys("""echo col("abs") col(1) col([])"""))
assertExOutput("0 0 0")
typeText(commandToKeys("""echo col([1, 1]) col([3, '$']) col(['.', '$']) col(['$', '$'])"""))
assertExOutput("1 11 0 0")
typeText(commandToKeys("""echo col([0, 1]) col([1, 1]) col([5, 1]) col([6, 1]) col([5, 2])"""))
assertExOutput("0 1 1 0 2")
}
@Test
fun `test exists`() {
configureByText("\n")
typeText(commandToKeys("echo exists(\"&nu\")"))
assertExOutput("1")
typeText(commandToKeys("echo exists(\"&unknownOptionName\")"))
assertExOutput("0")
typeText(commandToKeys("echo exists(\"g:myVar\")"))
assertExOutput("0")
enterCommand("let myVar = 42")
typeText(commandToKeys("echo exists(\"g:myVar\")"))
assertExOutput("1")
}
@Test
fun `test len`() {
configureByText("\n")
typeText(commandToKeys("echo len(123)"))
assertExOutput("3")
typeText(commandToKeys("echo len('abcd')"))
assertExOutput("4")
typeText(commandToKeys("echo len([1])"))
assertExOutput("1")
typeText(commandToKeys("echo len({})"))
assertExOutput("0")
typeText(commandToKeys("echo len(#{1: 'one'})"))
assertExOutput("1")
typeText(commandToKeys("echo len(12 . 4)"))
assertExOutput("3")
typeText(commandToKeys("echo len(4.2)"))
assertPluginErrorMessageContains("E701: Invalid type for len()")
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2003-2025 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.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 EmptyFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test empty`() {
assertCommandOutput("echo empty(0) empty(1)", "1 0")
assertCommandOutput("echo empty(\"123\") empty(\"\")", "0 1")
assertCommandOutput("echo empty([1, 2]) empty([])", "0 1")
assertCommandOutput("echo empty({1:2}) empty({})", "0 1")
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright 2003-2025 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.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 LenFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test len`() {
assertCommandOutput("echo len(123)", "3")
assertCommandOutput("echo len('abcd')", "4")
assertCommandOutput("echo len([1])", "1")
assertCommandOutput("echo len({})", "0")
assertCommandOutput("echo len(#{1: 'one'})", "1")
assertCommandOutput("echo len(12 . 4)", "3")
}
@Test
fun `test len with float causes errors`() {
enterCommand("echo len(4.2)")
assertPluginErrorMessageContains("E701: Invalid type for len()")
}
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2003-2024 The IdeaVim authors
* Copyright 2003-2025 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.ex.implementation.functions
package org.jetbrains.plugins.ideavim.ex.implementation.functions.commandLineFunctions
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
@ -48,4 +48,4 @@ class GetCmdTypeFunctionTest : VimTestCase() {
assertEquals("foo=", (injector.commandLine.getActiveCommandLine() as ExEntryPanel).visibleText)
}
}
}

View File

@ -0,0 +1,53 @@
/*
* Copyright 2003-2025 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.ex.implementation.functions.cursorFunctions
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
class ColFunctionTest : VimTestCase() {
// XXX virtualedit is not tested
@Test
fun `test col`() {
configureByText(
"""
1
2
1234${c}567890
4
5
""".trimIndent(),
)
assertCommandOutput("echo col('.')", "5")
assertCommandOutput("echo col('$')", "10")
typeText("ma")
assertCommandOutput("""echo col("'a") col("'z")""", "5 0")
// Without selection - current line
assertCommandOutput("""echo col("v")""", "5")
// With selection - make sure to delete the '<,'> that is automatically prepended when entering Command-line mode
// with a selection
typeText("vll")
typeText(":<C-U>echo col(\"v\")<CR>") // enterCommand/assertCommandOutput cannot handle <C-U>!
assertExOutput("5")
// Remove selection and check again - note that exiting Command-line mode removes selection and switches back to
// Normal. This <esc> does nothing
typeText("<esc>")
assertCommandOutput("""echo col("v")""", "5")
assertCommandOutput("echo col('$')", "10")
assertCommandOutput("""echo col("abs") col(1) col([])""", "0 0 0")
assertCommandOutput("""echo col([1, 1]) col([3, '$']) col(['.', '$']) col(['$', '$'])""", "1 11 0 0")
assertCommandOutput("""echo col([0, 1]) col([1, 1]) col([5, 1]) col([6, 1]) col([5, 2])""", "0 1 1 0 2")
}
}

View File

@ -0,0 +1,49 @@
/*
* Copyright 2003-2025 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.ex.implementation.functions.cursorFunctions
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
class LineFunctionTest : VimTestCase() {
@Test
fun `test line`() {
configureByText("1\n2\n${c}3\n4\n5")
assertCommandOutput("echo line('.')", "3")
assertCommandOutput("echo line('$')", "5")
typeText("ma")
assertCommandOutput("""echo line("'a") line("'x")""", "3 0")
setEditorVisibleSize(screenWidth, 3)
setPositionAndScroll(2, 2)
assertCommandOutput("""echo line("w0") line("w$")""", "3 5")
// Without selection - current line
assertCommandOutput("""echo line("v")""", "3")
// With selection - make sure to delete the '<,'> that is automatically prepended when entering Command-line mode
// with a selection
typeText("vj")
typeText(""":<C-U>echo line("v")<CR>""") // enterCommand/assertCommandOutput cannot handle <C-U>!
assertExOutput("3")
// Remove selection and check again - note that exiting Command-line mode removes selection and switches back to
// Normal. This <esc> does nothing
typeText("<esc>")
assertCommandOutput("""echo line("v")""", "3")
assertCommandOutput("""echo line("abs") line(1) line([])""", "0 0 0")
assertCommandOutput("""echo line([1, 1]) line(['.', '$']) line(['$', '$'])""", "1 0 0")
assertCommandOutput(
"""echo line([0, 1]) line([1, 1]) line([5, 1]) line([6, 1]) line([5, 2]) line([5, 3])""",
"0 1 5 0 5 0"
)
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2003-2025 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.ex.implementation.functions.floatFunctions
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 AbsFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test abs`() {
assertCommandOutput("echo abs(-123) abs(2)", "123 2")
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2003-2025 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.ex.implementation.functions.floatFunctions
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 SinFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test sin`() {
assertCommandOutput("echo sin(0) sin(1)", "0.0 0.841471")
}
}

View File

@ -0,0 +1,39 @@
/*
* Copyright 2003-2025 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.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 JoinFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test join`() {
assertCommandOutput("echo join(['Vim', 'is', 'awesome'], '_')", "Vim_is_awesome")
}
@Test
fun `test join without second argument defaults to spaces`() {
assertCommandOutput("echo join(['Vim', 'is', 'awesome'])", "Vim is awesome")
}
@Test
fun `test join with wrong first argument type`() {
typeText(commandToKeys("echo join('Vim is awesome')"))
assertPluginError(true)
assertPluginErrorMessageContains("E1211: List required for argument 1")
}
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2003-2023 The IdeaVim authors
* Copyright 2003-2025 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.ex.implementation.functions
package org.jetbrains.plugins.ideavim.ex.implementation.functions.listFunctions
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test

View File

@ -1,17 +1,16 @@
/*
* Copyright 2003-2024 The IdeaVim authors
* Copyright 2003-2025 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.ex.implementation.functions
package org.jetbrains.plugins.ideavim.ex.implementation.functions.stringFunctions
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
class EscapeFunctionTest : VimTestCase() {
@Test
fun `test escape windows path with spaces`() {
@ -64,4 +63,4 @@ class EscapeFunctionTest : VimTestCase() {
typeText(commandToKeys("""echo escape('🎉$🎊$', '$')"""))
assertExOutput("""🎉\$🎊\$""")
}
}
}

View File

@ -0,0 +1,48 @@
/*
* Copyright 2003-2025 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.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 ToLowerFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test tolower`() {
assertCommandOutput("echo tolower('Vim is awesome')", "vim is awesome")
}
@Test
fun `test tolower with number coerces to string`() {
assertCommandOutput("echo tolower(123)", "123")
}
@Test
fun `test tolower with list causes error`() {
enterCommand("echo tolower([1, 2, 3])")
assertNoExOutput()
assertPluginError(true)
assertPluginErrorMessageContains("E730: Using a List as a String")
}
@Test
fun `test tolower with dict causes error`() {
enterCommand("echo tolower({1: 2, 3: 4})")
assertNoExOutput()
assertPluginError(true)
assertPluginErrorMessageContains("E731: Using a Dictionary as a String")
}
}

View File

@ -0,0 +1,48 @@
/*
* Copyright 2003-2025 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.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 ToUpperFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test toupper`() {
assertCommandOutput("echo toupper('Vim is awesome')", "VIM IS AWESOME")
}
@Test
fun `test toupper with number coerces to string`() {
assertCommandOutput("echo toupper(123)", "123")
}
@Test
fun `test toupper with list causes error`() {
enterCommand("echo toupper([1, 2, 3])")
assertNoExOutput()
assertPluginError(true)
assertPluginErrorMessageContains("E730: Using a List as a String")
}
@Test
fun `test toupper with dict causes error`() {
enterCommand("echo toupper({1: 2, 3: 4})")
assertNoExOutput()
assertPluginError(true)
assertPluginErrorMessageContains("E731: Using a Dictionary as a String")
}
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2003-2023 The IdeaVim authors
* Copyright 2003-2025 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.ex.implementation.functions
package org.jetbrains.plugins.ideavim.ex.implementation.functions.varFunctions
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim

View File

@ -1,12 +1,12 @@
/*
* Copyright 2003-2023 The IdeaVim authors
* Copyright 2003-2025 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.ex.implementation.functions
package org.jetbrains.plugins.ideavim.ex.implementation.functions.varFunctions
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim

View File

@ -0,0 +1,31 @@
/*
* Copyright 2003-2025 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.ex.implementation.functions.variousFunctions
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 ExistsFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test exists`() {
assertCommandOutput("echo exists(\"&nu\")", "1")
assertCommandOutput("echo exists(\"&unknownOptionName\")", "0")
assertCommandOutput("echo exists(\"g:myVar\")", "0")
enterCommand("let myVar = 42")
assertCommandOutput("echo exists(\"g:myVar\")", "1")
}
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2003-2023 The IdeaVim authors
* Copyright 2003-2025 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.ex.implementation.functions
package org.jetbrains.plugins.ideavim.ex.implementation.functions.variousFunctions
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim

View File

@ -11,7 +11,7 @@ package com.maddyhome.idea.vim.vimscript.model.functions.handlers
import com.intellij.vim.annotations.VimscriptFunction
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.ex.ExException
import com.maddyhome.idea.vim.ex.exExceptionMessage
import com.maddyhome.idea.vim.vimscript.model.VimLContext
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimBlob
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
@ -40,7 +40,7 @@ internal class LenFunctionHandler : FunctionHandler() {
is VimList -> VimInt(argument.values.size)
is VimDictionary -> VimInt(argument.dictionary.entries.size)
is VimBlob -> TODO()
else -> throw ExException("E701: Invalid type for len()")
else -> throw exExceptionMessage("E701") // E701; Invalid type for len()
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2023 The IdeaVim authors
* Copyright 2003-2025 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
@ -11,7 +11,7 @@ package com.maddyhome.idea.vim.vimscript.model.functions.handlers.listFunctions
import com.intellij.vim.annotations.VimscriptFunction
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.ex.ExException
import com.maddyhome.idea.vim.ex.exExceptionMessage
import com.maddyhome.idea.vim.vimscript.model.VimLContext
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimList
@ -30,11 +30,11 @@ internal class JoinFunctionHandler : FunctionHandler() {
context: ExecutionContext,
vimContext: VimLContext,
): VimDataType {
val firstArgument = argumentValues[0].evaluate(editor, context, vimContext)
if (firstArgument !is VimList) {
throw ExException("E714: List required")
val argument1 = argumentValues[0].evaluate(editor, context, vimContext)
if (argument1 !is VimList) {
throw exExceptionMessage("E1211", "1") // E1211: List required for argument 1
}
val secondArgument = argumentValues.getOrNull(1)?.evaluate(editor, context, vimContext) ?: VimString(" ")
return VimString(firstArgument.values.joinToString(secondArgument.asString()) { it.toString() })
val argument2 = argumentValues.getOrNull(1)?.evaluate(editor, context, vimContext)?.asString() ?: " "
return VimString(argument1.values.joinToString(argument2) { it.toString() })
}
}