nvim-autopairs/tests/endwise_spec.lua

87 lines
2.0 KiB
Lua
Raw Normal View History

2021-04-18 18:06:11 +03:00
local npairs = require('nvim-autopairs')
2021-10-20 04:36:54 +03:00
local ts = require('nvim-treesitter.configs')
2021-04-18 18:06:11 +03:00
local log = require('nvim-autopairs._log')
2021-10-20 04:36:54 +03:00
ts.setup({
ensure_installed = { 'lua' },
highlight = { enable = true },
})
_G.npairs = npairs
vim.api.nvim_set_keymap(
'i',
'<CR>',
'v:lua.npairs.autopairs_cr()',
{ expr = true, noremap = true }
)
2021-04-18 18:06:11 +03:00
local data = {
{
2021-10-20 04:36:54 +03:00
name = 'lua function add endwise',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[<cr>]],
before = [[function a()| ]],
after = {
[[function a() ]],
[[| ]],
[[ end ]],
},
},
{
name = 'lua function add endwise',
2021-04-18 18:06:11 +03:00
filepath = './tests/endwise/init.lua',
2021-10-20 04:36:54 +03:00
filetype = 'lua',
linenr = 5,
key = [[<cr>]],
before = [[function a()|x ab ]],
after = {
[[function a() ]],
[[|x ab]],
},
2021-07-24 03:09:46 +03:00
},
{
2021-10-20 04:36:54 +03:00
name = 'add if endwise',
2021-07-24 03:09:46 +03:00
filepath = './tests/endwise/init.lua',
2021-10-20 04:36:54 +03:00
filetype = 'lua',
linenr = 5,
key = [[<cr>]],
before = [[if data== 'fdsafdsa' then| ]],
after = {
[[if data== 'fdsafdsa' then ]],
[[|]],
[[end ]],
},
2021-04-18 18:06:11 +03:00
},
{
2021-10-20 04:36:54 +03:00
name = 'undo on<cr> key',
2021-04-18 18:06:11 +03:00
filepath = './tests/endwise/init.lua',
2021-10-20 04:36:54 +03:00
filetype = 'lua',
linenr = 5,
2021-10-21 09:35:54 +03:00
key = [[{<cr><esc>u]],
2021-10-20 04:36:54 +03:00
before = [[local abc = | ]],
after = {
[[local abc = {|} ]],
[[]],
[[]],
},
2021-04-18 18:06:11 +03:00
},
}
2021-04-21 07:39:36 +03:00
local run_data = _G.Test_filter(data)
2021-04-18 18:06:11 +03:00
local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')
_G.TU = ts_utils
describe('[endwise tag]', function()
2021-10-20 04:36:54 +03:00
_G.Test_withfile(run_data, {
-- need to understand this ??? new line make change cursor zzz
cursor_add = 1,
2021-11-21 05:18:08 +03:00
before_each = function(value)
2021-10-20 04:36:54 +03:00
npairs.add_rules(
require('nvim-autopairs.rules.endwise-' .. value.filetype)
)
end,
2021-04-21 07:39:36 +03:00
})
2021-04-18 18:06:11 +03:00
end)