mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-07 05:34:02 +02:00
Add fmod function
This commit is contained in:
parent
9a5c558060
commit
91e927c913
src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/functions/floatFunctions
vim-engine/src/main
kotlin/com/maddyhome/idea/vim/vimscript/model/functions/handlers/floatFunctions
resources/ksp-generated
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 FmodFunctionTest : VimTestCase() {
|
||||
@BeforeEach
|
||||
override fun setUp(testInfo: TestInfo) {
|
||||
super.setUp(testInfo)
|
||||
configureByText("\n")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test fmod returns nan when arguments are zero`() {
|
||||
// The docs say this should return 0
|
||||
assertCommandOutput("echo fmod(0, 0) fmod(42, 0) fmod(0, 42)", "nan nan 0.0")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test fmod with integer values`() {
|
||||
assertCommandOutput("echo fmod(12, 7)", "5.0")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test fmod with float values`() {
|
||||
assertCommandOutput("echo fmod(12.33, 1.22)", "0.13")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test fmod with negative values`() {
|
||||
assertCommandOutput("echo fmod(-12.33, 1.22)", "-0.13")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test fmod with string value causes errors`() {
|
||||
enterCommand("echo fmod('42', 7)")
|
||||
assertPluginError(true)
|
||||
assertPluginErrorMessageContains("E808: Number or Float required")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test fmod with string value causes errors 2`() {
|
||||
enterCommand("echo fmod(42, '7')")
|
||||
assertPluginError(true)
|
||||
assertPluginErrorMessageContains("E808: Number or Float required")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test fmod with list value causes errors`() {
|
||||
enterCommand("echo fmod([1, 2], 7)")
|
||||
assertPluginError(true)
|
||||
assertPluginErrorMessageContains("E808: Number or Float required")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test fmod with list value causes errors 2`() {
|
||||
enterCommand("echo fmod(42, [1, 2])")
|
||||
assertPluginError(true)
|
||||
assertPluginErrorMessageContains("E808: Number or Float required")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test fmod with dictionary value causes errors`() {
|
||||
enterCommand("echo fmod({1: 2}, 7)")
|
||||
assertPluginError(true)
|
||||
assertPluginErrorMessageContains("E808: Number or Float required")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test fmod with dictionary value causes errors 2`() {
|
||||
enterCommand("echo fmod(42, {1: 2})")
|
||||
assertPluginError(true)
|
||||
assertPluginErrorMessageContains("E808: Number or Float required")
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 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.floatFunctions
|
||||
|
||||
import com.intellij.vim.annotations.VimscriptFunction
|
||||
|
||||
@VimscriptFunction("fmod")
|
||||
internal class FmodFunctionHandler : BinaryFloatFunctionHandlerBase() {
|
||||
override fun invoke(arg1: Double, arg2: Double) = arg1 % arg2
|
||||
}
|
@ -14,6 +14,7 @@
|
||||
"exists": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.variousFunctions.ExistsFunctionHandler",
|
||||
"exp": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.floatFunctions.ExpFunctionHandler",
|
||||
"floor": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.floatFunctions.FloorFunctionHandler",
|
||||
"fmod": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.floatFunctions.FmodFunctionHandler",
|
||||
"funcref": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.varFunctions.FuncrefFunctionHandler",
|
||||
"function": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.varFunctions.FunctionFunctionHandler",
|
||||
"get": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.GetFunctionHandler",
|
||||
@ -40,4 +41,4 @@
|
||||
"toupper": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.stringFunctions.ToupperFunctionHandler",
|
||||
"trunc": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.floatFunctions.TruncFunctionHandler",
|
||||
"xor": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.bitwiseFunctions.XorFunctionHandler"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user