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