diff options
| author | Lewis Russell <lewis6991@gmail.com> | 2025-07-25 15:12:23 +0100 |
|---|---|---|
| committer | Lewis Russell <me@lewisr.dev> | 2025-07-28 09:34:06 +0100 |
| commit | cf9b36f3d97b6f9c66ffff008bc1b5a5dd14ca98 (patch) | |
| tree | 40a42c440a32af74a08bef9223c35643c157b833 /test/functional/lua/vim_spec.lua | |
| parent | 7a051a4c389452b4955c22e3c29071433e01905a (diff) | |
| download | rneovim-cf9b36f3d97b6f9c66ffff008bc1b5a5dd14ca98.tar.gz rneovim-cf9b36f3d97b6f9c66ffff008bc1b5a5dd14ca98.tar.bz2 rneovim-cf9b36f3d97b6f9c66ffff008bc1b5a5dd14ca98.zip | |
feat(lua): add vim.list.unique()
Problem:
No way to deduplicate values in a list in-place
Solution:
Add `vim.list.unique()`
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
| -rw-r--r-- | test/functional/lua/vim_spec.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 9372f5c7b7..14e08cffba 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1260,6 +1260,28 @@ describe('lua stdlib', function() eq({ 2 }, exec_lua [[ return vim.list_extend({}, {2;a=1}, -1, 2) ]]) end) + it('vim.list.unique', function() + eq({ 1, 2, 3, 4, 5 }, vim.list.unique({ 1, 2, 2, 3, 4, 4, 5 })) + eq({ 1, 2, 3, 4, 5 }, vim.list.unique({ 1, 2, 3, 4, 4, 5, 1, 2, 3, 2, 1, 2, 3, 4, 5 })) + eq({ 1, 2, 3, 4, 5, field = 1 }, vim.list.unique({ 1, 2, 2, 3, 4, 4, 5, field = 1 })) + + -- Not properly defined, but test anyway + -- luajit evaluates #t as 7, whereas Lua 5.1 evaluates it as 12 + local r = vim.list.unique({ 1, 2, 2, 3, 4, 4, 5, nil, 6, 6, 7, 7 }) + if jit then + eq({ 1, 2, 3, 4, 5, nil, nil, nil, 6, 6, 7, 7 }, r) + else + eq({ 1, 2, 3, 4, 5, nil, 6, 7 }, r) + end + + eq( + { { 1 }, { 2 }, { 3 } }, + vim.list.unique({ { 1 }, { 1 }, { 2 }, { 2 }, { 3 }, { 3 } }, function(x) + return x[1] + end) + ) + end) + it('vim.tbl_add_reverse_lookup', function() eq( true, |