mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(api): add nvim_get_option_value
This commit is contained in:
@@ -629,6 +629,13 @@ describe('api/buf', function()
|
||||
-- Doesn't change the global value
|
||||
eq([[^\s*#\s*define]], nvim('get_option', 'define'))
|
||||
end)
|
||||
|
||||
it('returns values for unset local options', function()
|
||||
-- 'undolevels' is only set to its "unset" value when a new buffer is
|
||||
-- created
|
||||
command('enew')
|
||||
eq(-123456, curbuf('get_option', 'undolevels'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('nvim_buf_get_name, nvim_buf_set_name', function()
|
||||
|
||||
@@ -949,6 +949,33 @@ describe('API', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('nvim_get_option_value, nvim_set_option_value', function()
|
||||
it('works', function()
|
||||
ok(nvim('get_option_value', 'equalalways', {}))
|
||||
nvim('set_option_value', 'equalalways', false, {})
|
||||
ok(not nvim('get_option_value', 'equalalways', {}))
|
||||
end)
|
||||
|
||||
it('can get local values when global value is set', function()
|
||||
eq(0, nvim('get_option_value', 'scrolloff', {}))
|
||||
eq(-1, nvim('get_option_value', 'scrolloff', {scope = 'local'}))
|
||||
end)
|
||||
|
||||
it('can set global and local values', function()
|
||||
nvim('set_option_value', 'makeprg', 'hello', {})
|
||||
eq('hello', nvim('get_option_value', 'makeprg', {}))
|
||||
eq('', nvim('get_option_value', 'makeprg', {scope = 'local'}))
|
||||
nvim('set_option_value', 'makeprg', 'world', {scope = 'local'})
|
||||
eq('world', nvim('get_option_value', 'makeprg', {scope = 'local'}))
|
||||
nvim('set_option_value', 'makeprg', 'goodbye', {scope = 'global'})
|
||||
eq('goodbye', nvim('get_option_value', 'makeprg', {scope = 'global'}))
|
||||
nvim('set_option_value', 'makeprg', 'hello', {})
|
||||
eq('hello', nvim('get_option_value', 'makeprg', {scope = 'global'}))
|
||||
eq('hello', nvim('get_option_value', 'makeprg', {}))
|
||||
eq('', nvim('get_option_value', 'makeprg', {scope = 'local'}))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('nvim_{get,set}_current_buf, nvim_list_bufs', function()
|
||||
it('works', function()
|
||||
eq(1, #nvim('list_bufs'))
|
||||
|
||||
@@ -222,9 +222,9 @@ describe('API/win', function()
|
||||
eq('', nvim('get_option', 'statusline'))
|
||||
command("set modified")
|
||||
command("enew") -- global-local: not preserved in new buffer
|
||||
eq("Failed to get value for option 'statusline'",
|
||||
pcall_err(curwin, 'get_option', 'statusline'))
|
||||
eq('', eval('&l:statusline')) -- confirm local value was not copied
|
||||
-- confirm local value was not copied
|
||||
eq('', curwin('get_option', 'statusline'))
|
||||
eq('', eval('&l:statusline'))
|
||||
end)
|
||||
|
||||
it('after switching windows #15390', function()
|
||||
@@ -238,6 +238,10 @@ describe('API/win', function()
|
||||
eq('window-status', window('get_option', win1, 'statusline'))
|
||||
assert_alive()
|
||||
end)
|
||||
|
||||
it('returns values for unset local options', function()
|
||||
eq(-1, curwin('get_option', 'scrolloff'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('get_position', function()
|
||||
|
||||
@@ -1240,7 +1240,7 @@ describe('lua stdlib', function()
|
||||
|
||||
vim.opt.makeprg = "global-local"
|
||||
table.insert(result, vim.api.nvim_get_option('makeprg'))
|
||||
table.insert(result, (pcall(vim.api.nvim_buf_get_option, 0, 'makeprg')))
|
||||
table.insert(result, vim.api.nvim_buf_get_option(0, 'makeprg'))
|
||||
|
||||
vim.opt_local.mp = "only-local"
|
||||
table.insert(result, vim.api.nvim_get_option('makeprg'))
|
||||
@@ -1258,7 +1258,7 @@ describe('lua stdlib', function()
|
||||
|
||||
-- Set -> global & local
|
||||
eq("global-local", result[1])
|
||||
eq(false, result[2])
|
||||
eq("", result[2])
|
||||
|
||||
-- Setlocal -> only local
|
||||
eq("global-local", result[3])
|
||||
@@ -1268,9 +1268,9 @@ describe('lua stdlib', function()
|
||||
eq("only-global", result[5])
|
||||
eq("only-local", result[6])
|
||||
|
||||
-- set -> doesn't override previously set value
|
||||
-- Set -> sets global value and resets local value
|
||||
eq("global-local", result[7])
|
||||
eq("only-local", result[8])
|
||||
eq("", result[8])
|
||||
end)
|
||||
|
||||
it('should allow you to retrieve window opts even if they have not been set', function()
|
||||
|
||||
Reference in New Issue
Block a user