diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-07-29 11:20:15 +0100 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-08-02 19:04:37 +0100 |
commit | 7d24c4d6b0413cd5af8d0579f0a9a694db7f775e (patch) | |
tree | d9954c2001fe512c60a76561e7a19566b9de638b /test/functional/lua/fs_spec.lua | |
parent | f32557ca679cbb1d7de52ab54dc35585af9ab9d0 (diff) | |
download | rneovim-7d24c4d6b0413cd5af8d0579f0a9a694db7f775e.tar.gz rneovim-7d24c4d6b0413cd5af8d0579f0a9a694db7f775e.tar.bz2 rneovim-7d24c4d6b0413cd5af8d0579f0a9a694db7f775e.zip |
test: allow exec_lua to handle functions
Problem:
Tests have lots of exec_lua calls which input blocks of code
provided as unformatted strings.
Solution:
Teach exec_lua how to handle functions.
Diffstat (limited to 'test/functional/lua/fs_spec.lua')
-rw-r--r-- | test/functional/lua/fs_spec.lua | 64 |
1 files changed, 23 insertions, 41 deletions
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index aba02ab01b..4848787ed2 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -141,19 +141,14 @@ describe('vim.fs', function() it('works', function() eq( true, - exec_lua( - [[ - local dir, nvim = ... - for name, type in vim.fs.dir(dir) do - if name == nvim and type == 'file' then - return true + exec_lua(function(dir, nvim) + for name, type in vim.fs.dir(dir) do + if name == nvim and type == 'file' then + return true + end end - end - return false - ]], - nvim_dir, - nvim_prog_basename - ) + return false + end, nvim_dir, nvim_prog_basename) ) end) @@ -172,27 +167,21 @@ describe('vim.fs', function() io.open('testd/a/b/c/c4', 'w'):close() local function run(dir, depth, skip) - local r = exec_lua( - [[ - local dir, depth, skip = ... + local r = exec_lua(function(dir0, depth0, skip0) local r = {} local skip_f - if skip then - skip_f = function(n) - if vim.tbl_contains(skip or {}, n) then + if skip0 then + skip_f = function(n0) + if vim.tbl_contains(skip0 or {}, n0) then return false end end end - for name, type_ in vim.fs.dir(dir, { depth = depth, skip = skip_f }) do + for name, type_ in vim.fs.dir(dir0, { depth = depth0, skip = skip_f }) do r[name] = type_ end return r - ]], - dir, - depth, - skip - ) + end, dir, depth, skip) return r end @@ -263,13 +252,9 @@ describe('vim.fs', function() opts = { path = test_source_path .. '/contrib', limit = math.huge } eq( - exec_lua( - [[ - local dir = ... - return vim.tbl_map(vim.fs.basename, vim.fn.glob(dir..'/contrib/*', false, true)) - ]], - test_source_path - ), + exec_lua(function(dir) + return vim.tbl_map(vim.fs.basename, vim.fn.glob(dir .. '/contrib/*', false, true)) + end, test_source_path), vim.tbl_map( vim.fs.basename, vim.fs.find(function(_, d) @@ -299,11 +284,11 @@ describe('vim.fs', function() it('works with a function', function() ---@type string - local result = exec_lua([[ - return vim.fs.root(0, function(name, path) + local result = exec_lua(function() + return vim.fs.root(0, function(name, _) return name:match('%.txt$') end) - ]]) + end) eq(vim.fs.joinpath(test_source_path, 'test/functional/fixtures'), result) end) @@ -352,13 +337,10 @@ describe('vim.fs', function() local xdg_config_home = test_build_dir .. '/.config' eq( xdg_config_home .. '/nvim', - exec_lua( - [[ - vim.env.XDG_CONFIG_HOME = ... - return vim.fs.normalize('$XDG_CONFIG_HOME/nvim') - ]], - xdg_config_home - ) + exec_lua(function(...) + vim.env.XDG_CONFIG_HOME = ... + return vim.fs.normalize('$XDG_CONFIG_HOME/nvim') + end, xdg_config_home) ) end) |