diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2023-04-19 08:23:42 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-19 08:23:42 -0600 |
commit | 0ad5237162a05f0f04c74eab1961166f4f74254b (patch) | |
tree | ffc7297809337b2178b938d955361d07634bd4c6 /test/functional/lua/vim_spec.lua | |
parent | 0d7bed34a29ef1add5d225a6809882fa6dce49d9 (diff) | |
parent | 94894068794dbb99804cda689b6c37e70376c8ca (diff) | |
download | rneovim-0ad5237162a05f0f04c74eab1961166f4f74254b.tar.gz rneovim-0ad5237162a05f0f04c74eab1961166f4f74254b.tar.bz2 rneovim-0ad5237162a05f0f04c74eab1961166f4f74254b.zip |
Merge pull request #23198 from gpanders/iter-fix
fix(iter): allow table values in iterator pipelines
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r-- | test/functional/lua/vim_spec.lua | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index e5caf6f6f7..e37d477376 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -3374,13 +3374,45 @@ describe('lua stdlib', function() end) it('handles map-like tables', function() - local t = { a = 1, b = 2, c = 3 } - local it = vim.iter(t):map(function(k, v) + local it = vim.iter({ a = 1, b = 2, c = 3 }):map(function(k, v) if v % 2 ~= 0 then return k:upper(), v * 2 end end) - eq({ A = 2, C = 6 }, it:totable()) + + local t = it:fold({}, function(t, k, v) + t[k] = v + return t + end) + eq({ A = 2, C = 6 }, t) + end) + + it('handles table values mid-pipeline', function() + local map = { + item = { + file = 'test', + }, + item_2 = { + file = 'test', + }, + item_3 = { + file = 'test', + }, + } + + local output = vim.iter(map):map(function(key, value) + return { [key] = value.file } + end):totable() + + table.sort(output, function(a, b) + return next(a) < next(b) + end) + + eq({ + { item = 'test' }, + { item_2 = 'test' }, + { item_3 = 'test' }, + }, output) end) end) end) |