2017-03-26 04:20:44 -07:00
|
|
|
-- Tests for :setlocal and :setglobal
|
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local clear, feed_command, eval, eq, api = n.clear, n.feed_command, n.eval, t.eq, n.api
|
2017-03-26 04:20:44 -07:00
|
|
|
|
2017-03-27 00:51:14 -07:00
|
|
|
local function should_fail(opt, value, errmsg)
|
2017-06-28 11:21:44 -07:00
|
|
|
feed_command('setglobal ' .. opt .. '=' .. value)
|
2017-03-27 10:50:04 -07:00
|
|
|
eq(errmsg, eval('v:errmsg'):match('E%d*'))
|
2017-06-28 11:21:44 -07:00
|
|
|
feed_command('let v:errmsg = ""')
|
|
|
|
feed_command('setlocal ' .. opt .. '=' .. value)
|
2017-03-27 10:50:04 -07:00
|
|
|
eq(errmsg, eval('v:errmsg'):match('E%d*'))
|
2017-06-28 11:21:44 -07:00
|
|
|
feed_command('let v:errmsg = ""')
|
2024-01-12 10:59:57 -07:00
|
|
|
local status, err = pcall(api.nvim_set_option_value, opt, value, {})
|
2024-03-11 07:23:14 -07:00
|
|
|
eq(false, status)
|
2017-04-01 03:26:58 -07:00
|
|
|
eq(errmsg, err:match('E%d*'))
|
|
|
|
eq('', eval('v:errmsg'))
|
2017-03-27 00:51:14 -07:00
|
|
|
end
|
|
|
|
|
2017-03-31 09:30:06 -07:00
|
|
|
local function should_succeed(opt, value)
|
2017-06-28 11:21:44 -07:00
|
|
|
feed_command('setglobal ' .. opt .. '=' .. value)
|
|
|
|
feed_command('setlocal ' .. opt .. '=' .. value)
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value(opt, value, {})
|
|
|
|
eq(value, api.nvim_get_option_value(opt, {}))
|
2017-03-31 09:30:06 -07:00
|
|
|
eq('', eval('v:errmsg'))
|
|
|
|
end
|
|
|
|
|
2017-03-26 04:20:44 -07:00
|
|
|
describe(':setlocal', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
it('setlocal sets only local value', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, api.nvim_get_option_value('iminsert', { scope = 'global' }))
|
2017-06-28 11:21:44 -07:00
|
|
|
feed_command('setlocal iminsert=1')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, api.nvim_get_option_value('iminsert', { scope = 'global' }))
|
|
|
|
eq(-1, api.nvim_get_option_value('imsearch', { scope = 'global' }))
|
2017-06-28 11:21:44 -07:00
|
|
|
feed_command('setlocal imsearch=1')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(-1, api.nvim_get_option_value('imsearch', { scope = 'global' }))
|
2017-03-26 04:20:44 -07:00
|
|
|
end)
|
|
|
|
end)
|
2017-03-27 00:51:14 -07:00
|
|
|
|
|
|
|
describe(':set validation', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
it('setlocal and setglobal validate values', function()
|
|
|
|
should_fail('shiftwidth', -10, 'E487')
|
2017-03-31 09:30:06 -07:00
|
|
|
should_succeed('shiftwidth', 0)
|
2017-03-27 00:51:14 -07:00
|
|
|
should_fail('tabstop', -10, 'E487')
|
2017-03-28 07:17:53 -07:00
|
|
|
should_fail('winheight', -10, 'E487')
|
2017-03-31 09:30:06 -07:00
|
|
|
should_fail('winheight', 0, 'E487')
|
|
|
|
should_fail('winminheight', -1, 'E487')
|
|
|
|
should_succeed('winminheight', 0)
|
|
|
|
should_fail('winwidth', 0, 'E487')
|
|
|
|
should_fail('helpheight', -1, 'E487')
|
|
|
|
should_fail('iminsert', 3, 'E474')
|
|
|
|
should_fail('imsearch', 3, 'E474')
|
|
|
|
should_fail('titlelen', -1, 'E487')
|
2022-06-13 02:40:51 -07:00
|
|
|
should_fail('cmdheight', -1, 'E487')
|
2017-03-31 09:30:06 -07:00
|
|
|
should_fail('updatecount', -1, 'E487')
|
|
|
|
should_fail('textwidth', -1, 'E487')
|
|
|
|
should_fail('tabstop', 0, 'E487')
|
|
|
|
should_fail('timeoutlen', -1, 'E487')
|
2017-03-28 07:17:53 -07:00
|
|
|
should_fail('history', 1000000, 'E474')
|
2017-03-31 09:30:06 -07:00
|
|
|
should_fail('regexpengine', -1, 'E474')
|
2017-03-28 07:17:53 -07:00
|
|
|
should_fail('regexpengine', 3, 'E474')
|
2017-03-31 09:30:06 -07:00
|
|
|
should_succeed('regexpengine', 2)
|
|
|
|
should_fail('report', -1, 'E487')
|
|
|
|
should_succeed('report', 0)
|
|
|
|
should_fail('sidescroll', -1, 'E487')
|
|
|
|
should_fail('cmdwinheight', 0, 'E487')
|
|
|
|
should_fail('updatetime', -1, 'E487')
|
2017-03-28 07:17:53 -07:00
|
|
|
|
|
|
|
should_fail('foldlevel', -5, 'E487')
|
2020-01-14 11:50:30 -07:00
|
|
|
should_fail('foldcolumn', '13', 'E474')
|
2017-03-28 07:17:53 -07:00
|
|
|
should_fail('conceallevel', 4, 'E474')
|
2019-07-01 19:54:50 -07:00
|
|
|
should_fail('numberwidth', 21, 'E474')
|
2017-03-31 09:30:06 -07:00
|
|
|
should_fail('numberwidth', 0, 'E487')
|
|
|
|
|
2017-04-01 03:26:58 -07:00
|
|
|
-- If smaller than 1 this one is set to 'lines'-1
|
2017-06-28 11:21:44 -07:00
|
|
|
feed_command('setglobal window=-10')
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('window', -10, {})
|
|
|
|
eq(23, api.nvim_get_option_value('window', {}))
|
2017-04-01 03:26:58 -07:00
|
|
|
eq('', eval('v:errmsg'))
|
2020-03-17 12:05:34 -07:00
|
|
|
|
|
|
|
-- 'scrolloff' and 'sidescrolloff' can have a -1 value when
|
|
|
|
-- set for the current window, but not globally
|
|
|
|
feed_command('setglobal scrolloff=-1')
|
|
|
|
eq('E487', eval('v:errmsg'):match('E%d*'))
|
|
|
|
|
|
|
|
feed_command('setglobal sidescrolloff=-1')
|
|
|
|
eq('E487', eval('v:errmsg'):match('E%d*'))
|
|
|
|
|
|
|
|
feed_command('let v:errmsg=""')
|
|
|
|
|
|
|
|
feed_command('setlocal scrolloff=-1')
|
|
|
|
eq('', eval('v:errmsg'))
|
|
|
|
|
|
|
|
feed_command('setlocal sidescrolloff=-1')
|
|
|
|
eq('', eval('v:errmsg'))
|
2017-03-28 07:17:53 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('set wmh/wh wmw/wiw checks', function()
|
2017-06-28 11:21:44 -07:00
|
|
|
feed_command('set winheight=2')
|
|
|
|
feed_command('set winminheight=3')
|
2017-03-28 07:17:53 -07:00
|
|
|
eq('E591', eval('v:errmsg'):match('E%d*'))
|
|
|
|
|
2017-06-28 11:21:44 -07:00
|
|
|
feed_command('set winwidth=2')
|
|
|
|
feed_command('set winminwidth=3')
|
2017-03-28 07:17:53 -07:00
|
|
|
eq('E592', eval('v:errmsg'):match('E%d*'))
|
2017-03-27 00:51:14 -07:00
|
|
|
end)
|
2018-02-19 08:46:44 -07:00
|
|
|
|
|
|
|
it('set maxcombine resets to 6', function()
|
|
|
|
local function setto(value)
|
|
|
|
feed_command('setglobal maxcombine=' .. value)
|
|
|
|
feed_command('setlocal maxcombine=' .. value)
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('maxcombine', value, {})
|
|
|
|
eq(6, api.nvim_get_option_value('maxcombine', {}))
|
2018-02-19 08:46:44 -07:00
|
|
|
eq('', eval('v:errmsg'))
|
|
|
|
end
|
|
|
|
setto(0)
|
|
|
|
setto(1)
|
|
|
|
setto(6)
|
|
|
|
setto(7)
|
|
|
|
end)
|
2017-03-27 00:51:14 -07:00
|
|
|
end)
|