refactor!: optwin.lua #36505

Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
altermo
2025-11-20 05:43:15 +01:00
committed by GitHub
parent a04c73cc17
commit caa9419355
7 changed files with 824 additions and 1356 deletions

View File

@@ -0,0 +1,101 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local command = n.command
local api = n.api
local fn = n.fn
local eval = n.eval
local feed = n.feed
local clear = n.clear
local eq = t.eq
local neq = t.neq
describe('optwin.lua', function()
before_each(clear)
it(':options shows options UI', function()
command 'options'
command '/^ 1'
local lnum = fn.line('.')
feed('<CR>')
neq(lnum, fn.line('.'))
n.add_builddir_to_rtp()
command '/^startofline'
local win = api.nvim_get_current_win()
feed('<CR>')
neq(win, api.nvim_get_current_win())
eq('help', eval('&filetype'))
api.nvim_win_close(0, true)
eq(win, api.nvim_get_current_win())
command '/^ \t'
local opt_value = eval('&startofline')
local line = api.nvim_get_current_line()
feed('<CR>')
neq(opt_value, eval('&startofline'))
neq(line, api.nvim_get_current_line())
command('set startofline!')
neq(line, api.nvim_get_current_line())
feed('<space>')
eq(line, api.nvim_get_current_line())
command 'wincmd j'
command 'wincmd k'
command '/^number'
command '/^ \t'
line = api.nvim_get_current_line()
feed('<CR>')
neq(line, api.nvim_get_current_line())
command 'wincmd o'
feed('<CR>')
neq(line, api.nvim_get_current_line())
end)
it(':options shows all options', function()
local ignore = {
-- These options are removed/unused/deprecated
'compatible',
'paste',
'highlight',
'terse',
'aleph',
'encoding',
'termencoding',
'maxcombine',
'secure',
'prompt',
'edcompatible',
'guioptions',
'guitablabel',
'guitabtooltip',
'insertmode',
'mouseshape',
'imcmdline',
'imdisable',
'pastetoggle',
'langnoremap',
'opendevice',
'ttyfast',
'remap',
'hkmap',
'hkmapp',
-- These options are read-only
'channel',
}
command 'options'
local options = ignore
for _, line in ipairs(api.nvim_buf_get_lines(0, 0, -1, true)) do
if line:match('^[a-z]') then
table.insert(options, line:match('^[a-z]+'))
end
end
eq(fn.sort(vim.tbl_keys(api.nvim_get_all_options_info())), fn.sort(options))
end)
end)

View File

@@ -108,9 +108,9 @@ func Test_options_command()
" Check if the option-window is opened horizontally.
wincmd j
call assert_notequal('option-window', bufname(''))
call assert_notequal('nvim-optwin://optwin', bufname(''))
wincmd k
call assert_equal('option-window', bufname(''))
call assert_equal('nvim-optwin://optwin', bufname(''))
" close option-window
close
@@ -118,9 +118,9 @@ func Test_options_command()
vert options
" Check if the option-window is opened vertically.
wincmd l
call assert_notequal('option-window', bufname(''))
call assert_notequal('nvim-optwin://optwin', bufname(''))
wincmd h
call assert_equal('option-window', bufname(''))
call assert_equal('nvim-optwin://optwin', bufname(''))
" close option-window
close
@@ -141,16 +141,16 @@ func Test_options_command()
tab options
" Check if the option-window is opened in a tab.
normal gT
call assert_notequal('option-window', bufname(''))
call assert_notequal('nvim-optwin://optwin', bufname(''))
normal gt
call assert_equal('option-window', bufname(''))
call assert_equal('nvim-optwin://optwin', bufname(''))
" close option-window
close
" Open the options window browse
if has('browse')
browse set
call assert_equal('option-window', bufname(''))
call assert_equal('nvim-optwin://optwin', bufname(''))
close
endif
endfunc