eval: Add id() function and make printf("%p") return something useful (#6095)

This commit is contained in:
Nikolai Aleksandrovich Pavlov
2017-02-11 21:47:02 +03:00
committed by Justin M. Keyes
parent b1cf50c684
commit abdbfd26bc
7 changed files with 113 additions and 11 deletions

View File

@@ -1,7 +1,10 @@
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
local funcs = helpers.funcs
local meths = helpers.meths
local exc_exec = helpers.exc_exec
describe('printf()', function()
@@ -57,4 +60,33 @@ describe('printf()', function()
it('errors out when %b modifier is used for a float', function()
eq('Vim(call):E805: Using a Float as a Number', exc_exec('call printf("%b", 3.1415926535)'))
end)
it('works with %p correctly', function()
local null_ret = nil
local seen_rets = {}
-- Collect all args in an array to avoid possible allocation of the same
-- address after freeing unreferenced values.
meths.set_var('__args', {})
local function check_printf(expr, is_null)
eq(0, exc_exec('call add(__args, ' .. expr .. ')'))
eq(0, exc_exec('let __result = printf("%p", __args[-1])'))
local id_ret = eval('id(__args[-1])')
eq(id_ret, meths.get_var('__result'))
if is_null then
if null_ret then
eq(null_ret, id_ret)
else
null_ret = id_ret
end
else
eq(nil, seen_rets[id_ret])
seen_rets[id_ret] = expr
end
meths.del_var('__result')
end
check_printf('v:_null_list', true)
check_printf('v:_null_dict', true)
check_printf('[]')
check_printf('{}')
check_printf('function("tr", ["a"])')
end)
end)