Skip to content

Commit

Permalink
Add some tests for the getcmdtype() function
Browse files Browse the repository at this point in the history
  • Loading branch information
jphalip authored and AlexPl292 committed Nov 22, 2024
1 parent 52737c6 commit c75e675
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2003-2024 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 com.maddyhome.idea.vim.ui.ex.ExEntryPanel
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class GetCmdTypeFunctionTest : VimTestCase() {

@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)
}

@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)
}

@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)
}

@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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import com.maddyhome.idea.vim.vimscript.model.functions.FunctionHandler
/*
Return the current command-line type. Possible return values are:
: normal Ex command
> debug mode command debug-mode
/ forward search command
? backward search command
= i_CTRL-R_=
Returns an empty string otherwise.
Not yet implemented:
> debug mode command debug-mode
@ input() command
- :insert or :append command
*/
Expand Down

0 comments on commit c75e675

Please sign in to comment.