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

Add err_teapot function

This commit is contained in:
Matt Ellis 2025-02-19 09:25:11 +00:00 committed by Alex Pláte
parent 06791b9378
commit 5740372df9
4 changed files with 113 additions and 0 deletions
src
main/resources/messages
test/java/org/jetbrains/plugins/ideavim/ex/implementation/functions/variousFunctions
vim-engine/src/main
kotlin/com/maddyhome/idea/vim/vimscript/model/functions/handlers/variousFunctions
resources/ksp-generated

View File

@ -67,6 +67,7 @@ E363=E363: pattern caused out-of-stack error
E369=E369: invalid item in {0}%[]
E384=E384: Search hit TOP without match for: {0}
E385=E385: Search hit BOTTOM without match for: {0}
E418=E418: I am a teapot
E471=E471: Argument required
E474=E474: Invalid argument: {0}
E475=E475: Invalid argument: {0}
@ -77,6 +78,7 @@ E488=E488: Trailing characters: {0}
# Vim's message includes alternate files and the :p:h file name modifier, which we don't support
# E499: Empty file name for '%' or '#', only works with ":p:h"
E499=E499: Empty file name for '%'
E503=E503: Coffee is currently not available
E518=E518: Unknown option: {0}
E521=E521: Number required after =: {0}
E545=E545: Missing colon: {0}

View File

@ -0,0 +1,71 @@
/*
* 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 ErrTeapotFunctionTest : VimTestCase() {
@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}
@Test
fun `test err_teapot`() {
enterCommand("echo err_teapot()")
assertPluginError(true)
assertPluginErrorMessageContains("E418: I am a teapot")
}
@Test
fun `test err_teapot with boolean false argument`() {
enterCommand("echo err_teapot(0)")
assertPluginError(true)
assertPluginErrorMessageContains("E418: I am a teapot")
}
@Test
fun `test err_teapot with boolean true argument`() {
enterCommand("echo err_teapot(1)")
assertPluginError(true)
assertPluginErrorMessageContains("E503: Coffee is currently not available")
}
@Test
fun `test err_teapot with false string argument`() {
enterCommand("echo err_teapot(\"0\")")
assertPluginError(true)
assertPluginErrorMessageContains("E418: I am a teapot")
}
@Test
fun `test err_teapot with true string argument`() {
enterCommand("echo err_teapot(\"1\")")
assertPluginError(true)
assertPluginErrorMessageContains("E503: Coffee is currently not available")
}
@Test
fun `test err_teapot with list argument`() {
enterCommand("echo err_teapot([0])")
assertPluginError(true)
assertPluginErrorMessageContains("E745: Using a List as a Number")
}
@Test
fun `test err_teapot with dictionary argument`() {
enterCommand("echo err_teapot({1: 0})")
assertPluginError(true)
assertPluginErrorMessageContains("E728: Using a Dictionary as a Number")
}
}

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 com.maddyhome.idea.vim.vimscript.model.functions.handlers.variousFunctions
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.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.expressions.Expression
import com.maddyhome.idea.vim.vimscript.model.functions.FunctionHandler
@VimscriptFunction(name = "err_teapot")
class ErrTeapotFunctionHandler : FunctionHandler() {
override val minimumNumberOfArguments = 0
override val maximumNumberOfArguments: Int? = 1
override fun doFunction(
argumentValues: List<Expression>,
editor: VimEditor,
context: ExecutionContext,
vimContext: VimLContext,
): VimDataType {
val arg1 = argumentValues.getOrNull(0)?.evaluate(editor, context, vimContext)?.asBoolean() ?: false
if (arg1) {
throw exExceptionMessage("E503")
}
else {
throw exExceptionMessage("E418")
}
}
}

View File

@ -10,6 +10,7 @@
"cos": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.floatFunctions.CosFunctionHandler",
"cosh": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.floatFunctions.CoshFunctionHandler",
"empty": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.EmptyFunctionHandler",
"err_teapot": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.variousFunctions.ErrTeapotFunctionHandler",
"escape": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.stringFunctions.EscapeFunctionHandler",
"exists": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.variousFunctions.ExistsFunctionHandler",
"exp": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.floatFunctions.ExpFunctionHandler",