1

Regenerate nvim config

This commit is contained in:
2024-06-02 03:29:20 +02:00
parent 75eea0c030
commit ef2e28883d
5576 changed files with 604886 additions and 503 deletions

View File

@ -0,0 +1,86 @@
local yd = require 'yo-dawg'
describe('Attaching a strategy to a buffer', function()
local nvim
before_each(function()
nvim = yd.start()
-- Set up a tracking strategy
nvim:exec_lua([[
TSEnsure('lua', 'vim')
do
local track = require('rainbow-delimiters.strategy.track')
local noop = require('rainbow-delimiters.strategy.no-op')
the_strategy = track(noop)
end
vim.g.rainbow_delimiters = {
strategy = {
[''] = the_strategy
}
}]], {})
end)
after_each(function()
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 = 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
nvim:cmd({cmd = 'edit', args = {tempfile}}, {})
nvim:cmd({cmd = 'filetype', args = {'detect'}}, {})
end
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
nvim:buf_set_lines(0, 0, -1, true, {'print((((("Hello, world!")))))', '-- vim:ft=lua'})
nvim:cmd({cmd = 'filetype', args = {'detect'}}, {})
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
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)
it('Detaches from the buffer and re-attached with the new language', function()
-- Switching the file type preserves the number of attachments, but
-- changes the language
for _, expected in ipairs({'lua', 'vim'}) do
nvim:buf_set_option(0, 'filetype', expected)
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)
end
end)
it('Unloads a buffer without raising errors', function()
-- Create two windows with different buffers, but with same file type
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 = nvim:call_function('bufnr', {})
nvim:cmd({cmd = 'bdelete', args = {secondbuf}, bang = true}, {})
local errmsg = nvim:get_vvar('errmsg')
assert.is.equal('', errmsg)
end)
end)

View File

@ -0,0 +1,73 @@
local yd = require 'yo-dawg'
---Markdown document with Lua code inside a code block
local markdown_with_injected_lua = [[This is some Markdown
```lua
print(((('Hello world'))))
```
This is more markdown.]]
---Markdown document with Lua code outside a code block
local markdown_without_injected_lua = [[This is some Markdown
```lua
```
print(((('Hello world'))))
This is more markdown.]]
describe('Buffer Manipulation', function()
local nvim
before_each(function()
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)
vim.g.rainbow_delimiters = {
strategy = {
[''] = global
},
}
]], {})
end)
after_each(function()
yd.stop(nvim)
end)
it('Clears extmarks when moving line out of injected langauge', function()
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
nvim:cmd({cmd = 'move', range = {4}, args = {5}}, {})
local given = vim.fn.join(nvim:buf_get_lines(0, 0, -2, true), '\n')
assert.is.equal(markdown_without_injected_lua, given)
assert.nvim(nvim).Not.has_extmarks_at(4, 5, 'lua')
end)
it('Adds extmarks when moving line into injected langauge', function()
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
nvim:cmd({cmd = 'move', range = {5}, args = {3}}, {})
local given = vim.fn.join(nvim:buf_get_lines(0, 0, -2, true), '\n')
assert.is.equal(markdown_with_injected_lua, given)
assert.nvim(nvim).has_extmarks_at(3, 5, 'lua')
end)
end)

View File

@ -0,0 +1,171 @@
local yd = require 'yo-dawg'
describe('User settings are respected', function()
local nvim
before_each(function()
nvim = yd.start()
end)
after_each(function()
yd.stop(nvim)
end)
describe('Strategy settings', function()
it('Applies the default strategy to all languages', function()
local strategy = 'default strategy'
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)
it('Overrides the strategy for individual languages', 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.
nvim:exec_lua('require("rainbow-delimiters.default").strategy[""] = "default strategy"', {})
-- Override the strategy for Vim only
nvim:set_var('rainbow_delimiters', {strategy = {vim = 'vim strategy'}})
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')
end)
describe('Strategies can be thunks', function()
before_each(function()
-- Store strategies in global variables for later reference
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
nvim:exec_lua([[
vim.g.rainbow_delimiters = {
strategy = {
[""] = function() return the_strategy end,
vim = function() return nil end
}
}]], {})
end)
it('Uses the strategy returned by the thunk', function()
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()
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)
end)
it('Overrides the query for an individual language', function()
-- Override the query for one language only
nvim:set_var('rainbow_delimiters', {query = {c = 'other-query'}})
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)
end)
it('Falls back to default highlighting if the highlight table is empty', function()
---The expected highlight groups in order
local hlgroups = {
'RainbowDelimiterRed',
'RainbowDelimiterYellow',
'RainbowDelimiterBlue',
'RainbowDelimiterOrange',
'RainbowDelimiterGreen',
'RainbowDelimiterViolet',
'RainbowDelimiterCyan',
}
-- Set highlight to empty list
nvim:set_var('rainbow_delimiters', {highlight = {}})
for i, expected in ipairs(hlgroups) do
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()
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()
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()
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()
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')
end)
end)
describe('The setup function sets configuration indirectly', function()
it('Can call the setup function', function()
nvim:exec_lua([[
require('rainbow-delimiters.setup').setup {
query = {
lua = 'rainbow-blocks'
}
}
]], {})
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()
nvim:exec_lua([[
require('rainbow-delimiters.setup') {
query = {
lua = 'rainbow-blocks'
}
}
]], {})
local lua_query = nvim:eval('g:rainbow_delimiters.query.lua')
assert.is.equal('rainbow-blocks', lua_query)
end)
end)
end)

View File

@ -0,0 +1,182 @@
local yd = require 'yo-dawg'
describe('The Rainbow Delimiters public API', function()
local nvim
before_each(function()
nvim = yd.start()
-- Set up a tracking strategy
nvim:exec_lua([[
TSEnsure('markdown', 'lua', 'vim')
rb = require 'rainbow-delimiters'
vim.g.rainbow_delimiters = {
strategy = {
[''] = rb.strategy.global,
},
}]], {})
end)
after_each(function()
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(nvim:exec_lua('return rb.is_enabled()', {}))
end)
it('Is enabled for a supported language', function()
nvim:buf_set_option(0, 'filetype', 'lua')
assert.is.True(nvim:exec_lua('return rb.is_enabled()', {}))
end)
describe('Blacklist', function()
before_each(function()
nvim:command('let g:rainbow_delimiters.blacklist = ["markdown"]')
end)
it('Is enabled for a not blacklisted language', function()
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()
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()
nvim:buf_set_lines(0, 0, -1, true, {
'This is Markdown',
'',
'```lua',
'print(((("This is Lua"))))',
'```',
'',
'More Markdown',
})
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()
nvim:command('let g:rainbow_delimiters.whitelist = ["lua"]')
end)
it('Is disabled for a not whitelisted language', function()
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()
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()
nvim:buf_set_lines(0, 0, -1, true, {
'print "This is Lua"',
'vim.cmd [[echo "This is Vim"]]',
})
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()
nvim:buf_set_lines(0, 0, -1, true, {
'This is Markdown',
'',
'```lua',
'print(((("This is Lua"))))',
'```',
'',
'More Markdown',
})
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()
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()
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()
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()
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()
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()
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()
nvim:command('let g:rainbow_delimiters.blacklist = ["markdown"]')
end)
it('Can be enabled for a blacklisted language', function()
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()
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()
nvim:command('let g:rainbow_delimiters.whitelist = ["lua"]')
end)
it('Can be disabled for a whitelisted language', function()
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()
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)
end)

View File

@ -0,0 +1,31 @@
local yd = require 'yo-dawg'
describe('We can disable rainbow delimiters for certain languages', function()
local nvim
before_each(function()
nvim = yd.start()
end)
after_each(function()
yd.stop(nvim)
end)
it('Does not run for a blacklisted language', function()
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()
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)

View File

@ -0,0 +1,99 @@
local yd = require 'yo-dawg'
describe('The global strategy', function()
local nvim
before_each(function()
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
assert(nil ~= global)
the_strategy = track(global)
vim.g.rainbow_delimiters = {
strategy = {
[''] = the_strategy
}, query = {
},
}
]], {})
end)
after_each(function()
yd.stop(nvim)
end)
it('Does not reactivate when making changes', function()
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')
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)
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, nvim:exec_lua('return the_strategy.attachments[1]', {}))
end)
it('Ignores blacklisted injected languages', function()
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'
})
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')
assert.nvim(nvim).Not.has_extmarks_at(2, 13, 'vim')
end)
it('Ignores non-whitelisted injected languages', function()
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'
})
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')
assert.nvim(nvim).Not.has_extmarks_at(2, 13, 'vim')
end)
it('Applies highlighting to nested code', function()
-- See also https://github.com/HiPhish/rainbow-delimiters.nvim/pull/92
local content = [[local function foo()
return {
a = print('a'),
}
end
return foo]]
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'),"
nvim:win_set_cursor(0, {3, 0})
local keys = vim.api.nvim_replace_termcodes("ob = print('b'),<esc>", true, false, true)
nvim:feedkeys(keys, '', false)
assert.nvim(nvim).has_extmarks_at(2, 11, 'lua')
assert.nvim(nvim).has_extmarks_at(3, 11, 'lua')
end)
end)

View File

@ -0,0 +1,46 @@
local yd = require 'yo-dawg'
describe('The local strategy', function()
local nvim
before_each(function()
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']
assert(nil ~= strategy)
the_strategy = track(strategy)
vim.g.rainbow_delimiters = {
strategy = {
[''] = the_strategy
}
}
]], {})
end)
after_each(function()
yd.stop(nvim)
end)
it('Does not reactivate when making changes', function()
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')
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)
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, nvim:exec_lua('return the_strategy.attachments[1]', {}))
end)
end)

View File

@ -0,0 +1,64 @@
local yd = require 'yo-dawg'
describe('We can use functions to turn rainbow delimiters off and on again.', function()
local nvim
before_each(function()
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()
yd.stop(nvim)
end)
it('Does highlighting initially', function()
assert.nvim(nvim).has_extmarks_at(0, 5, 'lua')
end)
it('Disables rainbow delimiters', function()
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()
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()
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()
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()
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()
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)
end)