From 3fa4ca81880bc5113c32a89de965ce593e9b001f Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 12 Jul 2016 19:04:12 +0300 Subject: [PATCH] executor/converter: Fix conversion of self-containing containers --- src/nvim/viml/executor/converter.c | 2 +- test/functional/lua_spec.lua | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/nvim/viml/executor/converter.c b/src/nvim/viml/executor/converter.c index c127b87738..319e07bdbc 100644 --- a/src/nvim/viml/executor/converter.c +++ b/src/nvim/viml/executor/converter.c @@ -446,7 +446,7 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv) ? (void *)mpval.data.d.dict == (void *)(val) \ : (void *)mpval.data.l.list == (void *)(val)) { \ lua_pushvalue(lstate, \ - 1 - ((int)((kv_size(*mpstack) - backref + 1) * 2))); \ + -((int)((kv_size(*mpstack) - backref + 1) * 2))); \ break; \ } \ } \ diff --git a/test/functional/lua_spec.lua b/test/functional/lua_spec.lua index 4f00189519..5c6dee90a3 100644 --- a/test/functional/lua_spec.lua +++ b/test/functional/lua_spec.lua @@ -224,12 +224,23 @@ describe('luaeval() function', function() eq(10, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) end) -- TODO: check what happens when it errors out on second list item ---[[FIXME - [ - [ it('correctly converts self-containing containers', function() - [ meths.set_var('l', {}) - [ eval('add(l, l)') - [ eq(true, eval('luaeval("_A == _A[1]", l)')) - [ end) - ]] + -- TODO: check what happens if API function receives wrong number of + -- arguments. + -- TODO: check what happens if API function receives wrong argument types. + + it('correctly converts self-containing containers', function() + meths.set_var('l', {}) + eval('add(l, l)') + eq(true, eval('luaeval("_A == _A[1]", l)')) + eq(true, eval('luaeval("_A[1] == _A[1][1]", [l])')) + eq(true, eval('luaeval("_A.d == _A.d[1]", {"d": l})')) + eq(true, eval('luaeval("_A ~= _A[1]", [l])')) + + meths.set_var('d', {foo=42}) + eval('extend(d, {"d": d})') + eq(true, eval('luaeval("_A == _A.d", d)')) + eq(true, eval('luaeval("_A[1] == _A[1].d", [d])')) + eq(true, eval('luaeval("_A.d == _A.d.d", {"d": d})')) + eq(true, eval('luaeval("_A ~= _A.d", {"d": d})')) + end) end)