Translate selective activation test to Busted

This commit is contained in:
HiPhish 2024-01-15 20:48:03 +01:00
parent 7c171bbeff
commit bbe08e16ae
3 changed files with 49 additions and 17 deletions

View file

@ -28,7 +28,7 @@
check: unit-test e2e-test
unit-test:
eval $$(luarocks path --lua-version 5.1 --bin) && busted --run unit
@eval $$(luarocks path --lua-version 5.1 --bin) && busted --run unit
e2e-test:
eval $$(luarocks path --lua-version 5.1 --bin) && busted --run e2e
@eval $$(luarocks path --lua-version 5.1 --bin) && busted --run e2e

View file

@ -0,0 +1,47 @@
local rpcrequest = vim.fn.rpcrequest
local jobopts = {
rpc = true,
width = 80,
height = 24,
}
local exec_lua = 'nvim_exec_lua'
local buf_set_lines = 'nvim_buf_set_lines'
describe('We can disable rainbow delimiters for certain languages', function()
local nvim
local function request(method, ...)
return rpcrequest(nvim, method, ...)
end
before_each(function()
-- Start the remote Neovim process. The `--embed` flag lets us control
-- Neovim through RPC, the `--headless` flag tells it not to wait for a
-- UI to attach and start loading plugins and configuration immediately
nvim = vim.fn.jobstart({'nvim', '--embed', '--headless'}, jobopts)
end)
after_each(function()
vim.fn.jobstop(nvim)
end)
it('Does not run for a blacklisted language', function()
request(exec_lua, 'the_strategy = require("rainbow-delimiters.strategy.track")(require("rainbow-delimiters.strategy.no-op"))', {})
request(exec_lua, 'vim.g.rainbow_delimiters = {blacklist = {"lua"}, strategy = {[""] = the_strategy}}', {})
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]', {})
assert.is.equal(0, attachments)
end)
it('Runs for a whitelisted language', function()
request(exec_lua, 'the_strategy = require("rainbow-delimiters.strategy.track")(require("rainbow-delimiters.strategy.no-op"))', {})
request(exec_lua, 'vim.g.rainbow_delimiters = {whitelist = {"lua"}, strategy = {[""] = the_strategy}}', {})
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]', {})
assert.is.equal(1, attachments)
end)
end)

View file

@ -1,15 +0,0 @@
# We can disable rainbow delimiters for certain languages
Execute lua (Set up the plugin):
the_strategy = require('rainbow-delimiters.strategy.track')(require('rainbow-delimiters.strategy.no-op'))
vim.g.rainbow_delimiters = {blacklist = {'lua'}, strategy = {[''] = the_strategy}}
Given lua (A Lua buffer):
'test'
Execute (Do Nothing):
Then (Not attached to the Lua buffer):
AssertEqual 0, luaeval('the_strategy.attachments[1]')
# vim:tw=79:ts=2:sw=2:et: