diff options
author | Nikolai Aleksandrovich Pavlov <kp-pav@yandex.ru> | 2017-02-11 21:47:02 +0300 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-02-11 19:47:02 +0100 |
commit | abdbfd26bc7f91cb6fda8feb758ffd020fb58754 (patch) | |
tree | 866d2cc4db059f7392d30715483ca8c0eb52be6b /test/functional/eval/printf_spec.lua | |
parent | b1cf50c6846790fc1846a36ced3ba19134afef64 (diff) | |
download | rneovim-abdbfd26bc7f91cb6fda8feb758ffd020fb58754.tar.gz rneovim-abdbfd26bc7f91cb6fda8feb758ffd020fb58754.tar.bz2 rneovim-abdbfd26bc7f91cb6fda8feb758ffd020fb58754.zip |
eval: Add id() function and make printf("%p") return something useful (#6095)
Diffstat (limited to 'test/functional/eval/printf_spec.lua')
-rw-r--r-- | test/functional/eval/printf_spec.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/functional/eval/printf_spec.lua b/test/functional/eval/printf_spec.lua index c84290ceef..27e24c4118 100644 --- a/test/functional/eval/printf_spec.lua +++ b/test/functional/eval/printf_spec.lua @@ -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) |