mirror of
https://github.com/HiPhish/rainbow-delimiters.nvim.git
synced 2024-09-08 02:25:48 +02:00
Transition E2E to use the yo-dawg plugin
This commit is contained in:
parent
6c7d918621
commit
ca8d5ee2b4
12 changed files with 222 additions and 320 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +1,6 @@
|
|||
[submodule "test/xdg/local/share/nvim/site/pack/testing/start/nvim-treesitter"]
|
||||
path = test/xdg/local/share/nvim/site/pack/testing/start/nvim-treesitter
|
||||
url = https://github.com/nvim-treesitter/nvim-treesitter
|
||||
[submodule "test/xdg/local/share/nvim/site/pack/testing/start/yo-dawg"]
|
||||
path = test/xdg/local/share/nvim/site/pack/testing/start/yo-dawg
|
||||
url = https://gitlab.com/HiPhish/yo-dawg.nvim.git
|
||||
|
|
|
@ -1,24 +1,13 @@
|
|||
local rpcrequest = vim.rpcrequest
|
||||
local test_utils = require 'testing.utils'
|
||||
|
||||
local call_function = 'nvim_call_function'
|
||||
local exec_lua = 'nvim_exec_lua'
|
||||
local buf_set_lines = 'nvim_buf_set_lines'
|
||||
local buf_set_option = 'nvim_buf_set_option'
|
||||
local cmd = 'nvim_cmd'
|
||||
local yd = require 'yo-dawg'
|
||||
|
||||
describe('Attaching a strategy to a buffer', function()
|
||||
local nvim
|
||||
|
||||
local function request(method, ...)
|
||||
return rpcrequest(nvim, method, ...)
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
nvim = test_utils.start_embedded()
|
||||
nvim = yd.start()
|
||||
|
||||
-- Set up a tracking strategy
|
||||
request(exec_lua, [[
|
||||
nvim:exec_lua([[
|
||||
TSEnsure('lua', 'vim')
|
||||
do
|
||||
local track = require('rainbow-delimiters.strategy.track')
|
||||
|
@ -33,36 +22,36 @@ describe('Attaching a strategy to a buffer', function()
|
|||
end)
|
||||
|
||||
after_each(function()
|
||||
test_utils.stop_embedded(nvim)
|
||||
yd.stop(nvim)
|
||||
end)
|
||||
|
||||
it('Does not attach a second time if the buffer is already attached', function()
|
||||
-- Write buffer to a file
|
||||
local tempfile = request(call_function, 'tempname', {})
|
||||
request(call_function, 'writefile', {{'print((((("Hello, world!")))))', '-- vim:ft=lua'}, tempfile})
|
||||
local tempfile = nvim:call_function('tempname', {})
|
||||
nvim:call_function('writefile', {{'print((((("Hello, world!")))))', '-- vim:ft=lua'}, tempfile})
|
||||
|
||||
-- Edit the buffer multiple times, this will trigger attachment
|
||||
for _ = 1, 3 do
|
||||
request(cmd, {cmd = 'edit', args = {tempfile}}, {})
|
||||
request(cmd, {cmd = 'filetype', args = {'detect'}}, {})
|
||||
nvim:cmd({cmd = 'edit', args = {tempfile}}, {})
|
||||
nvim:cmd({cmd = 'filetype', args = {'detect'}}, {})
|
||||
end
|
||||
|
||||
local count = request(exec_lua, 'return the_strategy.attachments[1]', {})
|
||||
local count = nvim:exec_lua('return the_strategy.attachments[1]', {})
|
||||
assert.is.equal(1, count, 'Buffer attached multiple times')
|
||||
end)
|
||||
|
||||
it('Performs cleanup after a buffer is deleted', function()
|
||||
local is_attached
|
||||
|
||||
request(buf_set_lines, 0, 0, -1, true, {'print((((("Hello, world!")))))', '-- vim:ft=lua'})
|
||||
request(cmd, {cmd = 'filetype', args = {'detect'}}, {})
|
||||
nvim:buf_set_lines(0, 0, -1, true, {'print((((("Hello, world!")))))', '-- vim:ft=lua'})
|
||||
nvim:cmd({cmd = 'filetype', args = {'detect'}}, {})
|
||||
|
||||
is_attached = request(exec_lua, 'return the_strategy.buffers[vim.fn.bufnr()] ~= nil', {})
|
||||
is_attached = nvim:exec_lua('return the_strategy.buffers[vim.fn.bufnr()] ~= nil', {})
|
||||
assert.is_true(is_attached, 'Strategy must be attach to buffer')
|
||||
|
||||
-- Delete the buffer
|
||||
request(cmd, {cmd = 'bdelete', bang = true}, {})
|
||||
is_attached = request(exec_lua, 'return the_strategy.buffers[vim.fn.bufnr()] ~= nil', {})
|
||||
nvim:cmd({cmd = 'bdelete', bang = true}, {})
|
||||
is_attached = nvim:exec_lua('return the_strategy.buffers[vim.fn.bufnr()] ~= nil', {})
|
||||
assert.is_false(is_attached, 'Strategy must not be attach to buffer')
|
||||
end)
|
||||
|
||||
|
@ -70,10 +59,10 @@ describe('Attaching a strategy to a buffer', function()
|
|||
-- Switching the file type preserves the number of attachments, but
|
||||
-- changes the language
|
||||
for _, expected in ipairs({'lua', 'vim'}) do
|
||||
request('nvim_buf_set_option', 0, 'filetype', expected)
|
||||
nvim:buf_set_option(0, 'filetype', expected)
|
||||
|
||||
local lang = request(exec_lua, 'return the_strategy.buffers[vim.fn.bufnr()].lang', {})
|
||||
local attachments = request(exec_lua, 'return the_strategy.attachments[1]', {})
|
||||
local lang = nvim:exec_lua('return the_strategy.buffers[vim.fn.bufnr()].lang', {})
|
||||
local attachments = nvim:exec_lua('return the_strategy.attachments[1]', {})
|
||||
|
||||
assert.is.equal(1, attachments)
|
||||
assert.is.equal(lang, expected)
|
||||
|
@ -82,15 +71,15 @@ describe('Attaching a strategy to a buffer', function()
|
|||
|
||||
it('Unloads a buffer without raising errors', function()
|
||||
-- Create two windows with different buffers, but with same file type
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
request(buf_set_lines, 0, 0, -1, true, {'print(((("Hello world"))))', '-- vim:ft=lua'})
|
||||
request(cmd, {cmd = 'new'}, {})
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
request(buf_set_lines, 0, 0, -1, true, {'print(((("Goodbye world"))))', '-- vim:ft=lua'})
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
nvim:buf_set_lines(0, 0, -1, true, {'print(((("Hello world"))))', '-- vim:ft=lua'})
|
||||
nvim:cmd({cmd = 'new'}, {})
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
nvim:buf_set_lines(0, 0, -1, true, {'print(((("Goodbye world"))))', '-- vim:ft=lua'})
|
||||
|
||||
local secondbuf = request(call_function, 'bufnr', {})
|
||||
request(cmd, {cmd = 'bdelete', args = {secondbuf}, bang = true}, {})
|
||||
local errmsg = request('nvim_get_vvar', 'errmsg')
|
||||
local secondbuf = nvim:call_function('bufnr', {})
|
||||
nvim:cmd({cmd = 'bdelete', args = {secondbuf}, bang = true}, {})
|
||||
local errmsg = nvim:get_vvar('errmsg')
|
||||
|
||||
assert.is.equal('', errmsg)
|
||||
end)
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
local rpcrequest = vim.rpcrequest
|
||||
local test_utils = require 'testing.utils'
|
||||
|
||||
local exec_lua = 'nvim_exec_lua'
|
||||
local yd = require 'yo-dawg'
|
||||
|
||||
---Markdown document with Lua code inside a code block
|
||||
local markdown_with_injected_lua = [[This is some Markdown
|
||||
|
@ -25,14 +22,10 @@ This is more markdown.]]
|
|||
describe('Buffer Manipulation', function()
|
||||
local nvim
|
||||
|
||||
local function request(method, ...)
|
||||
return rpcrequest(nvim, method, ...)
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
nvim = test_utils.start_embedded()
|
||||
request(exec_lua, 'TSEnsure(...)', {'lua', 'vim', 'markdown'})
|
||||
request(exec_lua, [[
|
||||
nvim = yd.start()
|
||||
nvim:exec_lua('TSEnsure(...)', {'lua', 'vim', 'markdown'})
|
||||
nvim:exec_lua([[
|
||||
local rb = require 'rainbow-delimiters'
|
||||
local global = rb.strategy.global
|
||||
assert(nil ~= global)
|
||||
|
@ -45,19 +38,19 @@ describe('Buffer Manipulation', function()
|
|||
end)
|
||||
|
||||
after_each(function()
|
||||
test_utils.stop_embedded(nvim)
|
||||
yd.stop(nvim)
|
||||
end)
|
||||
|
||||
it('Clears extmarks when moving line out of injected langauge', function()
|
||||
request('nvim_exec_lua', 'TSEnsure(...)', {'lua', 'markdown'})
|
||||
request('nvim_buf_set_lines', 0, 0, -2, true, vim.fn.split(markdown_with_injected_lua, '\n'))
|
||||
request('nvim_buf_set_option', 0, 'filetype', 'markdown')
|
||||
nvim:exec_lua('TSEnsure(...)', {'lua', 'markdown'})
|
||||
nvim:buf_set_lines(0, 0, -2, true, vim.fn.split(markdown_with_injected_lua, '\n'))
|
||||
nvim:buf_set_option(0, 'filetype', 'markdown')
|
||||
assert.nvim(nvim).has_extmarks_at(3, 5, 'lua')
|
||||
|
||||
-- Move Lua line out of code block
|
||||
request('nvim_cmd', {cmd = 'move', range = {4}, args = {5}}, {})
|
||||
nvim:cmd({cmd = 'move', range = {4}, args = {5}}, {})
|
||||
|
||||
local given = vim.fn.join(request('nvim_buf_get_lines', 0, 0, -2, true), '\n')
|
||||
local given = vim.fn.join(nvim:buf_get_lines(0, 0, -2, true), '\n')
|
||||
assert.is.equal(markdown_without_injected_lua, given)
|
||||
|
||||
-- Skip this test for now; calling `move` via RPC does not trigger the
|
||||
|
@ -68,15 +61,15 @@ describe('Buffer Manipulation', function()
|
|||
end)
|
||||
|
||||
it('Adds extmarks when moving line into injected langauge', function()
|
||||
request('nvim_exec_lua', 'TSEnsure(...)', {'lua', 'markdown'})
|
||||
request('nvim_buf_set_lines', 0, 0, -2, true, vim.fn.split(markdown_without_injected_lua, '\n'))
|
||||
request('nvim_buf_set_option', 0, 'filetype', 'markdown')
|
||||
nvim:exec_lua('TSEnsure(...)', {'lua', 'markdown'})
|
||||
nvim:buf_set_lines(0, 0, -2, true, vim.fn.split(markdown_without_injected_lua, '\n'))
|
||||
nvim:buf_set_option(0, 'filetype', 'markdown')
|
||||
assert.nvim(nvim).Not.has_extmarks_at(4, 5, 'lua')
|
||||
|
||||
-- Move Lua line out of code block
|
||||
request('nvim_cmd', {cmd = 'move', range = {5}, args = {3}}, {})
|
||||
nvim:cmd({cmd = 'move', range = {5}, args = {3}}, {})
|
||||
|
||||
local given = vim.fn.join(request('nvim_buf_get_lines', 0, 0, -2, true), '\n')
|
||||
local given = vim.fn.join(nvim:buf_get_lines(0, 0, -2, true), '\n')
|
||||
assert.is.equal(markdown_with_injected_lua, given)
|
||||
|
||||
-- Skip this test for now; calling `move` via RPC does not trigger the
|
||||
|
|
|
@ -1,32 +1,22 @@
|
|||
local rpcrequest = vim.rpcrequest
|
||||
local test_utils = require 'testing.utils'
|
||||
|
||||
local exec_lua = 'nvim_exec_lua'
|
||||
local exec_vim = 'nvim_exec2'
|
||||
local set_var = 'nvim_set_var'
|
||||
local buf_set_lines = 'nvim_buf_set_lines'
|
||||
local yd = require 'yo-dawg'
|
||||
|
||||
describe('User settings are respected', function()
|
||||
local nvim
|
||||
|
||||
local function request(method, ...)
|
||||
return rpcrequest(nvim, method, ...)
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
nvim = test_utils.start_embedded()
|
||||
nvim = yd.start()
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
test_utils.stop_embedded(nvim)
|
||||
yd.stop(nvim)
|
||||
end)
|
||||
|
||||
describe('Strategy settings', function()
|
||||
it('Applies the default strategy to all languages', function()
|
||||
local strategy = 'default strategy'
|
||||
request(exec_vim, 'let g:rainbow_delimiters = {"strategy": {"": "default strategy"}}', {})
|
||||
local lua_strategy = request(exec_lua, 'return require("rainbow-delimiters.config").strategy.lua', {})
|
||||
local c_strategy = request(exec_lua, 'return require("rainbow-delimiters.config").strategy.c', {})
|
||||
nvim:exec2('let g:rainbow_delimiters = {"strategy": {"": "default strategy"}}', {})
|
||||
local lua_strategy = nvim:exec_lua('return require("rainbow-delimiters.config").strategy.lua', {})
|
||||
local c_strategy = nvim:exec_lua('return require("rainbow-delimiters.config").strategy.c', {})
|
||||
assert.is.equal(strategy, lua_strategy)
|
||||
assert.is.equal(strategy, c_strategy)
|
||||
end)
|
||||
|
@ -35,13 +25,13 @@ describe('User settings are respected', function()
|
|||
-- I had to use a trick here because we cannot compare dictionaries or
|
||||
-- functions for identity between Vim script and Lua. Instead I
|
||||
-- set a string as the strategy and compare for that equality.
|
||||
request( exec_lua, 'require("rainbow-delimiters.default").strategy[""] = "default strategy"', {})
|
||||
nvim:exec_lua('require("rainbow-delimiters.default").strategy[""] = "default strategy"', {})
|
||||
|
||||
-- Override the strategy for Vim only
|
||||
request(set_var, 'rainbow_delimiters', {strategy = {vim = 'vim strategy'}})
|
||||
nvim:set_var('rainbow_delimiters', {strategy = {vim = 'vim strategy'}})
|
||||
|
||||
local lua_strategy = request(exec_lua, 'return require("rainbow-delimiters.config").strategy.lua', {})
|
||||
local vim_strategy = request(exec_lua, 'return require("rainbow-delimiters.config").strategy.vim', {})
|
||||
local lua_strategy = nvim:exec_lua('return require("rainbow-delimiters.config").strategy.lua', {})
|
||||
local vim_strategy = nvim:exec_lua('return require("rainbow-delimiters.config").strategy.vim', {})
|
||||
|
||||
assert.is.equal('vim strategy', vim_strategy, 'Wrong strategy found for Vim')
|
||||
assert.is.equal('default strategy', lua_strategy, 'Wrong strategy found for Lua')
|
||||
|
@ -50,10 +40,10 @@ describe('User settings are respected', function()
|
|||
describe('Strategies can be thunks', function()
|
||||
before_each(function()
|
||||
-- Store strategies in global variables for later reference
|
||||
request(exec_lua, 'noop = require("rainbow-delimiters").strategy.noop', {})
|
||||
request(exec_lua, 'the_strategy = require("rainbow-delimiters.strategy.track")(noop)', {})
|
||||
nvim:exec_lua('noop = require("rainbow-delimiters").strategy.noop', {})
|
||||
nvim:exec_lua('the_strategy = require("rainbow-delimiters.strategy.track")(noop)', {})
|
||||
-- Set a thunk as the strategy
|
||||
request(exec_lua, [[
|
||||
nvim:exec_lua([[
|
||||
vim.g.rainbow_delimiters = {
|
||||
strategy = {
|
||||
[""] = function() return the_strategy end,
|
||||
|
@ -63,18 +53,18 @@ describe('User settings are respected', function()
|
|||
end)
|
||||
|
||||
it('Uses the strategy returned by the thunk', function()
|
||||
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]', {})
|
||||
nvim:exec_lua('TSEnsure(...)', {'lua'})
|
||||
nvim:buf_set_lines(0, 0, -1, true, {'print "Hello world"', '-- vim:ft=lua'})
|
||||
nvim:command('filetype detect')
|
||||
local attachments = nvim:exec_lua('return the_strategy.attachments[1]', {})
|
||||
assert.is.equal(1, attachments, 'The strategy should be attached to the Lua buffer')
|
||||
end)
|
||||
|
||||
it('Does nothing if the thunk returns nil', function()
|
||||
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]', {})
|
||||
nvim:exec_lua('TSEnsure(...)', {'vim'})
|
||||
nvim:buf_set_lines(0, 0, -1, true, {'echo "Hello world"', '" vim:ft=vim'})
|
||||
nvim:command('filetype detect')
|
||||
local attachments = nvim:exec_lua('return the_strategy.attachments[1]', {})
|
||||
assert.is.equal(0, attachments, 'The strategy should not be attached to the Vim buffer')
|
||||
end)
|
||||
end)
|
||||
|
@ -82,10 +72,10 @@ describe('User settings are respected', function()
|
|||
|
||||
it('Overrides the query for an individual language', function()
|
||||
-- Override the query for one language only
|
||||
request(set_var, 'rainbow_delimiters', {query = {c = 'other-query'}})
|
||||
nvim:set_var('rainbow_delimiters', {query = {c = 'other-query'}})
|
||||
|
||||
local c_query = request(exec_lua, 'return require("rainbow-delimiters.config").query.c', {})
|
||||
local lua_query = request(exec_lua, 'return require("rainbow-delimiters.config").query.lua', {})
|
||||
local c_query = nvim:exec_lua('return require("rainbow-delimiters.config").query.c', {})
|
||||
local lua_query = nvim:exec_lua('return require("rainbow-delimiters.config").query.lua', {})
|
||||
|
||||
assert.is.equal('other-query', c_query)
|
||||
assert.is.equal('rainbow-delimiters', lua_query)
|
||||
|
@ -104,49 +94,49 @@ describe('User settings are respected', function()
|
|||
}
|
||||
|
||||
-- Set highlight to empty list
|
||||
request(set_var, 'rainbow_delimiters', {highlight = {}})
|
||||
nvim:set_var('rainbow_delimiters', {highlight = {}})
|
||||
|
||||
for i, expected in ipairs(hlgroups) do
|
||||
local given = request(exec_lua, 'return require("rainbow-delimiters.config").highlight[...]', {i})
|
||||
local given = nvim:exec_lua('return require("rainbow-delimiters.config").highlight[...]', {i})
|
||||
assert.is.equal(expected, given, string.format('Wrong highlight group at index %d', i))
|
||||
end
|
||||
end)
|
||||
|
||||
describe('White- and blacklist individual languages', function()
|
||||
it('Has all languages enabled without configuration', function()
|
||||
request(exec_lua, 'rbc = require("rainbow-delimiters.config")', {})
|
||||
local lua_enabled = request(exec_lua, 'return rbc.enabled_for("lua")', {})
|
||||
local vim_enabled = request(exec_lua, 'return rbc.enabled_for("vim")', {})
|
||||
nvim:exec_lua('rbc = require("rainbow-delimiters.config")', {})
|
||||
local lua_enabled = nvim:exec_lua('return rbc.enabled_for("lua")', {})
|
||||
local vim_enabled = nvim:exec_lua('return rbc.enabled_for("vim")', {})
|
||||
|
||||
assert.is_true(lua_enabled, 'Lua should be enabled')
|
||||
assert.is_true(vim_enabled, 'Vim script should be enabled')
|
||||
end)
|
||||
|
||||
it('Has all languages enabled in blank configuration', function()
|
||||
request(set_var, 'rainbow_delimiters', {})
|
||||
request(exec_lua, 'rbc = require("rainbow-delimiters.config")', {})
|
||||
local lua_enabled = request(exec_lua, 'return rbc.enabled_for("lua")', {})
|
||||
local vim_enabled = request(exec_lua, 'return rbc.enabled_for("vim")', {})
|
||||
nvim:set_var('rainbow_delimiters', {})
|
||||
nvim:exec_lua('rbc = require("rainbow-delimiters.config")', {})
|
||||
local lua_enabled = nvim:exec_lua('return rbc.enabled_for("lua")', {})
|
||||
local vim_enabled = nvim:exec_lua('return rbc.enabled_for("vim")', {})
|
||||
|
||||
assert.is_true(lua_enabled, 'Lua should be enabled')
|
||||
assert.is_true(vim_enabled, 'Vim script should be enabled')
|
||||
end)
|
||||
|
||||
it('Can whitelist individual file types by adding them to our configuration', function()
|
||||
request(set_var, 'rainbow_delimiters', {whitelist = {'lua'}})
|
||||
request(exec_lua, 'rbc = require("rainbow-delimiters.config")', {})
|
||||
local lua_enabled = request(exec_lua, 'return rbc.enabled_for("lua")', {})
|
||||
local vim_enabled = request(exec_lua, 'return rbc.enabled_for("vim")', {})
|
||||
nvim:set_var('rainbow_delimiters', {whitelist = {'lua'}})
|
||||
nvim:exec_lua('rbc = require("rainbow-delimiters.config")', {})
|
||||
local lua_enabled = nvim:exec_lua('return rbc.enabled_for("lua")', {})
|
||||
local vim_enabled = nvim:exec_lua('return rbc.enabled_for("vim")', {})
|
||||
|
||||
assert.is_true( lua_enabled, 'Lua should be enabled')
|
||||
assert.is_false(vim_enabled, 'Vim script should be disabled')
|
||||
end)
|
||||
|
||||
it('Can blacklist individual file types by adding them to our configuration', function()
|
||||
request(set_var, 'rainbow_delimiters', {blacklist = {'vim'}})
|
||||
request(exec_lua, 'rbc = require("rainbow-delimiters.config")', {})
|
||||
local lua_enabled = request(exec_lua, 'return rbc.enabled_for("lua")', {})
|
||||
local vim_enabled = request(exec_lua, 'return rbc.enabled_for("vim")', {})
|
||||
nvim:set_var('rainbow_delimiters', {blacklist = {'vim'}})
|
||||
nvim:exec_lua('rbc = require("rainbow-delimiters.config")', {})
|
||||
local lua_enabled = nvim:exec_lua('return rbc.enabled_for("lua")', {})
|
||||
local vim_enabled = nvim:exec_lua('return rbc.enabled_for("vim")', {})
|
||||
|
||||
assert.is_true( lua_enabled, 'Lua should be enabled')
|
||||
assert.is_false(vim_enabled, 'Vim script should be disabled')
|
||||
|
@ -155,26 +145,26 @@ describe('User settings are respected', function()
|
|||
|
||||
describe('The setup function sets configuration indirectly', function()
|
||||
it('Can call the setup function', function()
|
||||
request(exec_lua, [[
|
||||
nvim:exec_lua([[
|
||||
require('rainbow-delimiters.setup').setup {
|
||||
query = {
|
||||
lua = 'rainbow-blocks'
|
||||
}
|
||||
}
|
||||
]], {})
|
||||
local lua_query = request('nvim_eval', 'g:rainbow_delimiters.query.lua')
|
||||
local lua_query = nvim:eval('g:rainbow_delimiters.query.lua')
|
||||
assert.is.equal('rainbow-blocks', lua_query)
|
||||
end)
|
||||
|
||||
it('Can call the table itset', function()
|
||||
request(exec_lua, [[
|
||||
nvim:exec_lua([[
|
||||
require('rainbow-delimiters.setup') {
|
||||
query = {
|
||||
lua = 'rainbow-blocks'
|
||||
}
|
||||
}
|
||||
]], {})
|
||||
local lua_query = request('nvim_eval', 'g:rainbow_delimiters.query.lua')
|
||||
local lua_query = nvim:eval('g:rainbow_delimiters.query.lua')
|
||||
assert.is.equal('rainbow-blocks', lua_query)
|
||||
end)
|
||||
end)
|
||||
|
|
|
@ -1,24 +1,13 @@
|
|||
local rpcrequest = vim.rpcrequest
|
||||
local test_utils = require 'testing.utils'
|
||||
|
||||
local exec_lua = 'nvim_exec_lua'
|
||||
local buf_set_lines = 'nvim_buf_set_lines'
|
||||
local buf_set_option = 'nvim_buf_set_option'
|
||||
local command = 'nvim_command'
|
||||
|
||||
local yd = require 'yo-dawg'
|
||||
|
||||
describe('The Rainbow Delimiters public API', function()
|
||||
local nvim
|
||||
|
||||
local function request(method, ...)
|
||||
return rpcrequest(nvim, method, ...)
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
nvim = test_utils.start_embedded()
|
||||
nvim = yd.start()
|
||||
|
||||
-- Set up a tracking strategy
|
||||
request(exec_lua, [[
|
||||
nvim:exec_lua([[
|
||||
TSEnsure('markdown', 'lua', 'vim')
|
||||
rb = require 'rainbow-delimiters'
|
||||
vim.g.rainbow_delimiters = {
|
||||
|
@ -29,36 +18,36 @@ describe('The Rainbow Delimiters public API', function()
|
|||
end)
|
||||
|
||||
after_each(function()
|
||||
test_utils.stop_embedded(nvim)
|
||||
yd.stop(nvim)
|
||||
end)
|
||||
|
||||
describe('Whether RB is enabled for a buffer at startup', function()
|
||||
it('Is disabled for a buffer without file type', function()
|
||||
assert.is.False(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
assert.is.False(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Is enabled for a supported language', function()
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
assert.is.True(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
assert.is.True(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
describe('Blacklist', function()
|
||||
before_each(function()
|
||||
request(command, 'let g:rainbow_delimiters.blacklist = ["markdown"]')
|
||||
nvim:command('let g:rainbow_delimiters.blacklist = ["markdown"]')
|
||||
end)
|
||||
|
||||
it('Is enabled for a not blacklisted language', function()
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
assert.is.True(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
assert.is.True(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Is disabled for a blacklisted language', function()
|
||||
request(buf_set_option, 0, 'filetype', 'markdown')
|
||||
assert.is.False(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'markdown')
|
||||
assert.is.False(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Is disabled for a blacklisted language with injected whitelisted language', function()
|
||||
request(buf_set_lines, 0, 0, -1, true, {
|
||||
nvim:buf_set_lines(0, 0, -1, true, {
|
||||
'This is Markdown',
|
||||
'',
|
||||
'```lua',
|
||||
|
@ -67,37 +56,37 @@ describe('The Rainbow Delimiters public API', function()
|
|||
'',
|
||||
'More Markdown',
|
||||
})
|
||||
request(buf_set_option, 0, 'filetype', 'markdown')
|
||||
assert.is.False(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'markdown')
|
||||
assert.is.False(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('Whitelist', function()
|
||||
before_each(function()
|
||||
request(command, 'let g:rainbow_delimiters.whitelist = ["lua"]')
|
||||
nvim:command('let g:rainbow_delimiters.whitelist = ["lua"]')
|
||||
end)
|
||||
|
||||
it('Is disabled for a not whitelisted language', function()
|
||||
request(buf_set_option, 0, 'filetype', 'markdown')
|
||||
assert.is.False(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'markdown')
|
||||
assert.is.False(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Is enabled for a whitelisted language', function()
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
assert.is.True(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
assert.is.True(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Is enabled for whitelisted language with other language injected', function()
|
||||
request(buf_set_lines, 0, 0, -1, true, {
|
||||
nvim:buf_set_lines(0, 0, -1, true, {
|
||||
'print "This is Lua"',
|
||||
'vim.cmd [[echo "This is Vim"]]',
|
||||
})
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
assert.is.True(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
assert.is.True(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Is disabled for not whitelisted language with injected whitelisted language', function()
|
||||
request(buf_set_lines, 0, 0, -1, true, {
|
||||
nvim:buf_set_lines(0, 0, -1, true, {
|
||||
'This is Markdown',
|
||||
'',
|
||||
'```lua',
|
||||
|
@ -106,87 +95,87 @@ describe('The Rainbow Delimiters public API', function()
|
|||
'',
|
||||
'More Markdown',
|
||||
})
|
||||
request(buf_set_option, 0, 'filetype', 'markdown')
|
||||
assert.is.False(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'markdown')
|
||||
assert.is.False(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('Manual toggling', function()
|
||||
it('Can be disabled for a buffer', function()
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
request(exec_lua, 'rb.disable(0)', {})
|
||||
assert.is.False(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
nvim:exec_lua('rb.disable(0)', {})
|
||||
assert.is.False(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Can be turned back on', function()
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
request(exec_lua, 'rb.disable(0)', {})
|
||||
request(exec_lua, 'rb.enable(0)', {})
|
||||
assert.is.True(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
nvim:exec_lua('rb.disable(0)', {})
|
||||
nvim:exec_lua('rb.enable(0)', {})
|
||||
assert.is.True(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Can be toggled off', function()
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
request(exec_lua, 'rb.toggle(0)', {})
|
||||
assert.is.False(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
nvim:exec_lua('rb.toggle(0)', {})
|
||||
assert.is.False(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Can be toggled on', function()
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
request(exec_lua, 'rb.toggle(0)', {})
|
||||
request(exec_lua, 'rb.toggle(0)', {})
|
||||
assert.is.True(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
nvim:exec_lua('rb.toggle(0)', {})
|
||||
nvim:exec_lua('rb.toggle(0)', {})
|
||||
assert.is.True(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Gets disabled idempotently', function()
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
request(exec_lua, 'rb.disable(0)', {})
|
||||
request(exec_lua, 'rb.disable(0)', {})
|
||||
assert.is.False(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
nvim:exec_lua('rb.disable(0)', {})
|
||||
nvim:exec_lua('rb.disable(0)', {})
|
||||
assert.is.False(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Gets enabled idempotently', function()
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
request(exec_lua, 'rb.disable(0)', {})
|
||||
request(exec_lua, 'rb.enable(0)', {})
|
||||
request(exec_lua, 'rb.enable(0)', {})
|
||||
assert.is.True(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
nvim:exec_lua('rb.disable(0)', {})
|
||||
nvim:exec_lua('rb.enable(0)', {})
|
||||
nvim:exec_lua('rb.enable(0)', {})
|
||||
assert.is.True(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
describe('Blacklist', function()
|
||||
before_each(function()
|
||||
request(command, 'let g:rainbow_delimiters.blacklist = ["markdown"]')
|
||||
nvim:command('let g:rainbow_delimiters.blacklist = ["markdown"]')
|
||||
end)
|
||||
|
||||
it('Can be enabled for a blacklisted language', function()
|
||||
request(buf_set_option, 0, 'filetype', 'markdown')
|
||||
request(exec_lua, 'rb.enable(0)', {})
|
||||
assert.is.True(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'markdown')
|
||||
nvim:exec_lua('rb.enable(0)', {})
|
||||
assert.is.True(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Can be toggled for a blacklisted language', function()
|
||||
request(buf_set_option, 0, 'filetype', 'markdown')
|
||||
request(exec_lua, 'rb.toggle(0)', {})
|
||||
assert.is.True(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'markdown')
|
||||
nvim:exec_lua('rb.toggle(0)', {})
|
||||
assert.is.True(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('Whitelist', function()
|
||||
before_each(function()
|
||||
request(command, 'let g:rainbow_delimiters.whitelist = ["lua"]')
|
||||
nvim:command('let g:rainbow_delimiters.whitelist = ["lua"]')
|
||||
end)
|
||||
|
||||
it('Can be disabled for a whitelisted language', function()
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
request(exec_lua, 'rb.disable(0)', {})
|
||||
assert.is.False(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
nvim:exec_lua('rb.disable(0)', {})
|
||||
assert.is.False(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
|
||||
it('Can be toggled for a whitelisted language', function()
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
request(exec_lua, 'rb.toggle(0)', {})
|
||||
assert.is.False(request(exec_lua, 'return rb.is_enabled()', {}))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
nvim:exec_lua('rb.toggle(0)', {})
|
||||
assert.is.False(nvim:exec_lua('return rb.is_enabled()', {}))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
|
@ -1,39 +1,31 @@
|
|||
local rpcrequest = vim.rpcrequest
|
||||
local test_utils = require 'testing.utils'
|
||||
|
||||
local exec_lua = 'nvim_exec_lua'
|
||||
local buf_set_lines = 'nvim_buf_set_lines'
|
||||
local yd = require 'yo-dawg'
|
||||
|
||||
describe('We can disable rainbow delimiters for certain languages', function()
|
||||
local nvim
|
||||
|
||||
local function request(method, ...)
|
||||
return rpcrequest(nvim, method, ...)
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
nvim = test_utils.start_embedded()
|
||||
nvim = yd.start()
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
test_utils.stop_embedded(nvim)
|
||||
yd.stop(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]', {})
|
||||
nvim:exec_lua('the_strategy = require("rainbow-delimiters.strategy.track")(require("rainbow-delimiters.strategy.no-op"))', {})
|
||||
nvim:exec_lua('vim.g.rainbow_delimiters = {blacklist = {"lua"}, strategy = {[""] = the_strategy}}', {})
|
||||
nvim:buf_set_lines(0, 0, -1, true, {'print "Hello world"', '-- vim:ft=lua'})
|
||||
nvim:command('filetype detect')
|
||||
local attachments = nvim: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]', {})
|
||||
nvim:exec_lua('the_strategy = require("rainbow-delimiters.strategy.track")(require("rainbow-delimiters.strategy.no-op"))', {})
|
||||
nvim:exec_lua('vim.g.rainbow_delimiters = {whitelist = {"lua"}, strategy = {[""] = the_strategy}}', {})
|
||||
nvim:buf_set_lines(0, 0, -1, true, {'print "Hello world"', '-- vim:ft=lua'})
|
||||
nvim:command('filetype detect')
|
||||
local attachments = nvim:exec_lua('return the_strategy.attachments[1]', {})
|
||||
assert.is.equal(1, attachments)
|
||||
end)
|
||||
end)
|
||||
|
|
|
@ -1,23 +1,12 @@
|
|||
local rpcrequest = vim.rpcrequest
|
||||
local test_utils = require 'testing.utils'
|
||||
|
||||
local exec_lua = 'nvim_exec_lua'
|
||||
local feedkeys = 'nvim_feedkeys'
|
||||
local call_function = 'nvim_call_function'
|
||||
local buf_set_lines = 'nvim_buf_set_lines'
|
||||
local buf_set_option = 'nvim_buf_set_option'
|
||||
local yd = require 'yo-dawg'
|
||||
|
||||
describe('The global strategy', function()
|
||||
local nvim
|
||||
|
||||
local function request(method, ...)
|
||||
return rpcrequest(nvim, method, ...)
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
nvim = test_utils.start_embedded()
|
||||
request(exec_lua, 'TSEnsure(...)', {'lua', 'vim'})
|
||||
request(exec_lua, [[
|
||||
nvim = yd.start()
|
||||
nvim:exec_lua('TSEnsure(...)', {'lua', 'vim'})
|
||||
nvim:exec_lua([[
|
||||
local rb = require 'rainbow-delimiters'
|
||||
local track = require('rainbow-delimiters.strategy.track')
|
||||
local global = rb.strategy.global
|
||||
|
@ -33,37 +22,37 @@ describe('The global strategy', function()
|
|||
end)
|
||||
|
||||
after_each(function()
|
||||
test_utils.stop_embedded(nvim)
|
||||
yd.stop(nvim)
|
||||
end)
|
||||
|
||||
it('Does not reactivate when making changes', function()
|
||||
request(buf_set_lines, 0, 0, -1, true, {'print({{{{{}}}}})', '-- vim:ft=lua'})
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
nvim:buf_set_lines(0, 0, -1, true, {'print({{{{{}}}}})', '-- vim:ft=lua'})
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
assert.nvim(nvim).has_extmarks_at(0, 5, 'lua')
|
||||
|
||||
request(call_function, 'rainbow_delimiters#disable', {0})
|
||||
nvim:call_function('rainbow_delimiters#disable', {0})
|
||||
assert.nvim(nvim).Not.has_extmarks_at(0, 5, 'lua')
|
||||
|
||||
-- Add a new pair of curly braces
|
||||
-- (jump to first column, find the first closing brace, insert new pair)
|
||||
local keys = vim.api.nvim_replace_termcodes('gg0f}i{}<esc>', true, false, true)
|
||||
request(feedkeys, keys, 'n', false)
|
||||
assert.is.same({'print({{{{{{}}}}}})'}, request('nvim_buf_get_lines', 0, 0, 1, true))
|
||||
nvim:feedkeys(keys, 'n', false)
|
||||
assert.is.same({'print({{{{{{}}}}}})'}, nvim:buf_get_lines(0, 0, 1, true))
|
||||
|
||||
assert.nvim(nvim).Not.has_extmarks_at(0, 5, 'lua')
|
||||
assert.is.equal(0, request(exec_lua, 'return the_strategy.attachments[1]', {}))
|
||||
assert.is.equal(0, nvim:exec_lua('return the_strategy.attachments[1]', {}))
|
||||
end)
|
||||
|
||||
it('Ignores blacklisted injected languages', function()
|
||||
request(exec_lua, 'vim.g.rainbow_delimiters.blacklist = {...}', {'vim'})
|
||||
request(buf_set_lines, 0, 0, -1, true, {
|
||||
nvim:exec_lua('vim.g.rainbow_delimiters.blacklist = {...}', {'vim'})
|
||||
nvim:buf_set_lines(0, 0, -1, true, {
|
||||
'print {{{{{}}}}}',
|
||||
'vim.cmd [[',
|
||||
' echo string(1 + (2 + (3 + 4)))',
|
||||
']]',
|
||||
'-- vim:ft=lua'
|
||||
})
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
|
||||
-- The Lua code is highlighted, the Vim code not
|
||||
assert.nvim(nvim).has_extmarks_at(0, 6, 'lua')
|
||||
|
@ -71,15 +60,15 @@ describe('The global strategy', function()
|
|||
end)
|
||||
|
||||
it('Ignores non-whitelisted injected languages', function()
|
||||
request(exec_lua, 'vim.g.rainbow_delimiters.whitelist = {...}', {'lua'})
|
||||
request(buf_set_lines, 0, 0, -1, true, {
|
||||
nvim:exec_lua('vim.g.rainbow_delimiters.whitelist = {...}', {'lua'})
|
||||
nvim:buf_set_lines(0, 0, -1, true, {
|
||||
'print {{{{{}}}}}',
|
||||
'vim.cmd [[',
|
||||
' echo string(1 + (2 + (3 + 4)))',
|
||||
']]',
|
||||
'-- vim:ft=lua'
|
||||
})
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
|
||||
-- The Lua code is highlighted, the Vim code not
|
||||
assert.nvim(nvim).has_extmarks_at(0, 6, 'lua')
|
||||
|
@ -96,13 +85,13 @@ end
|
|||
|
||||
return foo]]
|
||||
|
||||
request(exec_lua, 'vim.g.rainbow_delimiters.query.lua = "rainbow-blocks"', {})
|
||||
request(buf_set_lines, 0, 0, -1, true, vim.fn.split(content, '\n'))
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
nvim:exec_lua('vim.g.rainbow_delimiters.query.lua = "rainbow-blocks"', {})
|
||||
nvim:buf_set_lines(0, 0, -1, true, vim.fn.split(content, '\n'))
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
-- Insert the line " b = print('b'),"
|
||||
request('nvim_win_set_cursor', 0, {3, 0})
|
||||
nvim:win_set_cursor(0, {3, 0})
|
||||
local keys = vim.api.nvim_replace_termcodes("ob = print('b'),<esc>", true, false, true)
|
||||
vim.fn.rpcrequest(nvim,'nvim_feedkeys', keys, '', false)
|
||||
nvim:feedkeys(keys, '', false)
|
||||
|
||||
assert.nvim(nvim).has_extmarks_at(2, 11, 'lua')
|
||||
assert.nvim(nvim).has_extmarks_at(3, 11, 'lua')
|
||||
|
|
|
@ -1,23 +1,12 @@
|
|||
local rpcrequest = vim.rpcrequest
|
||||
local test_utils = require 'testing.utils'
|
||||
|
||||
local exec_lua = 'nvim_exec_lua'
|
||||
local feedkeys = 'nvim_feedkeys'
|
||||
local call_function = 'nvim_call_function'
|
||||
local buf_set_lines = 'nvim_buf_set_lines'
|
||||
local buf_set_option = 'nvim_buf_set_option'
|
||||
local yd = require 'yo-dawg'
|
||||
|
||||
describe('The local strategy', function()
|
||||
local nvim
|
||||
|
||||
local function request(method, ...)
|
||||
return rpcrequest(nvim, method, ...)
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
nvim = test_utils.start_embedded()
|
||||
request(exec_lua, 'TSEnsure(...)', {'lua', 'vim'})
|
||||
request(exec_lua, [[
|
||||
nvim = yd.start()
|
||||
nvim:exec_lua('TSEnsure(...)', {'lua', 'vim'})
|
||||
nvim:exec_lua([[
|
||||
local rb = require 'rainbow-delimiters'
|
||||
local track = require('rainbow-delimiters.strategy.track')
|
||||
local strategy = rb.strategy['local']
|
||||
|
@ -32,26 +21,26 @@ describe('The local strategy', function()
|
|||
end)
|
||||
|
||||
after_each(function()
|
||||
test_utils.stop_embedded(nvim)
|
||||
yd.stop(nvim)
|
||||
end)
|
||||
|
||||
it('Does not reactivate when making changes', function()
|
||||
request(buf_set_lines, 0, 0, -1, true, {'print({{{{{}}}}})', '-- vim:ft=lua'})
|
||||
request('nvim_win_set_cursor', 0, {1, 5})
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
nvim:buf_set_lines(0, 0, -1, true, {'print({{{{{}}}}})', '-- vim:ft=lua'})
|
||||
nvim:win_set_cursor(0, {1, 5})
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
assert.nvim(nvim).has_extmarks_at(0, 5, 'lua')
|
||||
|
||||
request(call_function, 'rainbow_delimiters#disable', {0})
|
||||
nvim:call_function('rainbow_delimiters#disable', {0})
|
||||
assert.nvim(nvim).Not.has_extmarks_at(0, 5, 'lua')
|
||||
|
||||
-- Add a new pair of curly braces
|
||||
-- (jump to first column, find the first closing brace, insert new pair)
|
||||
local keys = vim.api.nvim_replace_termcodes('gg0f}i{}<esc>', true, false, true)
|
||||
request(feedkeys, keys, 'n', false)
|
||||
assert.is.same({'print({{{{{{}}}}}})'}, request('nvim_buf_get_lines', 0, 0, 1, true))
|
||||
nvim:feedkeys(keys, 'n', false)
|
||||
assert.is.same({'print({{{{{{}}}}}})'}, nvim:buf_get_lines(0, 0, 1, true))
|
||||
|
||||
assert.nvim(nvim).Not.has_extmarks_at(0, 5, 'lua')
|
||||
assert.is.equal(0, request(exec_lua, 'return the_strategy.attachments[1]', {}))
|
||||
assert.is.equal(0, nvim:exec_lua('return the_strategy.attachments[1]', {}))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
|
|
@ -1,28 +1,18 @@
|
|||
local rpcrequest = vim.rpcrequest
|
||||
local test_utils = require 'testing.utils'
|
||||
|
||||
local call_function = 'nvim_call_function'
|
||||
local exec_lua = 'nvim_exec_lua'
|
||||
local buf_set_lines = 'nvim_buf_set_lines'
|
||||
local buf_set_option = 'nvim_buf_set_option'
|
||||
local yd = require 'yo-dawg'
|
||||
|
||||
describe('We can use functions to turn rainbow delimiters off and on again.', function()
|
||||
local nvim
|
||||
|
||||
local function request(method, ...)
|
||||
return rpcrequest(nvim, method, ...)
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
nvim = test_utils.start_embedded()
|
||||
request(exec_lua, 'the_strategy = require("rainbow-delimiters.strategy.global")', {})
|
||||
request(exec_lua, 'TSEnsure(...)', {'lua'})
|
||||
request(buf_set_lines, 0, 0, -1, true, {'print((((("Hello, world!")))))'})
|
||||
request(buf_set_option, 0, 'filetype', 'lua')
|
||||
nvim = yd.start()
|
||||
nvim:exec_lua('the_strategy = require("rainbow-delimiters.strategy.global")', {})
|
||||
nvim:exec_lua('TSEnsure(...)', {'lua'})
|
||||
nvim:buf_set_lines(0, 0, -1, true, {'print((((("Hello, world!")))))'})
|
||||
nvim:buf_set_option(0, 'filetype', 'lua')
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
test_utils.stop_embedded(nvim)
|
||||
yd.stop(nvim)
|
||||
end)
|
||||
|
||||
it('Does highlighting initially', function()
|
||||
|
@ -30,44 +20,44 @@ describe('We can use functions to turn rainbow delimiters off and on again.', fu
|
|||
end)
|
||||
|
||||
it('Disables rainbow delimiters', function()
|
||||
request(call_function, 'rainbow_delimiters#disable', {0})
|
||||
nvim:call_function('rainbow_delimiters#disable', {0})
|
||||
assert.nvim(nvim).Not.has_extmarks_at(0, 5, 'lua')
|
||||
end)
|
||||
|
||||
it('Remains disabled when disabling twice', function()
|
||||
request(call_function, 'rainbow_delimiters#disable', {0})
|
||||
request(call_function, 'rainbow_delimiters#disable', {0})
|
||||
nvim:call_function('rainbow_delimiters#disable', {0})
|
||||
nvim:call_function('rainbow_delimiters#disable', {0})
|
||||
|
||||
assert.nvim(nvim).Not.has_extmarks_at(0, 5, 'lua')
|
||||
end)
|
||||
|
||||
it('Turns rainbow delimiters back on', function()
|
||||
request(call_function, 'rainbow_delimiters#disable', {0})
|
||||
request(call_function, 'rainbow_delimiters#enable', {0})
|
||||
nvim:call_function('rainbow_delimiters#disable', {0})
|
||||
nvim:call_function('rainbow_delimiters#enable', {0})
|
||||
|
||||
assert.nvim(nvim).has_extmarks_at(0, 5, 'lua')
|
||||
end)
|
||||
|
||||
it('Remains enabled when enabling twice', function()
|
||||
request(call_function, 'rainbow_delimiters#disable', {0})
|
||||
request(call_function, 'rainbow_delimiters#enable', {0})
|
||||
request(call_function, 'rainbow_delimiters#enable', {0})
|
||||
nvim:call_function('rainbow_delimiters#disable', {0})
|
||||
nvim:call_function('rainbow_delimiters#enable', {0})
|
||||
nvim:call_function('rainbow_delimiters#enable', {0})
|
||||
|
||||
assert.nvim(nvim).has_extmarks_at(0, 5, 'lua')
|
||||
end)
|
||||
|
||||
it('Can be disabled after being enabled', function()
|
||||
request(call_function, 'rainbow_delimiters#disable', {0})
|
||||
request(call_function, 'rainbow_delimiters#enable', {0})
|
||||
request(call_function, 'rainbow_delimiters#disable', {0})
|
||||
nvim:call_function('rainbow_delimiters#disable', {0})
|
||||
nvim:call_function('rainbow_delimiters#enable', {0})
|
||||
nvim:call_function('rainbow_delimiters#disable', {0})
|
||||
|
||||
assert.nvim(nvim).Not.has_extmarks_at(0, 5, 'lua')
|
||||
end)
|
||||
|
||||
it('Can be enabled after being disabled twice', function()
|
||||
request(call_function, 'rainbow_delimiters#disable', {0})
|
||||
request(call_function, 'rainbow_delimiters#disable', {0})
|
||||
request(call_function, 'rainbow_delimiters#enable', {0})
|
||||
nvim:call_function('rainbow_delimiters#disable', {0})
|
||||
nvim:call_function('rainbow_delimiters#disable', {0})
|
||||
nvim:call_function('rainbow_delimiters#enable', {0})
|
||||
|
||||
assert.nvim(nvim).has_extmarks_at(0, 5, 'lua')
|
||||
end)
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
local M = {}
|
||||
|
||||
local jobopts = {
|
||||
rpc = true,
|
||||
width = 80,
|
||||
height = 24,
|
||||
}
|
||||
|
||||
---Start the remote Neovim process.
|
||||
function M.start_embedded()
|
||||
-- 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.
|
||||
return vim.fn.jobstart({'nvim', '--embed', '--headless'}, jobopts)
|
||||
end
|
||||
|
||||
function M.stop_embedded(nvim)
|
||||
vim.rpcnotify(nvim, 'nvim_cmd', {cmd = 'quitall', bang = true}, {})
|
||||
vim.fn.jobwait({nvim})
|
||||
end
|
||||
|
||||
return M
|
|
@ -3,7 +3,6 @@
|
|||
local say = require 'say'
|
||||
local assert = require 'luassert'
|
||||
local filter = vim.fn.filter
|
||||
local rpcrequest = vim.rpcrequest
|
||||
|
||||
|
||||
local NVIM_STATE_KEY = {}
|
||||
|
@ -21,8 +20,8 @@ local function has_extmarks_at(_state, arguments, lang)
|
|||
local nvim = rawget(_state, NVIM_STATE_KEY)
|
||||
assert(nvim ~= nil, 'No Neovim channel set, use the nvim modifier to set the channel')
|
||||
local row, column = arguments[1], arguments[2]
|
||||
local nsid = rpcrequest(nvim, 'nvim_exec_lua', 'return require("rainbow-delimiters.lib").nsids[...]', {lang})
|
||||
local extmarks = rpcrequest(nvim, 'nvim_exec_lua', 'return vim.inspect_pos(...).extmarks', {0, row, column})
|
||||
local nsid = nvim:exec_lua('return require("rainbow-delimiters.lib").nsids[...]', {lang})
|
||||
local extmarks = nvim:exec_lua('return vim.inspect_pos(...).extmarks', {0, row, column})
|
||||
filter(extmarks, function(_, v) return v.ns_id == nsid end)
|
||||
return #extmarks > 0
|
||||
end
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 9c2694cc435b31d9a5221b8ec84cbc06117ebbb8
|
Loading…
Reference in a new issue