Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve formatting of :set command output #666

Merged
merged 7 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/maddyhome/idea/vim/ui/ExOutputPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ private ExOutputPanel(@NotNull Editor editor) {
add(myScrollPane, BorderLayout.CENTER);
add(myLabel, BorderLayout.SOUTH);

// Set the text area read only, and support wrap
myText.setEditable(false);
myText.setLineWrap(true);

myAdapter = new ComponentAdapter() {
@Override
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/org/jetbrains/plugins/ideavim/VimTestCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,14 @@ abstract class VimTestCase {
assertEquals(expected, selected)
}

fun assertCommandOutput(command: String, expected: String) {
enterCommand(command)
assertExOutput(expected)
}

fun assertExOutput(expected: String) {
val actual = getInstance(fixture.editor).text
assertNotNull("No Ex output", actual)
assertNotNull(actual, "No Ex output")
assertEquals(expected, actual)
NeovimTesting.typeCommand("<esc>", testInfo, fixture.editor)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,67 @@ package org.jetbrains.plugins.ideavim.ex.implementation.commands
import com.maddyhome.idea.vim.api.Options
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.options.OptionScope
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
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

@Suppress("SpellCheckingInspection")
class SetCommandTest : VimTestCase() {

@BeforeEach
override fun setUp(testInfo: TestInfo) {
super.setUp(testInfo)
configureByText("\n")
}

private fun setOsSpecificOptionsToSafeValues() {
enterCommand("set shell=/dummy/path/to/bash")
enterCommand("set shellcmdflag=-x")
enterCommand("set shellxescape=@")
enterCommand("set shellxquote={")
}

@Test
fun `test unknown option`() {
configureByText("\n")
enterCommand("set unknownOption")
assertPluginError(true)
assertPluginErrorMessageContains("Unknown option: unknownOption")
}

@Test
fun `test toggle option`() {
configureByText("\n")
enterCommand("set rnu")
assertTrue(options().relativenumber)
enterCommand("set rnu!")
assertFalse(options().relativenumber)
}

// todo we have spaces in assertExOutput because of pad(20) in the com.maddyhome.idea.vim.vimscript.model.commands.SetCommandKt#showOptions method
@TestWithoutNeovim(reason = SkipNeovimReason.OPTION)
@Test
fun `test number option`() {
configureByText("\n")
enterCommand("set scrolloff&")
assertEquals(0, options().scrolloff)
enterCommand("set scrolloff?")
assertExOutput("scrolloff=0 \n")
assertCommandOutput("set scrolloff?", " scrolloff=0\n")
enterCommand("set scrolloff=5")
assertEquals(5, options().scrolloff)
enterCommand("set scrolloff?")
assertExOutput("scrolloff=5 \n")
assertCommandOutput("set scrolloff?", " scrolloff=5\n")
}

@TestWithoutNeovim(reason = SkipNeovimReason.OPTION)
@Test
fun `test toggle option as a number`() {
configureByText("\n")
enterCommand("set number&")
assertEquals(0, injector.optionGroup.getOptionValue(Options.number, OptionScope.GLOBAL).asDouble().toInt())
enterCommand("set number?")
assertExOutput("nonumber \n")
assertCommandOutput("set number?", "nonumber\n")
enterCommand("let &nu=1000")
assertEquals(1000, injector.optionGroup.getOptionValue(Options.number, OptionScope.GLOBAL).asDouble().toInt())
enterCommand("set number?")
assertExOutput(" number \n")
assertCommandOutput("set number?", " number\n")
}

@TestWithoutNeovim(reason = SkipNeovimReason.PLUGIN_ERROR)
@Test
fun `test toggle option exceptions`() {
configureByText("\n")
enterCommand("set number+=10")
assertPluginError(true)
assertPluginErrorMessageContains("E474: Invalid argument: number+=10")
Expand All @@ -93,10 +94,8 @@ class SetCommandTest : VimTestCase() {
assertPluginErrorMessageContains("E474: Invalid argument: number-=test")
}

@TestWithoutNeovim(reason = SkipNeovimReason.PLUGIN_ERROR)
@Test
fun `test number option exceptions`() {
configureByText("\n")
enterCommand("set scrolloff+=10")
assertPluginError(false)
enterCommand("set scrolloff+=test")
Expand All @@ -116,33 +115,188 @@ class SetCommandTest : VimTestCase() {
assertPluginErrorMessageContains("E521: Number required after =: scrolloff-=test")
}

@TestWithoutNeovim(reason = SkipNeovimReason.OPTION)
@Test
fun `test string option`() {
configureByText("\n")
enterCommand("set selection&")
assertEquals("inclusive", options().selection)
enterCommand("set selection?")
assertExOutput("selection=inclusive \n")
assertCommandOutput("set selection?", " selection=inclusive\n")
enterCommand("set selection=exclusive")
assertEquals("exclusive", options().selection)
enterCommand("set selection?")
assertExOutput("selection=exclusive \n")
assertCommandOutput("set selection?", " selection=exclusive\n")
}

@TestWithoutNeovim(reason = SkipNeovimReason.OPTION)
@Test
fun `test show numbered value`() {
configureByText("\n")
enterCommand("set so")
assertExOutput("scrolloff=0 \n")
assertCommandOutput("set so", " scrolloff=0\n")
}

@TestWithoutNeovim(reason = SkipNeovimReason.OPTION)
@Test
fun `test show numbered value with question mark`() {
configureByText("\n")
enterCommand("set so?")
assertExOutput("scrolloff=0 \n")
assertCommandOutput("set so?", " scrolloff=0\n")
}

@Test
fun `test show all modified effective option values`() {
enterCommand("set number relativenumber scrolloff nrformats")
assertCommandOutput("set",
"""
|--- Options ---
| ideastrictmode number relativenumber
|
""".trimMargin())
}

@Test
fun `test show all effective option values`() {
setOsSpecificOptionsToSafeValues()
assertCommandOutput("set all",
"""
|--- Options ---
|noargtextobj ideawrite=all scrolljump=1 notextobj-indent
| closenotebooks noignorecase scrolloff=0 timeout
|nocommentary noincsearch selectmode= timeoutlen=1000
|nodigraph nomatchit shellcmdflag=-x notrackactionids
|noexchange maxmapdepth=20 shellxescape=@ undolevels=1000
|nogdefault more shellxquote={ unifyjumps
|nohighlightedyank nomultiple-cursors showcmd virtualedit=
| history=50 noNERDTree showmode novisualbell
|nohlsearch nrformats=hex sidescroll=0 visualdelay=100
|noideaglobalmode nonumber sidescrolloff=0 whichwrap=b,s
|noideajoin nooctopushandler nosmartcase wrapscan
| ideamarks oldundo startofline
| ideastrictmode norelativenumber nosurround
|noideatracetime scroll=0 notextobj-entire
| clipboard=ideaput,autoselect,exclude:cons\|linux
| excommandannotation
| guicursor=n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
| ide=IntelliJ IDEA Community Edition
|noideacopypreprocess
| idearefactormode=select
| ideastatusicon=enabled
| ideavimsupport=dialog
| iskeyword=@,48-57,_
| keymodel=continueselect,stopselect
| lookupkeys=<Tab>,<Down>,<Up>,<Enter>,<Left>,<Right>,<C-Down>,<C-Up>,<PageUp>,<PageDown>,<C-J>,<C-Q>
| matchpairs=(:),{:},[:]
|noReplaceWithRegister
| selection=inclusive
| shell=/dummy/path/to/bash
|novim-paragraph-motion
| viminfo='100,<50,s10,h
| vimscriptfunctionannotation
|
""".trimMargin())
}

@Test
fun `test show named options`() {
assertCommandOutput("set number? relativenumber? scrolloff? nrformats?", """
| nrformats=hex nonumber norelativenumber scrolloff=0
|""".trimMargin()
)
}

@Test
fun `test show all modified option values in single column`() {
enterCommand("set number relativenumber scrolloff nrformats")
assertCommandOutput("set!",
"""
|--- Options ---
| ideastrictmode
| number
| relativenumber
|""".trimMargin()
)
}

@Test
fun `test show all option values in single column`() {
setOsSpecificOptionsToSafeValues()
assertCommandOutput("set! all", """
|--- Options ---
|noargtextobj
| clipboard=ideaput,autoselect,exclude:cons\|linux
| closenotebooks
|nocommentary
|nodigraph
|noexchange
| excommandannotation
|nogdefault
| guicursor=n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
|nohighlightedyank
| history=50
|nohlsearch
| ide=IntelliJ IDEA Community Edition
|noideacopypreprocess
|noideaglobalmode
|noideajoin
| ideamarks
| idearefactormode=select
| ideastatusicon=enabled
| ideastrictmode
|noideatracetime
| ideavimsupport=dialog
| ideawrite=all
|noignorecase
|noincsearch
| iskeyword=@,48-57,_
| keymodel=continueselect,stopselect
| lookupkeys=<Tab>,<Down>,<Up>,<Enter>,<Left>,<Right>,<C-Down>,<C-Up>,<PageUp>,<PageDown>,<C-J>,<C-Q>
|nomatchit
| matchpairs=(:),{:},[:]
| maxmapdepth=20
| more
|nomultiple-cursors
|noNERDTree
| nrformats=hex
|nonumber
|nooctopushandler
| oldundo
|norelativenumber
|noReplaceWithRegister
| scroll=0
| scrolljump=1
| scrolloff=0
| selection=inclusive
| selectmode=
| shell=/dummy/path/to/bash
| shellcmdflag=-x
| shellxescape=@
| shellxquote={
| showcmd
| showmode
| sidescroll=0
| sidescrolloff=0
|nosmartcase
| startofline
|nosurround
|notextobj-entire
|notextobj-indent
| timeout
| timeoutlen=1000
|notrackactionids
| undolevels=1000
| unifyjumps
|novim-paragraph-motion
| viminfo='100,<50,s10,h
| vimscriptfunctionannotation
| virtualedit=
|novisualbell
| visualdelay=100
| whichwrap=b,s
| wrapscan
|""".trimMargin()
)
}

@Test
fun `test show named options in single column`() {
assertCommandOutput("set! number? relativenumber? scrolloff? nrformats?", """
| nrformats=hex
|nonumber
|norelativenumber
| scrolloff=0
|""".trimMargin()
)
}
}
Loading