mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api: Replace set_var(name, NIL) with del_var(name)
This commit is contained in:
@@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')
|
||||
local clear, nvim, buffer = helpers.clear, helpers.nvim, helpers.buffer
|
||||
local curbuf, curwin, eq = helpers.curbuf, helpers.curwin, helpers.eq
|
||||
local curbufmeths, ok = helpers.curbufmeths, helpers.ok
|
||||
local funcs = helpers.funcs
|
||||
|
||||
describe('buffer_* functions', function()
|
||||
before_each(clear)
|
||||
@@ -234,11 +235,14 @@ describe('buffer_* functions', function()
|
||||
|
||||
end)
|
||||
|
||||
describe('{get,set}_var', function()
|
||||
describe('{get,set,del}_var', function()
|
||||
it('works', function()
|
||||
curbuf('set_var', 'lua', {1, 2, {['3'] = 1}})
|
||||
eq({1, 2, {['3'] = 1}}, curbuf('get_var', 'lua'))
|
||||
eq({1, 2, {['3'] = 1}}, nvim('eval', 'b:lua'))
|
||||
eq(1, funcs.exists('b:lua'))
|
||||
curbufmeths.del_var('lua')
|
||||
eq(0, funcs.exists('b:lua'))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ local helpers = require('test.functional.helpers')
|
||||
local clear, nvim, tabpage, curtab, eq, ok =
|
||||
helpers.clear, helpers.nvim, helpers.tabpage, helpers.curtab, helpers.eq,
|
||||
helpers.ok
|
||||
local wait = helpers.wait
|
||||
local curtabmeths = helpers.curtabmeths
|
||||
local funcs = helpers.funcs
|
||||
|
||||
describe('tabpage_* functions', function()
|
||||
before_each(clear)
|
||||
@@ -21,11 +24,14 @@ describe('tabpage_* functions', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('{get,set}_var', function()
|
||||
describe('{get,set,del}_var', function()
|
||||
it('works', function()
|
||||
curtab('set_var', 'lua', {1, 2, {['3'] = 1}})
|
||||
eq({1, 2, {['3'] = 1}}, curtab('get_var', 'lua'))
|
||||
eq({1, 2, {['3'] = 1}}, nvim('eval', 't:lua'))
|
||||
eq(1, funcs.exists('t:lua'))
|
||||
curtabmeths.del_var('lua')
|
||||
eq(0, funcs.exists('t:lua'))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ local Screen = require('test.functional.ui.screen')
|
||||
local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq
|
||||
local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed
|
||||
local os_name = helpers.os_name
|
||||
local meths = helpers.meths
|
||||
local funcs = helpers.funcs
|
||||
|
||||
describe('vim_* functions', function()
|
||||
before_each(clear)
|
||||
@@ -70,11 +72,14 @@ describe('vim_* functions', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('{get,set}_var', function()
|
||||
describe('{get,set,del}_var', function()
|
||||
it('works', function()
|
||||
nvim('set_var', 'lua', {1, 2, {['3'] = 1}})
|
||||
eq({1, 2, {['3'] = 1}}, nvim('get_var', 'lua'))
|
||||
eq({1, 2, {['3'] = 1}}, nvim('eval', 'g:lua'))
|
||||
eq(1, funcs.exists('g:lua'))
|
||||
meths.del_var('lua')
|
||||
eq(0, funcs.exists('g:lua'))
|
||||
end)
|
||||
|
||||
it('set_var returns the old value', function()
|
||||
@@ -84,6 +89,14 @@ describe('vim_* functions', function()
|
||||
eq(val1, nvim('set_var', 'lua', val2))
|
||||
end)
|
||||
|
||||
it('del_var returns the old value', function()
|
||||
local val1 = {1, 2, {['3'] = 1}}
|
||||
local val2 = {4, 7}
|
||||
eq(nil, meths.set_var('lua', val1))
|
||||
eq(val1, meths.set_var('lua', val2))
|
||||
eq(val2, meths.del_var('lua'))
|
||||
end)
|
||||
|
||||
it('truncates values with NULs in them', function()
|
||||
nvim('set_var', 'xxx', 'ab\0cd')
|
||||
eq('ab', nvim('get_var', 'xxx'))
|
||||
|
||||
@@ -5,6 +5,8 @@ local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq,
|
||||
helpers.curbuf_contents, helpers.window, helpers.curwin, helpers.eq,
|
||||
helpers.neq, helpers.ok, helpers.feed, helpers.insert, helpers.eval
|
||||
local wait = helpers.wait
|
||||
local curwinmeths = helpers.curwinmeths
|
||||
local funcs = helpers.funcs
|
||||
|
||||
-- check if str is visible at the beginning of some line
|
||||
local function is_visible(str)
|
||||
@@ -126,11 +128,14 @@ describe('window_* functions', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('{get,set}_var', function()
|
||||
describe('{get,set,del}_var', function()
|
||||
it('works', function()
|
||||
curwin('set_var', 'lua', {1, 2, {['3'] = 1}})
|
||||
eq({1, 2, {['3'] = 1}}, curwin('get_var', 'lua'))
|
||||
eq({1, 2, {['3'] = 1}}, nvim('eval', 'w:lua'))
|
||||
eq(1, funcs.exists('w:lua'))
|
||||
curwinmeths.del_var('lua')
|
||||
eq(0, funcs.exists('w:lua'))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user