2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-12-01 07:41:03 -07:00
|
|
|
local nvim = helpers.meths
|
2021-11-22 00:50:14 -07:00
|
|
|
local clear, eq, neq, eval = helpers.clear, helpers.eq, helpers.neq, helpers.eval
|
2015-12-01 07:41:03 -07:00
|
|
|
local curbuf, buf = helpers.curbuf, helpers.bufmeths
|
2016-02-12 04:38:20 -07:00
|
|
|
local curwin = helpers.curwin
|
2021-09-19 02:29:37 -07:00
|
|
|
local exec_capture = helpers.exec_capture
|
2017-04-08 14:12:26 -07:00
|
|
|
local source, command = helpers.source, helpers.command
|
2015-11-27 08:41:50 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
local function declare_hook_function()
|
|
|
|
source([[
|
|
|
|
fu! AutoCommand(match, bufnr, winnr)
|
|
|
|
let l:acc = {
|
2021-11-22 00:50:14 -07:00
|
|
|
\ 'option' : a:match,
|
|
|
|
\ 'oldval' : v:option_old,
|
|
|
|
\ 'oldval_l' : v:option_oldlocal,
|
|
|
|
\ 'oldval_g' : v:option_oldglobal,
|
|
|
|
\ 'newval' : v:option_new,
|
|
|
|
\ 'scope' : v:option_type,
|
|
|
|
\ 'cmd' : v:option_command,
|
|
|
|
\ 'attr' : {
|
2015-12-01 07:41:03 -07:00
|
|
|
\ 'bufnr' : a:bufnr,
|
|
|
|
\ 'winnr' : a:winnr,
|
|
|
|
\ }
|
|
|
|
\ }
|
|
|
|
call add(g:ret, l:acc)
|
|
|
|
endfu
|
|
|
|
]])
|
|
|
|
end
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
local function set_hook(pattern)
|
2017-04-08 14:12:26 -07:00
|
|
|
command(
|
2015-12-01 07:41:03 -07:00
|
|
|
'au OptionSet '
|
|
|
|
.. pattern ..
|
|
|
|
' :call AutoCommand(expand("<amatch>"), bufnr("%"), winnr())'
|
|
|
|
)
|
|
|
|
end
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
local function init_var()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('let g:ret = []')
|
2015-12-01 07:41:03 -07:00
|
|
|
end
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
local function get_result()
|
|
|
|
local ret = nvim.get_var('ret')
|
|
|
|
init_var()
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
local function expected_table(option, oldval, oldval_l, oldval_g, newval, scope, cmd, attr)
|
2015-12-01 07:41:03 -07:00
|
|
|
return {
|
2021-11-22 00:50:14 -07:00
|
|
|
option = option,
|
|
|
|
oldval = tostring(oldval),
|
|
|
|
oldval_l = tostring(oldval_l),
|
|
|
|
oldval_g = tostring(oldval_g),
|
|
|
|
newval = tostring(newval),
|
|
|
|
scope = scope,
|
|
|
|
cmd = cmd,
|
|
|
|
attr = attr,
|
2015-12-01 07:41:03 -07:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
local function expected_combination(...)
|
|
|
|
local args = {...}
|
|
|
|
local ret = get_result()
|
|
|
|
|
|
|
|
if not (#args == #ret) then
|
|
|
|
local expecteds = {}
|
|
|
|
for _, v in pairs(args) do
|
|
|
|
table.insert(expecteds, expected_table(unpack(v)))
|
|
|
|
end
|
|
|
|
eq(expecteds, ret)
|
|
|
|
return
|
|
|
|
end
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
for i, v in ipairs(args) do
|
2021-11-22 00:50:14 -07:00
|
|
|
local attr = v[8]
|
2015-12-01 07:41:03 -07:00
|
|
|
if not attr then
|
|
|
|
-- remove attr entries
|
|
|
|
ret[i].attr = nil
|
|
|
|
else
|
|
|
|
-- remove attr entries which are not required
|
|
|
|
for k in pairs(ret[i].attr) do
|
|
|
|
if not attr[k] then
|
|
|
|
ret[i].attr[k] = nil
|
|
|
|
end
|
2015-11-28 01:06:23 -07:00
|
|
|
end
|
2015-12-01 07:41:03 -07:00
|
|
|
end
|
|
|
|
eq(expected_table(unpack(v)), ret[i])
|
|
|
|
end
|
|
|
|
end
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
local function expected_empty()
|
|
|
|
eq({}, get_result())
|
|
|
|
end
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
local function make_buffer()
|
|
|
|
local old_buf = curbuf()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('botright new')
|
2015-12-01 07:41:03 -07:00
|
|
|
local new_buf = curbuf()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('wincmd p') -- move previous window
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
neq(old_buf, new_buf)
|
|
|
|
eq(old_buf, curbuf())
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
return new_buf
|
|
|
|
end
|
|
|
|
|
2016-02-12 04:38:20 -07:00
|
|
|
local function get_new_window_number()
|
2016-02-11 22:01:35 -07:00
|
|
|
local old_win = curwin()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('botright new')
|
2016-02-11 22:01:35 -07:00
|
|
|
local new_win = curwin()
|
2021-09-19 02:29:37 -07:00
|
|
|
local new_winnr = exec_capture('echo winnr()')
|
2017-04-08 14:12:26 -07:00
|
|
|
command('wincmd p') -- move previous window
|
2016-02-11 22:01:35 -07:00
|
|
|
|
|
|
|
neq(old_win, new_win)
|
|
|
|
eq(old_win, curwin())
|
|
|
|
|
2021-09-19 02:29:37 -07:00
|
|
|
return new_winnr
|
2016-02-11 22:01:35 -07:00
|
|
|
end
|
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
describe('au OptionSet', function()
|
2021-11-22 00:50:14 -07:00
|
|
|
describe('with any option (*)', function()
|
2015-12-01 07:41:03 -07:00
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
declare_hook_function()
|
|
|
|
init_var()
|
|
|
|
set_hook('*')
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('should be called in setting number option', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set nu')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'number', 0, 0, 0, 1, 'global', 'set'})
|
2015-12-01 07:41:03 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('setlocal nonu')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'number', 1, 1, '', 0, 'local', 'setlocal'})
|
2015-12-01 07:41:03 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('setglobal nonu')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'number', 1, '', 1, 0, 'global', 'setglobal'})
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('should be called in setting autoindent option',function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('setlocal ai')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'autoindent', 0, 0, '', 1, 'local', 'setlocal'})
|
2015-12-01 07:41:03 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('setglobal ai')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'autoindent', 0, '', 0, 1, 'global', 'setglobal'})
|
2015-12-01 07:41:03 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set noai')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'autoindent', 1, 1, 1, 0, 'global', 'set'})
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('should be called in inverting global autoindent option',function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set ai!')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'autoindent', 0, 0, 0, 1, 'global', 'set'})
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('should be called in being unset local autoindent option',function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('setlocal ai')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'autoindent', 0, 0, '', 1, 'local', 'setlocal'})
|
2015-12-01 07:41:03 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('setlocal ai<')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'autoindent', 1, 1, '', 0, 'local', 'setlocal'})
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('should be called in setting global list and number option at the same time',function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set list nu')
|
2015-12-01 07:41:03 -07:00
|
|
|
expected_combination(
|
2021-11-22 00:50:14 -07:00
|
|
|
{'list', 0, 0, 0, 1, 'global', 'set'},
|
|
|
|
{'number', 0, 0, 0, 1, 'global', 'set'}
|
2015-12-01 07:41:03 -07:00
|
|
|
)
|
|
|
|
end)
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
it('should not print anything, use :noa', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('noa set nolist nonu')
|
2015-12-01 07:41:03 -07:00
|
|
|
expected_empty()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('should be called in setting local acd', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('setlocal acd')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'autochdir', 0, 0, '', 1, 'local', 'setlocal'})
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('should be called in setting autoread', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set noar')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'autoread', 1, 1, 1, 0, 'global', 'set'})
|
2015-12-01 07:41:03 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('setlocal ar')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'autoread', 0, 0, '', 1, 'local', 'setlocal'})
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('should be called in inverting global autoread', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('setglobal invar')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'autoread', 1, '', 1, 0, 'global', 'setglobal'})
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
it('should be called in setting backspace option through :let', function()
|
2021-11-22 00:50:14 -07:00
|
|
|
local oldval = eval('&backspace')
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('let &bs=""')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'backspace', oldval, oldval, oldval, '', 'global', 'set'})
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
2015-11-28 04:09:56 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
describe('being set by setbufvar()', function()
|
|
|
|
it('should not trigger because option name is invalid', function()
|
2017-04-08 16:17:03 -07:00
|
|
|
command('silent! call setbufvar(1, "&l:bk", 1)')
|
2015-12-01 07:41:03 -07:00
|
|
|
expected_empty()
|
2015-11-28 01:06:23 -07:00
|
|
|
end)
|
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
it('should trigger using correct option name', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('call setbufvar(1, "&backup", 1)')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'backup', 0, 0, '', 1, 'local', 'setlocal'})
|
2015-11-28 01:06:23 -07:00
|
|
|
end)
|
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
it('should trigger if the current buffer is different from the targetted buffer', function()
|
|
|
|
local new_buffer = make_buffer()
|
|
|
|
local new_bufnr = buf.get_number(new_buffer)
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'buftype', '', '', '', 'nofile', 'local', 'setlocal', {bufnr = new_bufnr}})
|
2015-11-28 01:06:23 -07:00
|
|
|
end)
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
2021-11-22 00:50:14 -07:00
|
|
|
|
|
|
|
it('with string global option', function()
|
|
|
|
local oldval = eval('&backupext')
|
|
|
|
|
|
|
|
command('set backupext=foo')
|
|
|
|
expected_combination({'backupext', oldval, oldval, oldval, 'foo', 'global', 'set'})
|
|
|
|
|
|
|
|
command('set backupext&')
|
|
|
|
expected_combination({'backupext', 'foo', 'foo', 'foo', oldval, 'global', 'set'})
|
|
|
|
|
|
|
|
command('setglobal backupext=bar')
|
|
|
|
expected_combination({'backupext', oldval, '', oldval, 'bar', 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa set backupext&')
|
|
|
|
-- As this is a global option this sets the global value even though :setlocal is used!
|
|
|
|
command('setlocal backupext=baz')
|
|
|
|
expected_combination({'backupext', oldval, oldval, '', 'baz', 'local', 'setlocal'})
|
|
|
|
|
|
|
|
command('noa setglobal backupext=ext_global')
|
|
|
|
command('noa setlocal backupext=ext_local') -- Sets the global(!) value
|
|
|
|
command('set backupext=foo')
|
|
|
|
expected_combination({
|
|
|
|
'backupext', 'ext_local', 'ext_local', 'ext_local', 'foo', 'global', 'set'
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with string global-local (to buffer) option', function()
|
|
|
|
local oldval = eval('&tags')
|
|
|
|
|
|
|
|
command('set tags=tagpath')
|
|
|
|
expected_combination({'tags', oldval, oldval, oldval, 'tagpath', 'global', 'set'})
|
|
|
|
|
|
|
|
command('set tags&')
|
|
|
|
expected_combination({'tags', 'tagpath', 'tagpath', 'tagpath', oldval, 'global', 'set'})
|
|
|
|
|
|
|
|
command('setglobal tags=tagpath1')
|
|
|
|
expected_combination({'tags', oldval, '', oldval, 'tagpath1', 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('setlocal tags=tagpath2')
|
|
|
|
expected_combination({'tags', 'tagpath1', 'tagpath1', '', 'tagpath2', 'local', 'setlocal'})
|
|
|
|
|
|
|
|
-- Note: v:option_old is the old global value for global-local string options
|
|
|
|
-- but the old local value for all other kinds of options.
|
|
|
|
command('noa setglobal tags=tag_global')
|
|
|
|
command('noa setlocal tags=tag_local')
|
|
|
|
command('set tags=tagpath')
|
|
|
|
expected_combination({
|
|
|
|
'tags', 'tag_global', 'tag_local', 'tag_global', 'tagpath', 'global', 'set'
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Note: v:option_old is the old global value for global-local string options
|
|
|
|
-- but the old local value for all other kinds of options.
|
|
|
|
command('noa set tags=tag_global')
|
|
|
|
command('noa setlocal tags=')
|
|
|
|
command('set tags=tagpath')
|
|
|
|
expected_combination({'tags', 'tag_global', '', 'tag_global', 'tagpath', 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with string local (to buffer) option', function()
|
|
|
|
local oldval = eval('&spelllang')
|
|
|
|
|
|
|
|
command('set spelllang=elvish,klingon')
|
|
|
|
expected_combination({'spelllang', oldval, oldval, oldval, 'elvish,klingon', 'global', 'set'})
|
|
|
|
|
|
|
|
command('set spelllang&')
|
|
|
|
expected_combination({
|
|
|
|
'spelllang', 'elvish,klingon', 'elvish,klingon', 'elvish,klingon', oldval, 'global', 'set'
|
|
|
|
})
|
|
|
|
|
|
|
|
command('setglobal spelllang=elvish')
|
|
|
|
expected_combination({'spelllang', oldval, '', oldval, 'elvish', 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa set spelllang&')
|
|
|
|
command('setlocal spelllang=klingon')
|
|
|
|
expected_combination({'spelllang', oldval, oldval, '', 'klingon', 'local', 'setlocal'})
|
|
|
|
|
|
|
|
-- Note: v:option_old is the old global value for global-local string options
|
|
|
|
-- but the old local value for all other kinds of options.
|
|
|
|
command('noa setglobal spelllang=spellglobal')
|
|
|
|
command('noa setlocal spelllang=spelllocal')
|
|
|
|
command('set spelllang=foo')
|
|
|
|
expected_combination({
|
|
|
|
'spelllang', 'spelllocal', 'spelllocal', 'spellglobal', 'foo', 'global', 'set'
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with string global-local (to window) option', function()
|
|
|
|
local oldval = eval('&statusline')
|
|
|
|
|
|
|
|
command('set statusline=foo')
|
|
|
|
expected_combination({'statusline', oldval, oldval, '', 'foo', 'global', 'set'})
|
|
|
|
|
|
|
|
-- Note: v:option_old is the old global value for global-local string options
|
|
|
|
-- but the old local value for all other kinds of options.
|
|
|
|
command('set statusline&')
|
|
|
|
expected_combination({'statusline', 'foo', 'foo', 'foo', oldval, 'global', 'set'})
|
|
|
|
|
|
|
|
command('setglobal statusline=bar')
|
|
|
|
expected_combination({'statusline', oldval, '', oldval, 'bar', 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa set statusline&')
|
|
|
|
command('setlocal statusline=baz')
|
|
|
|
expected_combination({'statusline', oldval, oldval, '', 'baz', 'local', 'setlocal'})
|
|
|
|
|
|
|
|
-- Note: v:option_old is the old global value for global-local string options
|
|
|
|
-- but the old local value for all other kinds of options.
|
|
|
|
command('noa setglobal statusline=bar')
|
|
|
|
command('noa setlocal statusline=baz')
|
|
|
|
command('set statusline=foo')
|
|
|
|
expected_combination({'statusline', 'bar', 'baz', 'bar', 'foo', 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with string local (to window) option', function()
|
|
|
|
local oldval = eval('&foldignore')
|
|
|
|
|
|
|
|
command('set foldignore=fo')
|
|
|
|
expected_combination({'foldignore', oldval, oldval, oldval, 'fo', 'global', 'set'})
|
|
|
|
|
|
|
|
command('set foldignore&')
|
|
|
|
expected_combination({'foldignore', 'fo', 'fo', 'fo', oldval, 'global', 'set'})
|
|
|
|
|
|
|
|
command('setglobal foldignore=bar')
|
|
|
|
expected_combination({'foldignore', oldval, '', oldval, 'bar', 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa set foldignore&')
|
|
|
|
command('setlocal foldignore=baz')
|
|
|
|
expected_combination({'foldignore', oldval, oldval, '', 'baz', 'local', 'setlocal'})
|
|
|
|
|
|
|
|
command('noa setglobal foldignore=glob')
|
|
|
|
command('noa setlocal foldignore=loc')
|
|
|
|
command('set foldignore=fo')
|
|
|
|
expected_combination({'foldignore', 'loc', 'loc', 'glob', 'fo', 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with number global option', function()
|
|
|
|
command('noa setglobal cmdheight=8')
|
|
|
|
command('noa setlocal cmdheight=1') -- Sets the global(!) value
|
|
|
|
command('setglobal cmdheight=2')
|
|
|
|
expected_combination({'cmdheight', 1, '', 1, 2, 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa setglobal cmdheight=8')
|
|
|
|
command('noa setlocal cmdheight=1') -- Sets the global(!) value
|
|
|
|
command('setlocal cmdheight=2')
|
|
|
|
expected_combination({'cmdheight', 1, 1, '', 2, 'local', 'setlocal'})
|
|
|
|
|
|
|
|
command('noa setglobal cmdheight=8')
|
|
|
|
command('noa setlocal cmdheight=1') -- Sets the global(!) value
|
|
|
|
command('set cmdheight=2')
|
|
|
|
expected_combination({'cmdheight', 1, 1, 1, 2, 'global', 'set'})
|
|
|
|
|
|
|
|
command('noa set cmdheight=8')
|
|
|
|
command('set cmdheight=2')
|
|
|
|
expected_combination({'cmdheight', 8, 8, 8, 2, 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with number global-local (to buffer) option', function()
|
|
|
|
command('noa setglobal undolevels=8')
|
|
|
|
command('noa setlocal undolevels=1')
|
|
|
|
command('setglobal undolevels=2')
|
|
|
|
expected_combination({'undolevels', 8, '', 8, 2, 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa setglobal undolevels=8')
|
|
|
|
command('noa setlocal undolevels=1')
|
|
|
|
command('setlocal undolevels=2')
|
|
|
|
expected_combination({'undolevels', 1, 1, '', 2, 'local', 'setlocal'})
|
|
|
|
|
|
|
|
command('noa setglobal undolevels=8')
|
|
|
|
command('noa setlocal undolevels=1')
|
|
|
|
command('set undolevels=2')
|
|
|
|
expected_combination({'undolevels', 1, 1, 8, 2, 'global', 'set'})
|
|
|
|
|
|
|
|
command('noa set undolevels=8')
|
|
|
|
command('set undolevels=2')
|
|
|
|
expected_combination({'undolevels', 8, 8, 8, 2, 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with number local (to buffer) option', function()
|
|
|
|
command('noa setglobal wrapmargin=8')
|
|
|
|
command('noa setlocal wrapmargin=1')
|
|
|
|
command('setglobal wrapmargin=2')
|
|
|
|
expected_combination({'wrapmargin', 8, '', 8, 2, 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa setglobal wrapmargin=8')
|
|
|
|
command('noa setlocal wrapmargin=1')
|
|
|
|
command('setlocal wrapmargin=2')
|
|
|
|
expected_combination({'wrapmargin', 1, 1, '', 2, 'local', 'setlocal'})
|
|
|
|
|
|
|
|
command('noa setglobal wrapmargin=8')
|
|
|
|
command('noa setlocal wrapmargin=1')
|
|
|
|
command('set wrapmargin=2')
|
|
|
|
expected_combination({'wrapmargin', 1, 1, 8, 2, 'global', 'set'})
|
|
|
|
|
|
|
|
command('noa set wrapmargin=8')
|
|
|
|
command('set wrapmargin=2')
|
|
|
|
expected_combination({'wrapmargin', 8, 8, 8, 2, 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with number global-local (to window) option', function()
|
|
|
|
command('noa setglobal scrolloff=8')
|
|
|
|
command('noa setlocal scrolloff=1')
|
|
|
|
command('setglobal scrolloff=2')
|
|
|
|
expected_combination({'scrolloff', 8, '', 8, 2, 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa setglobal scrolloff=8')
|
|
|
|
command('noa setlocal scrolloff=1')
|
|
|
|
command('setlocal scrolloff=2')
|
|
|
|
expected_combination({'scrolloff', 1, 1, '', 2, 'local', 'setlocal'})
|
|
|
|
|
|
|
|
command('noa setglobal scrolloff=8')
|
|
|
|
command('noa setlocal scrolloff=1')
|
|
|
|
command('set scrolloff=2')
|
|
|
|
expected_combination({'scrolloff', 1, 1, 8, 2, 'global', 'set'})
|
|
|
|
|
|
|
|
command('noa set scrolloff=8')
|
|
|
|
command('set scrolloff=2')
|
|
|
|
expected_combination({'scrolloff', 8, 8, 8, 2, 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with number local (to window) option', function()
|
|
|
|
command('noa setglobal foldcolumn=8')
|
|
|
|
command('noa setlocal foldcolumn=1')
|
|
|
|
command('setglobal foldcolumn=2')
|
|
|
|
expected_combination({'foldcolumn', 8, '', 8, 2, 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa setglobal foldcolumn=8')
|
|
|
|
command('noa setlocal foldcolumn=1')
|
|
|
|
command('setlocal foldcolumn=2')
|
|
|
|
expected_combination({'foldcolumn', 1, 1, '', 2, 'local', 'setlocal'})
|
|
|
|
|
|
|
|
command('noa setglobal foldcolumn=8')
|
|
|
|
command('noa setlocal foldcolumn=1')
|
|
|
|
command('set foldcolumn=2')
|
|
|
|
expected_combination({'foldcolumn', 1, 1, 8, 2, 'global', 'set'})
|
|
|
|
|
|
|
|
command('noa set foldcolumn=8')
|
|
|
|
command('set foldcolumn=2')
|
|
|
|
expected_combination({'foldcolumn', 8, 8, 8, 2, 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with boolean global option', function()
|
|
|
|
command('noa setglobal nowrapscan')
|
|
|
|
command('noa setlocal wrapscan') -- Sets the global(!) value
|
|
|
|
command('setglobal nowrapscan')
|
|
|
|
expected_combination({'wrapscan', 1, '', 1, 0, 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa setglobal nowrapscan')
|
|
|
|
command('noa setlocal wrapscan') -- Sets the global(!) value
|
|
|
|
command('setlocal nowrapscan')
|
|
|
|
expected_combination({'wrapscan', 1, 1, '', 0, 'local', 'setlocal'})
|
|
|
|
|
|
|
|
command('noa setglobal nowrapscan')
|
|
|
|
command('noa setlocal wrapscan') -- Sets the global(!) value
|
|
|
|
command('set nowrapscan')
|
|
|
|
expected_combination({'wrapscan', 1, 1, 1, 0, 'global', 'set'})
|
|
|
|
|
|
|
|
command('noa set nowrapscan')
|
|
|
|
command('set wrapscan')
|
|
|
|
expected_combination({'wrapscan', 0, 0, 0, 1, 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with boolean global-local (to buffer) option', function()
|
|
|
|
command('noa setglobal noautoread')
|
|
|
|
command('noa setlocal autoread')
|
|
|
|
command('setglobal autoread')
|
|
|
|
expected_combination({'autoread', 0, '', 0, 1, 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa setglobal noautoread')
|
|
|
|
command('noa setlocal autoread')
|
|
|
|
command('setlocal noautoread')
|
|
|
|
expected_combination({'autoread', 1, 1, '', 0, 'local', 'setlocal'})
|
|
|
|
|
|
|
|
command('noa setglobal noautoread')
|
|
|
|
command('noa setlocal autoread')
|
|
|
|
command('set autoread')
|
|
|
|
expected_combination({'autoread', 1, 1, 0, 1, 'global', 'set'})
|
|
|
|
|
|
|
|
command('noa set noautoread')
|
|
|
|
command('set autoread')
|
|
|
|
expected_combination({'autoread', 0, 0, 0, 1, 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with boolean local (to buffer) option', function()
|
|
|
|
command('noa setglobal nocindent')
|
|
|
|
command('noa setlocal cindent')
|
|
|
|
command('setglobal cindent')
|
|
|
|
expected_combination({'cindent', 0, '', 0, 1, 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa setglobal nocindent')
|
|
|
|
command('noa setlocal cindent')
|
|
|
|
command('setlocal nocindent')
|
|
|
|
expected_combination({'cindent', 1, 1, '', 0, 'local', 'setlocal'})
|
|
|
|
|
|
|
|
command('noa setglobal nocindent')
|
|
|
|
command('noa setlocal cindent')
|
|
|
|
command('set cindent')
|
|
|
|
expected_combination({'cindent', 1, 1, 0, 1, 'global', 'set'})
|
|
|
|
|
|
|
|
command('noa set nocindent')
|
|
|
|
command('set cindent')
|
|
|
|
expected_combination({'cindent', 0, 0, 0, 1, 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with boolean local (to window) option', function()
|
|
|
|
command('noa setglobal nocursorcolumn')
|
|
|
|
command('noa setlocal cursorcolumn')
|
|
|
|
command('setglobal cursorcolumn')
|
|
|
|
expected_combination({'cursorcolumn', 0, '', 0, 1, 'global', 'setglobal'})
|
|
|
|
|
|
|
|
command('noa setglobal nocursorcolumn')
|
|
|
|
command('noa setlocal cursorcolumn')
|
|
|
|
command('setlocal nocursorcolumn')
|
|
|
|
expected_combination({'cursorcolumn', 1, 1, '', 0, 'local', 'setlocal'})
|
|
|
|
|
|
|
|
command('noa setglobal nocursorcolumn')
|
|
|
|
command('noa setlocal cursorcolumn')
|
|
|
|
command('set cursorcolumn')
|
|
|
|
expected_combination({'cursorcolumn', 1, 1, 0, 1, 'global', 'set'})
|
|
|
|
|
|
|
|
command('noa set nocursorcolumn')
|
|
|
|
command('set cursorcolumn')
|
|
|
|
expected_combination({'cursorcolumn', 0, 0, 0, 1, 'global', 'set'})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('with option value converted internally', function()
|
|
|
|
command('noa set backspace=1')
|
|
|
|
command('set backspace=2')
|
|
|
|
expected_combination(({
|
|
|
|
'backspace', 'indent,eol', 'indent,eol', 'indent,eol', '2', 'global', 'set'
|
|
|
|
}))
|
|
|
|
end)
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('with specific option', function()
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
declare_hook_function()
|
|
|
|
init_var()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('should be called iff setting readonly', function()
|
|
|
|
set_hook('readonly')
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set nu')
|
2015-12-01 07:41:03 -07:00
|
|
|
expected_empty()
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('setlocal ro')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'readonly', 0, 0, '', 1, 'local', 'setlocal'})
|
2015-12-01 07:41:03 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('setglobal ro')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'readonly', 0, '', 0, 1, 'global', 'setglobal'})
|
2015-12-01 07:41:03 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set noro')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'readonly', 1, 1, 1, 0, 'global', 'set'})
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('being set by setbufvar()', function()
|
|
|
|
it('should not trigger because option name does not match with backup', function()
|
|
|
|
set_hook('backup')
|
|
|
|
|
2017-04-08 16:17:03 -07:00
|
|
|
command('silent! call setbufvar(1, "&l:bk", 1)')
|
2015-11-28 01:06:23 -07:00
|
|
|
expected_empty()
|
|
|
|
end)
|
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
it('should trigger, use correct option name backup', function()
|
|
|
|
set_hook('backup')
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('call setbufvar(1, "&backup", 1)')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'backup', 0, 0, '', 1, 'local', 'setlocal'})
|
2015-11-28 01:06:23 -07:00
|
|
|
end)
|
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
it('should trigger if the current buffer is different from the targetted buffer', function()
|
|
|
|
set_hook('buftype')
|
|
|
|
|
|
|
|
local new_buffer = make_buffer()
|
|
|
|
local new_bufnr = buf.get_number(new_buffer)
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'buftype', '', '', '', 'nofile', 'local', 'setlocal', {bufnr = new_bufnr}})
|
2015-11-28 01:06:23 -07:00
|
|
|
end)
|
2015-12-01 07:41:03 -07:00
|
|
|
end)
|
|
|
|
|
2016-02-11 22:01:35 -07:00
|
|
|
describe('being set by setwinvar()', function()
|
|
|
|
it('should not trigger because option name does not match with backup', function()
|
|
|
|
set_hook('backup')
|
|
|
|
|
2017-04-08 16:17:03 -07:00
|
|
|
command('silent! call setwinvar(1, "&l:bk", 1)')
|
2016-02-11 22:01:35 -07:00
|
|
|
expected_empty()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('should trigger, use correct option name backup', function()
|
|
|
|
set_hook('backup')
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('call setwinvar(1, "&backup", 1)')
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'backup', 0, 0, '', 1, 'local', 'setlocal'})
|
2016-02-11 22:01:35 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('should not trigger if the current window is different from the targetted window', function()
|
|
|
|
set_hook('cursorcolumn')
|
|
|
|
|
2016-02-12 04:38:20 -07:00
|
|
|
local new_winnr = get_new_window_number()
|
2016-02-11 22:01:35 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('call setwinvar(' .. new_winnr .. ', "&cursorcolumn", 1)')
|
2016-02-11 22:01:35 -07:00
|
|
|
-- expected_combination({'cursorcolumn', 0, 1, 'local', {winnr = new_winnr}})
|
|
|
|
expected_empty()
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
describe('being set by neovim api', function()
|
|
|
|
it('should trigger if a boolean option be set globally', function()
|
|
|
|
set_hook('autochdir')
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
nvim.set_option('autochdir', true)
|
|
|
|
eq(true, nvim.get_option('autochdir'))
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'autochdir', 0, '', 0, 1, 'global', 'setglobal'})
|
2015-11-28 01:06:23 -07:00
|
|
|
end)
|
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
it('should trigger if a number option be set globally', function()
|
|
|
|
set_hook('cmdheight')
|
|
|
|
|
|
|
|
nvim.set_option('cmdheight', 5)
|
|
|
|
eq(5, nvim.get_option('cmdheight'))
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'cmdheight', 1, '', 1, 5, 'global', 'setglobal'})
|
2015-11-28 01:06:23 -07:00
|
|
|
end)
|
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
it('should trigger if a string option be set globally', function()
|
|
|
|
set_hook('ambiwidth')
|
2015-11-28 01:06:23 -07:00
|
|
|
|
2015-12-01 07:41:03 -07:00
|
|
|
nvim.set_option('ambiwidth', 'double')
|
|
|
|
eq('double', nvim.get_option('ambiwidth'))
|
2021-11-22 00:50:14 -07:00
|
|
|
expected_combination({'ambiwidth', 'single', '', 'single', 'double', 'global', 'setglobal'})
|
2015-11-28 01:06:23 -07:00
|
|
|
end)
|
|
|
|
end)
|
2015-11-27 08:41:50 -07:00
|
|
|
end)
|
|
|
|
end)
|