api: vim_set_var() should return the old value #2899

Closes #2816
This commit is contained in:
Justin M. Keyes
2015-06-25 00:13:33 -04:00
parent 406e9876b6
commit f78bf64771
2 changed files with 8 additions and 0 deletions

View File

@@ -146,6 +146,7 @@ Object dict_set_value(dict_T *dict, String key, Object value, Error *err)
dict_add(dict, di);
} else {
// Return the old value
rv = vim_to_object(&di->di_tv);
clear_tv(&di->di_tv);
}

View File

@@ -62,6 +62,13 @@ describe('vim_* functions', function()
eq({1, 2, {['3'] = 1}}, nvim('eval', 'g:lua'))
end)
it('set_var returns the old value', function()
local val1 = {1, 2, {['3'] = 1}}
local val2 = {4, 7}
eq(nil, nvim('set_var', 'lua', val1))
eq(val1, nvim('set_var', 'lua', val2))
end)
it('truncates values with NULs in them', function()
nvim('set_var', 'xxx', 'ab\0cd')
eq('ab', nvim('get_var', 'xxx'))