mirror of
https://github.com/HiPhish/rainbow-delimiters.nvim.git
synced 2024-09-16 14:24:05 +02:00
Avoid reinstalling parser in tests
Uses a custom function in the faker user config. This function can be called via RPC in the process under test.
This commit is contained in:
parent
bbe08e16ae
commit
80ee86a2a8
3 changed files with 18 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
# Tag file created by Vim
|
||||
doc/tags
|
||||
test/xdg/config/nvim/
|
||||
|
||||
# Fake user directory structures
|
||||
test/xdg/local/share/nvim/
|
||||
test/xdg/local/state/nvim/
|
||||
!test/xdg/local/share/nvim/site/pack/testing/start/rainbow-delimiters
|
||||
|
|
|
@ -71,7 +71,7 @@ describe('User settings are respected', function()
|
|||
end)
|
||||
|
||||
it('Uses the strategy returned by the thunk', function()
|
||||
request('nvim_command', 'TSInstallSync! lua')
|
||||
request(exec_lua, 'TSEnsure(...)', {'lua'})
|
||||
request(buf_set_lines, 0, 0, -1, true, {'print "Hello world"', '-- vim:ft=lua'})
|
||||
request('nvim_command', 'filetype detect')
|
||||
local attachments = request(exec_lua, 'return the_strategy.attachments[1]', {})
|
||||
|
@ -79,7 +79,7 @@ describe('User settings are respected', function()
|
|||
end)
|
||||
|
||||
it('Does nothing if the thunk returns nil', function()
|
||||
request('nvim_command', 'TSInstallSync! vim')
|
||||
request(exec_lua, 'TSEnsure(...)', {'vim'})
|
||||
request(buf_set_lines, 0, 0, -1, true, {'echo "Hello world"', '" vim:ft=vim'})
|
||||
request('nvim_command', 'filetype detect')
|
||||
local attachments = request(exec_lua, 'return the_strategy.attachments[1]', {})
|
||||
|
|
14
test/xdg/config/nvim/plugin/ts-ensure.lua
Normal file
14
test/xdg/config/nvim/plugin/ts-ensure.lua
Normal file
|
@ -0,0 +1,14 @@
|
|||
local get_runtime_file = vim.api.nvim_get_runtime_file
|
||||
local parser_pattern = 'parser/%s.*'
|
||||
|
||||
---Wrapper around the `:TSinstall` command which will only install a parser if
|
||||
---it is not installed yet
|
||||
---@param lang string Language to install
|
||||
function TSEnsure(lang, ...)
|
||||
for _, l in ipairs({lang, ...}) do
|
||||
local parsers = get_runtime_file(parser_pattern:format(l), true)
|
||||
if #parsers == 0 then
|
||||
vim.cmd {cmd = 'TSInstallSync', args = {l}}
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue